function [psi_r,psi_s] = GradModalBaseValues2D(a,b,i,j)

% return the derivatives of the modal basis polynomial (i,j)
% on the 2D simplex at (a,b).

P1 = JacobiP(a,0,0,i);
gradP1 = GradJacobiP(a,0,0,i);
P2 = JacobiP(b,2 * i + 1,0,j);
gradP2 = GradJacobiP(b,2 * i + 1,0,j);

% r-derivative
%psi_r = sqrt(2) * gradP1 .* P2 * 2 .* ((1 - b) .^ (i - 1)); % problem pro i = 0 - dochazi k deleni nulou; 0^0 Matlab bere jako 1
psi_r = sqrt(2) * gradP1 .* P2;
if i > 0
    psi_r = psi_r * 2 .* ((1 - b) .^ (i - 1));
end

% r-derivative
psi_s = sqrt(2) * gradP1 .* P2 .* (1 + a);
if i > 0
    psi_s = psi_s .* ((1 - b) .^ (i - 1));
end
temp = gradP2 .* ((1 - b) .^ i);
if i > 0
    temp = temp - i * P2 .* ((1 - b) .^ (i - 1));
end
psi_s = psi_s + sqrt(2) * P1 .* temp;

end