function jednokrokoveMetody()

% Newtonuv zakon oteplovani
% y'(t) = -lambda*(y(t)-y1), t0<t<T
% y(t0) = y0
% poc. teplota y0=0, konecna teplota y1=1,
% koeficient prestupu tepla lambda=1,
% t0=0, T=10
t0 = 0;
y0 = 0;
y1 = 1;
lambda = 1;
T = 10;

% prava strana v dif. rovnici
f = @(t,y) -lambda*(y-y1);

% analyticke reseni
y = @(t) (y0-y1)*exp(-lambda*t)+y1;

% dopredna Eulerova metoda
figure
for h = [2,1,0.5,0.1,0.01] % [2,1,0.5,0.1]
    t = t0:h:T;
    u = t;
    u(1) = y0;
    for n=1:(length(t)-1)
        u(n+1) = u(n) + h*f(0,u(n));
    end
    hold on
    if h==0.01
        plot(t,y(t),'r',t,u,'b')
    else
        plot(t,u,'b')
    end
end

% zpetna Eulerova metoda
for h = [5,2,1,0.5,0.1,0.01] %[5,2,1,0.5,0.1]
    t = t0:h:T;
    u = t;
    u(1) = y0;
    for n=1:(length(t)-1)
        u(n+1) = (u(n)+h*lambda*y1)/(1+h*lambda);
%         u(n+1) = (u(n) + (h/2)*(2-u(n))) / (1+h/2);
    end
    hold on
    plot(t,u,'k')
end

% Heuneho metoda
for h = [1,0.5] %[2,1,0.5,0.1,0.01] % [2,1,0.5,0.1]
    t = t0:h:T;
    u = t;
    u(1) = y0;
    for n=1:(length(t)-1)
        u(n+1) = u(n) + (h/2)*( f(0,u(n)) + f(0,u(n)+h*f(0,u(n))) );
    end
    hold on
    plot(t,u,'m')
end
