Find the file where we had created the program to plot the velocity of the parachutist

possibly- fall.m

In the command window- type fall. Look at figure 1, using Insert- put labels, etc.

change step size- and put text etc.

Let's add distance- ds/dt = -v; so s(t+h)= s(t)- h*v

And use arrays so we can plot later- because 2 different scales:

v=0;

h=.1;

% t is time, v is velocity, s is distance

t(1)=0;

v(1)=0;

s(1)=100;

i=1;

% dragc is drag coeficient

dragc=1.5;

while (s(i)>0)

v(i+1)=v(i)+h*(32-dragc*v(i));

s(i+1)=s(i)-h*v(i+1);

t(i+1)=t(i)+h;

i=i+1;

end

save in distance.m

in command window:

distance;

plot(t(1:i),v(1:i))

figure(2)

plot(t(1:i),s(1:i))

now change the drag coefficient and run again

and run with hold on.

subplot(1,2,1);

plot(t(1:i),v(1:i))

subplot(1,2,2);

plot(t(1:i),s(1:i))

Missile attack problem:

plane going at rate 500 ft/ sec. in horizontal direction.

Thus plane is at points (0,0), (500,0), (1000,0), etc.

Missile initially at 100000 ft. high and 40000 in x and going 10000 ft/second

Assume missile can always find plane- Is that a valid assumption?

In google - type scientific computing disasters scud

Click on first item

If missile is at (x,y) and plane at (0,d), missile should go in direction along the line connecting them.

The length of the line connecting them is

s= sqrt(y*y (x-d)^2);

The change in x should be 1000*(x-d)/s, and the change in y is 1000*y/s.

The change in d is just 500.

Look at flowchart on p. 67.

How would you implement this - what control structure

in Matlab-

x=40000;

y=100000;

d=0;

speedm=1000; %missile speed

speedp=500; % plane speed

s=sqrt(y*y+(x-d)*(x-d));

plot(x,y,'r*',d,0,'b*');

hold on;

while s>500

x=x-speedm*(x-d)/s;

y=y-speedm*y/s;

d=d+speedp;

plot(x,y,'r*',d,0,'b*');

s=sqrt(y*y+(x-d)*(x-d));

end

How would you do the second problem- that is your homework

What variables do you need?

In exercise 4- what variables do we need

in 1 minute- can turn 10 degrees- what in radians

command window- type pi

newfile

xsub=5;

ysub=0;

xship=0;

yship=0;

speedship=20/(60*10); %miles per 6 seconds

speedsub=10/(60*10); %miles per 6 seconds

plot(xship,yship,'r*',xsub,ysub,'b*');

hold on;

s= sqrt((xsub-xship)^2 + (ysub-yship)^2);

smin=s;

seconds6=1;

while (s <=smin)

xsub=xsub-speedsub*(xsub-xship)/s; % sub moves

ysub=ysub-speedsub*(ysub-yship)/s;

xdiff=cos(pi/180 *seconds6); %new direction for the ship

ydiff=sin(pi/180*seconds6);

seconds6=seconds6+1;

xship=xship+xdiff*speedship;% ship moves

yship=yship-ydiff*speedship;

s= sqrt((xsub-xship)^2 + (ysub-yship)^2);

if (s<smin)

smin=s; %new minimum distance

end

plot(xship,yship,'r*',xsub,ysub,'b*');

smin, xship, yship, xsub, ysub, seconds6

end