I'm trying to write a MATLAB code for the Forward Euler method, but I don't think the output is completely correct.
This is my code:
function [t ,u] = Euler(f,tspan ,u0,n)
T = [tspan(1) :n: tspan(2)];
u = zeros(1,n);
u(n) = u0;
h = (tspan(2) - tspan(1))/n;
for i= 1: n
u(i+1) = u(i) + h*f(T(i),u(i));
t = [u(i+1)*T(i)];
u = [u(i+1)];
end
end