Sunday, August 06, 2006

Polyfitting in MATLAB

clc,clear
disp('Your Name')
t=[1,2,3,4,5,6];
y=[42,83,102,124,129,120];
coef=polyfit(t,y,2);
a1=coef(1);
a2=coef(2);
a3=coef(3);
disp('The values of g and vo are...')
g=-2*a1
vo=a2
yf=polyval(coef,t);
disp(' time y fitting y')
disp(' ')
disp([t',y',yf'])
plot(t,y,'o',t,yf)

Saturday, August 05, 2006

Rocket Trajectory for MATLAB 5.3

%Problem #2 Chapter #3 page 121 rocket trajectory

clc,clear

disp('Your Name')
disp('-')
disp('-')

t = 0:2:100;

for n = 1:51;
time = t(n);

h(n) = 60 + (2.13 * (time^2)) - (.0013 * (time^4)) + (.000034 * (time^4.751));
if h(n) >= 0 | h(n) <=0 [d, dtime] = max(h); [i, impact] = min(h); end
end
end
disp('This is the time in seconds after which the rocket starts to fall.')
t(dtime)
t(impact);
n = 1:51;
time = t(n);
[h(n)',time'];

for n = 1:51;
time = t(n);

h(n) = 60 + (2.13 * (time^2)) - (.0013 * (time^4)) + (.000034 * (time^4.751));
if h(n) <=0 disp('This is the time in seconds when the rocket has hit the ground.')
time
break
end
end