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

n = length(x)-1;
Atilda = zeros(n+1,n+1);
btilda = zeros(n+1,1);

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

% Robinovy (Newtonovy) podminky
for i=1:length(IR)
    Atilda(IR(i),IR(i)) =  Atilda(IR(i),IR(i)) + alfa;
    btilda(IR(i)) = btilda(IR(i)) + alfa*ustriska;
end

idx = setdiff(1:(n+1),ID);
ustriska = zeros(n+1,1);
ustriska(ID) = uD;
btilda(IN) = btilda(IN) + tau;

A = Atilda(idx,idx);
b = btilda(idx) - Atilda(idx,:)*ustriska;