function [A,b] = mkp1d_verze2(x,k,f,ID,uD,IN,tau,alfa,r,ustriska,IR)

n = length(x);
m = n-1;
Avlnka = zeros(n,n);
bvlnka = zeros(n,1);

for p=1:m
    h = x(p+1)-x(p);
    
    Ap = (k(p)/h) * [1,-1;-1,1];
    Ap = Ap + (alfa*2/r)*(h/6)*[2,1;1,2];
    bp = ((f(p)+alfa*(2/r)*ustriska)*h/2) * [1;1];
    
    idx = [p,p+1];
    Avlnka(idx,idx) = Avlnka(idx,idx) + Ap;
    bvlnka(idx) = bvlnka(idx) + bp;
end

% Neumannovy podminky
bvlnka(IN) = bvlnka(IN) + tau;

% Dirichletovy podminky
UD = zeros(n,1);
UD(ID) = uD;
bvlnka = bvlnka - Avlnka*UD;

% Robinovy podminky
for i=1:length(IR)
    Avlnka(IR(i),IR(i)) = Avlnka(IR(i),IR(i)) + alfa;
end
bvlnka(IR) = bvlnka(IR) + alfa*ustriska;

idx = setdiff(1:n,ID);
A = Avlnka(idx,idx);
b = bvlnka(idx);