(a) Modify the following function so that it performs N steps of the Adams-Bashf
ID: 3844749 • Letter: #
Question
(a) Modify the following function so that it performs N steps of the Adams-Bashforth-Moulton combination in PECE mode.
function [x,y] = ab4 (x,y,h,N)
% The first 3 steps are taken using a four-stage explicit
% Runge-Kutta method
for i=1:3
k1 = fn(x,y);
k2 = fn(x+0.5*h,y+0.5*h*k1);
k3 = fn(x+0.5*h,y+0.5*h*k2);
k4 = fn(x+h,y+h*k3);
y = y + h/6*(k1+2*k2+2*k3+k4);
x = x + h; f(:,i) = k1;
end
f(:,4) = fn(x,y);
% Now do the rest of the steps using the four-step
% Adams Bashforth
for i=4:N
y = y + h/24*(55*f(:,4)-59*f(:,3)+37*f(:,2)-9*f(:,1));
x= x + h;
f(:,1) = f(:,2);
f(:,2) = f(:,3);
f(:,3) = f(:,4);
f(:,4) = fn(x,y);
end
This question is about using the four-step Adams-Bashforth and Adams-Moulton methods in PECE mode to estimate y(10) for IVP1. Therefore estimate y(10) for IVP1.
Explanation / Answer
% The first 3 steps are taken using a four-stage explicit
% Runge-Kutta method
for i=1:3
k1 = fn(x,y);
k2 = fn(x+0.5*h,y+0.5*h*k1);
k3 = fn(x+0.5*h,y+0.5*h*k2);
k4 = fn(x+h,y+h*k3);
y = y + h/6*(k1+2*k2+2*k3+k4);
x = x + h; f(:,i) = k1;
end
f(:,4) = fn(x,y);
% Now do the rest of the steps using the four-step
% Adams Bashforth
for i=4:N
y = y + h/24*(55*f(:,4)-59*f(:,3)+37*f(:,2)-9*f(:,1));
x= x + h;
f(:,1) = f(:,2);
f(:,2) = f(:,3);
f(:,3) = f(:,4);
f(:,4) = fn(x,y);
end
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.