% Implementation of Euler's method for a given ordinary differential
% equation.

t = [0, 5]; % Vector with initial and final time.
h = 0.05;   % Step size
x0 = 4; % Initial value;

n = round(diff(t)/h); % Compute required number of steps
T = linspace(t(1),t(2),n+1); % Generate vector of step times

f = @(t,x) sin(t.*x); % Right hand side function for the ODE
X = zeros(length(x0),n+1); % Generate matrix/vector to hold solution
X(:,1) = x0; % Insert initial value in first column

for i = 1:n
    X(:,i+1) = X(:,i)+h*f(T(i),X(:,i)); % Euler step
end


