function [X,T] = euler(x0,F,t,h) % Implementation of the Explicit Euler method for % an autonomous system of ODEs in vector form % % INPUT: x0 (initial value vector) % F (right hand side function) % t (vector with initial and final time) % h (step size) % % OUTPUT: X (matrix of approximate solutions at the discrete times) % T (vector of times t_n for which the solution is approximated) % n = round(diff(t)/h); T = linspace(t(1),t(2),n+1); X = zeros(length(x0),n+1); X(:,1) = x0; for i = 1:n X(:,i+1) = X(:,i)+h*F(X(:,i)); end end