% % Applies a Two-Step Adams-Bashforth method to: % % y' = f(y,t) y(t0)=y0 % % taking n step sizes of length h. % % w(i+1) = w(i) + h/2 [3f(t_i,w_i) - f(t_{i-1},w_{i-1})] % % % INPUT: F string of the function name % h step size % n number of iterations % t0 vector of t values % w0 vector of initial values for w % % OUTPUT: vectors (t,w) where w(i) is % the approximation of y(t) at % t(i)=t0(1)+(n-1)*h, i=1,2,3,... % % function [t,w]=AdBash2(F,h,n,t0,w0) t(1:2)=t0; w(1:2)=w0; % Temporary Storage for function values temp(1) = feval(F,t(1),w(1)); for i=3:(n+2) temp(2) = feval(F,t(i-1),w(i-1)); w(i) = w(i-1) + h*(3*temp(2) - temp(1))/2; t(i) = t(i-1)+h; % Reassign temporary storage temp(1) = temp(2); end % end-for-loop