clear all 
%
% Euler's method to solve x' = f(t,x)
%

% Initialization
t0=0;x0=2; %Initial values. Higher dimensional, specifiy x0=[x01;x02; ...; x0n], i.e. column vector
t1=10; % end time for the solution interval [t0 t1]
N=100; % Number of division of the time interval [t0, t1]
tinc=(t1-t0)/N; % Increament or length of the subintervals
t=[];x=[]; % storage
t(1)=t0;x(:,1)=x0; % Initial point of the solution
for k=1:N
    xprime = f(t(k), x(:,k)); % the slope of the tangent line approximation. Change 'f' as needed. 
    t(k+1) = t(k) + tinc;
    x(:,k+1) = x(:,k) + tinc.*xprime;
end

plot(t,x(1,:))


%
% Same file, except for a system of equations. x' = Ff(t,x)
%
clear all 
%
% Euler's method to solve x' = f(t,x)
%

% Initialization
t0=0;x0=[2;1]; %Initial values. Higher dimensional, specifiy x0=[x01;x02; ...; x0n], i.e. column vector
t1=10; % end time for the solution interval [t0 t1]
N=100; % Number of division of the time interval [t0, t1]
tinc=(t1-t0)/N; % Increament or length of the subintervals
t=[];x=[]; % storage
t(1)=t0;x(:,1)=x0; % Initial point of the solution
for k=1:N
    xprime = Ff(t(k), x(:,k)); % the slope of the tangent line approximation. Change 'Ff' as needed. 
    t(k+1) = t(k) + tinc;
    x(:,k+1) = x(:,k) + tinc.*xprime;
end

plot(t,x(1,:),'r-',t,x(2,:),'b-')