{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

hw19_solutions

# hw19_solutions - Study Problem from HW8 Write your own...

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

Study Problem from HW8 Write your own matlab code for the forth-order Runge-Kutta method. Apply this is problem 3 above, and ad the new data to the plots The slope for predictor-corrector trapezoid method is roughly 2, which matches the fact that this method is O (h^2) accurate. The slope for Runge-Kutta method is roughly 4, which matches the fact that the this method is O (h^4) accurate. Matlab code is as below N = [2 4 10 100 1000 2000000]; % all numbers of steps %%%%%%%%%%%%%%%%% use trapezoid method first %%%%%%%%%%%%%%%%% % first assume the actual y is achieved when n = 2000 t0 = 0; % initial t y0 = 0; % initial y n1 = 2000; % number of step n h1 = 2/2000; % step size h ytrue = zeros(1,n1+1); % initialize true y for k = 1:n1 f0 = sin(t0+y0)*exp(-sqrt(1+y0^2)); % use trapezoid method t1 = t0 + h1; y1 = y0 + h1*f0; f1 = sin(t1+y1)*exp(-sqrt(1+y1^2)); y1 = y0 + 0.5*h1*(f0+f1); ytrue(k+1) = y1; % save each estimate to the y array y0 = y1; % update y0 t0 = t1; % update t0 end % then estimate y using all other numbers of steps

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 / 6

hw19_solutions - Study Problem from HW8 Write your own...

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

View Full Document
Ask a homework question - tutors are online