This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: options = odeset( 'Events' , @(t,y)hit_wall(t, y), 'Maxstep' , 0.01); y = [3 0 0]; t = [0]; finalT = 50; while (t(end) < finalT) [t1,y1] = ode45( @(t,a)dydt_solution(t,a),[t(end) finalT], [y(end,1) y(end,2) y(end,3) ], options ); y = [y; y1]; t = [t; t1]; end figure(3), plot(t,y(:,1)); xlabel( 'Time (s)' ) ylabel( 'Position (m)' ) title( 'Final solution' ) %% Functions used % Returns a column matrix of dy/dt function dydt = dydt_solution(t,a) k1=8; k2=8; F=10; b1=16; b2=16; w=2; m=2; a0=k1/b2; a1=((k1+k2)/k2)+(b1/b2); a2=(b1/k2)+(m/b2); a3=m/k2; dydt = [a(2); ... a(3); ... (F*cos(w.*t)  a0*a(1)  a1*a(2)  a2*a(3)) / a3; ... ]; function [valueToTest, shouldStop, direction] = hit_wall(t, y) valueToTest = y(1); shouldStop = 1; direction = 1;...
View
Full Document
 Spring '08
 RobertSpilker
 Harshad number

Click to edit the document details