function [t,p] = hw2euler(f,t0,p0,h,iter) % Use Euler's method to solve the initial value problem % for the first order ODE % dp/dt = f(t,p), p(t0) = p0. % Calling sequence % function [t,p] = hw2euler(f,t0,p0,h,iter) % h: Step size % iter: Number of iterations % Kartik's MATLAB code % September 6, 2005 tbar = t0; pbar = p0; t = tbar; p = pbar; for i=1:iter, pbar = pbar + h*f(tbar,pbar); tbar = tbar + h; p = [p; pbar]; t = [t; tbar]; end