# hw3 - Problem 1 modifying professor's code of falling ball...

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

Problem 1: % modifying professor's code of falling ball to represent ith component. t = 0; y = 2; % user's choice of ith component. t_final = 20; dt = .4; t_plot = t; y_plot = y; f = @(y,t,g,cd,m) g-cd/m*y^2; while t < t_final if (t + dt) > t_final dt = t_final- t; end t = t + dt; g = 9.81; cd = .25; m = 70; % Calling Euler, RK2, RK4 methods. Use only one function at a time. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% y = Euler_Step(f, y, t, dt, g,cd,m); % y = RK2_Step(f, y, t, dt, g,cd,m); % y = RK4_Step(f, y, t, dt, g,cd,m); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% y_plot = [y_plot y]; t_plot = [t_plot t]; end hold on ; plot(t_plot,y_plot, 'ro' ); hold on ; g=9.81; m=70; cd=.25; xlabel( 't' ); ylabel( 'y' ); % change Euler to RK2 or RK4 with respect to function used above title( 'Numerical solution of an ODE using Euler method' ); y_exact=sqrt(g*m/cd)*tanh(sqrt(g*cd/m)*t_plot); plot(t_plot,y_exact); % change Euler to RK2 or RK4 with respect to function used above

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.

{[ snackBarMessage ]}

### Page1 / 7

hw3 - Problem 1 modifying professor's code of falling ball...

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

View Full Document
Ask a homework question - tutors are online