rocket problem:
d=[0 ;0];
v=[0 ;0];
theta=0; t=0;
tm=10000; f=400000;
r=50;
deg=20*pi/180;
g=32;
hold on;
while (d(2)>0 | t==0)
tm-tm-r;
t=t+1;
a=[f*sin(theta)/tm; f*cos(theta)/tm-g];
v=v+a;
d=d+v
plot(d(1),d(2),'*');
if(t==10)
theta=20*pi/180;
end;
if(t==100)
f=0;
end;
end;
snail problem:
position=[0 100 100 0 0
0 0 100 100 0]
speed=1;
s=200;
hold on;
plot(position(1,1),position(2,1),'*',position(1,2),position(2,2),'*', position(1,3),position(2,3),'*',position(1,4),position(2,4),'*');
while(s>10)
s=0;
for i=1:4
diff=position(:,i)-position(:,i+1);
position(:,i)=position(:,i)-speed*diff/norm(diff);
s=s+norm(diff);
end
s
plot(position(1,1),position(2,1),'*',position(1,2),position(2,2),'*', position(1,3),position(2,3),'*',position(1,4),position(2,4),'*');
position(:,5)=position(:,1);
end;
car problem:
d=[0 ;0];
xpart=cos(pi/18);
ypart=sin(pi/18);
v=[88*xpart;88*ypart]
tm=2000; f=400000;
a=[f*xpart/(tm*v(1)); f*ypart/(tm*v(2))-32]
t=0;
hold on;
h=.01
diff=h*a(2);
while ( t<1 &&abs(diff)>.001)
t=t+h;
a=[f*xpart/(tm*v(1)); f*ypart/(tm*v(2))-32];
v=v+a*h;
diff=h*a(2)
d=d+v*h;
plot(d(1),d(2),'*');
end;