function [ti,wi]=euler(f,a,b,y0,N) %Euler's method: See section 5.2. %Solves y' = f(t,y), y(a) = y0, on the interval a <= t <= b. %The unknown y may be a scalar or vector. (See section 5.9.) %Time steps have a size of h = (b-a)/N. %The output ti is a column vector of values of t. %The output wi is a column vector or matrix, whose rows are estimated values of y. h = (b-a)/N; ti = linspace(a, b, N+1); wi(1,:) = y0(:); for i=1:N k1(1,:) = h*f(ti(i), wi(i,:)); wi(i+1,:) = wi(i,:) + k1; end