%
% Löser y'' + (y'+2)^2 = e^t
%
% y(0)=0, y'(0)=1
%
% med Framåt Euler
%

T  = 2;
u0 = [0;1];
h = 0.1;

u = u0;
U = u;

tt = 0:h:T;

for t=tt(1:end-1)
    f = [u(2); exp(t)-(u(2)+2)^2];
    u = u + f*h;
    U=[U u];
end

[tx yx] = ode45(@(t,y) [y(2); exp(t)-(y(2)+2)^2],[0 T],[0 1]);  % "exakt" lösning

plot(tt,U(1,:),'-o',tx,yx(:,1))
