T=0.5;
yT=5; yTold=y+1;
h=0.1;
hold on
while abs(yT-yTold)>1e-4
    yTold=yT;
    y=zeros(T/h+1,1);
    t=0:h:T;
    y(1)=0.5;
    for i=1:T/h
        y(i+1)=y(i)+h*t(i)*exp(-y(i));
    end
    plot(t,y)
    xlabel('t'),ylabel('y')
    yT=y(T/h+1);
    h=h/2;
end

disp(['Losningen vid tiden 3: ', num2str(yT)])