You are on page 1of 2

clc

close all
yA=sym('yA');
yB=sym('yB');
tA=sym('tA');
tB=sym('tB');
v0=sym('v0');
t=sym('t');

g=10;
h=input('Nhap do cao h= ');
tA=tB+2;
while (h<0)
h=input('Nhap lai do cao h= ');
end
a = solve((-1/2*g*tB^2 + h == 0), (tA - tB - 2==0), (v0*tA - 0.5*g*tA^2 + h == 0),
tB>0);
v0=double(a.v0);
tA=double(a.tB)+2;
tB=double(a.tB);
fprintf('Van toc dau cua vat A de vat A cham dat cham hon vat B 2s la: v0 = %0.2f
m/s\n', v0)
fprintf('Thoi gian cham dat cua vat A: tA = %0.2fs\n', tA);
fprintf('Thoi gian cham dat cua vat B: tB = %0.2fs\n', tB);

yA = v0*t - 0.5*g*t^2 + h;
disp('Phuong trinh cua A: yA = ');
disp(yA);
yB = h - 0.5*g*(t)^2;
disp('Phuong trinh cua B: yB = ');
disp(yB);
disp('NHAN ENTER DE HIEN QUY DAO CUA HE')
pause
t = 0;
d = 0;
xA = 4;
xB = 5;
yA0 = h;
yB0 = h;
figure('name','Nem xien','color','white','numbertitle','off');
hold on
xlabel('x');
ylabel('y');
vatA = plot(xA,yA0,'ro','MarkerSize',10,'markerfacecolor','r');
ht = title(sprintf('t = %0.2f s', t));
hold on
vatB = plot(xB,yB0,'ro','MarkerSize',10,'markerfacecolor','b');
axis equal
axis([0 50 -1 50]);

while (t < (tA))


d=d+1;
t =d*tA/100;
plot(xA, subs(yA), 'o', 'Markersize', 0.5, 'color', 'k');
set(vatA, 'xdata', xA, 'ydata', subs(yA));
if (subs(yB) >= 0)
tB = t;
plot(xB, subs(yB), 'o', 'Markersize', 0.5, 'color', 'k');
set(vatB, 'xdata', xB, 'ydata', subs(yB));
end
legend('A', 'B');
set(ht,'string',sprintf('tA = %0.2f s tB = %0.2f s',t,tB ));
pause(0.0001);
end

You might also like