T=0.5;
y=5; yold=y+1;
h=0.1;

while abs(y-yold)>1e-4
    yold=y;
    y=0.5;
    for i=0:T/h-1
        y=y+h*i*h*exp(-y);
    end
    h=h/2;
end

disp(['Losningen vid tiden 0.5: ', num2str(y)])