{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Homework 15 - options = odeset'Events(t,y)hit_wall(t...

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

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) Position (m) Single zero-crossing handled

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

View Full Document
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);
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'

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

View Full Document
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

{[ snackBarMessage ]}

What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern