function cviko2()

% Resime 1d stacionarni vedeni tepla:
%    -u''(x) + 2pi*r*alfa/kappa*u(x) = 1 + 2*pi*r*alfa*T/kappa
% s okrajovymi podminkami:
%      u(0) = 1
%    -u'(1) = 2*pi*r*alfa/kappa*(u(1)-T)

r = 1; kappa = 1; alfa = 1; T = -5;
K = 2*pi*r*alfa/kappa;

% analyticke reseni
lambda1 = -sqrt(K);
lambda2 = sqrt(K);
C3 = (1+K*T)/K;
M = [1 1;K*exp(lambda1)+lambda1*exp(lambda1) K*exp(lambda2)+lambda2*exp(lambda2)];
v = [1-C3;K*(T-C3)];
C = M\v;

x = 0:0.01:1;
u = C(1)*exp(lambda1*x)+C(2)*exp(lambda2*x)+C3;
plot(x,u,'r')

for n=10:10:100
    h = 1/(n-1);
    A = zeros(n,n); b = zeros(n,1);
    A(1,1) = 1; b(1) = 1;
    A(n,n-1) = -1/h; A(n,n) = K+1/h; b(n) = K*T;
    
    for j=2:n-1
        A(j,j-1) = -1/h^2;
        A(j,j) = 2/h^2 + K;
        A(j,j+1) = -1/h^2;
        b(j) = 1 + K*T;
    end
    u = A\b;
    
    x = 0:h:1;
    hold on
    plot(x,u','b')
    pause
end