function cviko3()

% Resime (MKD) 1d stacionarni vedeni tepla s nehomogennim materialem:
%    -k1*u1''(x) = 1 v (0,1/2)
%    -k2*u2''(x) = 1 v (1/2,1)
% s okrajovymi podminkami:
%      u1(0) = 1
% -k2*u2'(1) = 0
% a s podminkami prechodu
%    u1(1/2) = u2(1/2)
% -k1*u1'(1/2) = -k2*u2'(1/2)

f = 1; U = 1; tau = 0; k1 = 1; k2 = 3;

for n=11:10:101
    h = 1/(n-1);
    m = (n+1)/2;
    
    e = ones(m,1);
    B = (1/h^2) * spdiags([-e,2*e,-e],[0,1,2],m-2,m);
    
    A = sparse(n,n);
    A(1,1) = 1;
    A(2:m-1,1:m) = k1*B;
    A(m,m-1) = -k1/h;
    A(m,m) = (k1+k2)/h;
    A(m,m+1) = -k2/h;
    A(m+1:n-1,m:n) = k2*B;
    A(n,n-1) = k2/h;
    A(n,n) = -k2/h;
    
    b = zeros(n,1);
    b(1) = U;
    b(2:m-1) = f;
    b(m) = 0;
    b(m+1:n-1) = f;
    b(n) = tau;

    u = A\b;
    
    x = 0:h:1;
    hold on
    plot(x,u','b')
    pause
end