Homework 15 - options = odeset( 'Events' ,...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
0 5 10 15 20 25 30 35 40 45 50 -2 -1 0 1 2 3 4 Time (s) Position (m) No bounds checking 0 2 4 6 8 10 12 -0.5 0 0.5 1 1.5 2 2.5 3 3.5 4 Time (s) Single zero-crossing handled
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
0 5 10 15 20 25 30 35 40 45 50 -0.5 0 0.5 1 1.5 2 2.5 3 3.5 4 Time (s) Position (m) Final solution function lumped_system % Run entire file, not single cells %% No bounds checking [t,y]=ode45(@(t,a)dydt_solution(t,a),[0 50], [3 0 0]); figure(1), plot(t,y(:,1)); xlabel( 'Time (s)' ) ylabel( 'Position (m)' ) title( 'No bounds checking' ) %% Dealing with zero-crossing for one step options = odeset( 'Events' , @(t,y)hit_wall(t, y), 'Maxstep' , 0.01); [t,y]=ode45(@(t,a)dydt_solution(t,a),[0 50], [3 0 0], options); [t1,y1]=ode45(@(t,a)dydt_solution(t,a),[t(end) 50], [y(end,1) - y(end,2) y(end,3) ], options);
Background image of page 2
y_total = [y; y1]; t_total = [t; t1]; figure(2), plot(t_total, y_total(:,1)); xlabel( 'Time (s)' ) ylabel( 'Position (m)' ) title( 'Single zero-crossing handled' ) %% Final solution
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 4
This is the end of the preview. Sign up to access the rest of the 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

This homework help was uploaded on 04/17/2008 for the course BMED 2200 taught by Professor Robertspilker during the Spring '08 term at Rensselaer Polytechnic Institute.

Page1 / 4

Homework 15 - options = odeset( 'Events' ,...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online