function druhyPriklad1dMKP()

% -u''(x) = f(x) v (0,1)
%    u(0) = 0
%  -u'(1) = tau

tau = 0; %0.1;

f = @(x) (heaviside(x-0.5));

for n = 2:1:20;
    h = 1/n;
    x = 0:h:1;
    fx = f(0.5*(x(1:n)+x(2:n+1)));
    
    A = zeros(n,n);
    b = zeros(n,1);
    for i=1:n
        if i<n
            b(i) = (fx(i)+fx(i+1))*h/2;
        else
            b(i) = fx(i)*h/2 - tau;
        end
        for j=1:n
            if i==j
                if i<n
                    A(i,i) = 2/h;
                else
                    A(i,i) = 1/h;
                end
            elseif abs(i-j)==1
                A(i,j) = -1/h;
            end
        end
    end
    
    u = A\b;
    plot(x,[0;u]')
    axis equal
    hold on
    pause
end
