%euler forward

% change f to get different right hand side
% to use the funtion, define y0,Tmax, and h

% y0 = 1;
% Tmax = 0.1;
% h = 0.05;
% 
% yy = eulerforward(y0, Tmax, h);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function yy = eulerforward(y0, Tmax, h) 
%Tmax    %final time
%h: step size, make sure you choose step size such that T/h is an integer
%y0: initial value at t=0

%yy output vector of the numerical solution

N = Tmax/h

t = 0;   %initial time
y = y0;   %initial value at t=0

yy = zeros(N+1,1); yy(1) = y0; %vector, saved solution

for i=1:N
    t = t+h;
    y = y+h*f(t,y);
    yy(i+1) = y;
end
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%
function f=f(t,y)
    f = 2*y-3*t;
end
