

function [X,t]=AdamsB2(pw,t0,x0,x1,N=100,t)
#explicit Adams scheme of 2nd order solves approximately
#x'=pw(x,t) with x(t0)=x0
#y=pw(x,t) fucntion handle to the vector field  - output: vector y of size of x
#t0- initial time  
#x0- vector of length M  (vertical) - initial value
#x1 approximation  of solution at  t_1=t0+h (2 step scheme)
#Output (as in lsode())
#X- matrix Nx M which has  an approximated solution at time moment t(k):
#x(t(k)) in the kth row for t(k)=t0+(k+1)*h
#t -vector with time moments t(k)
h=(t-t0)/(N);
M=length(x0);
X=zeros(N+1,M);
X([1 2],:)=[x0'; x1'];
fx=pw(X(1,:),t0); #f(x0.t0)
t=t0+(0:N).* h;
for k=3:N+1
 pfx=fx;
 fx=pw(X(k-1,:),t); 
 X(k,:)=X(k-1,:)+0.5*h*(3*fx'-pfx');
endfor

endfunction
