Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

Adam-Bashfort 2 steps 1 of 1

function [t,x]=mab2(f,intervalo,x0,N)
% Solves a problem of the sort:
% x' = f(t,x) en [t0,t]
% x(t0) = x0
% with x0 an n-dimensional vector using a Adam-Bashfort method of 2 steps.
h = (intervalo(2)-intervalo(1))/N;
t = transpose(intervalo(1):h:intervalo(2));
x = zeros(length(x0), N+1);
x(:,1) = x0;
F1 = f(t(1),x0);
x(:,2) = x(:,1) + h*F1;
for i=1:N-2
F2 = f(t(i+1),x(:,i+1));
x(:,i+2) = x(:,i+1) + (h/2)*(3*F2 - F1);
F1 = F2;
end
x = transpose(x);
end

You might also like