% NymFys - Module 4.1 - Euler's Method - Part a
% Example 1
% 17 October 2012

clear all;

format long % increases number of digits displayed

N=10000; % number of steps
h=0.001; % step size

% initial values
t_0=0;
x_0=0;

t=zeros(N+1,1);
x=zeros(N+1,1);
t(1,1)=t_0;
x(1,1)=x_0;

t_old=t_0;
x_old=x_0;

for n=1:N
    
    x_new=x_old+h*(cos(x_old)+sin(t_old)); % Euler's method
    
    t(n+1,1)=t_old+h;
    x(n+1,1)=x_new;
    
    t_old=t_old+h;
    x_old=x_new;
    
end;

plot(t,x); % plotting the solution

x_old % the value of x(t) at the last grid point t_N
