function [U,gradU] = vypocti_MHP_reseni_v_Omega(Uzly,Segmenty,q,Body)

N = size(Body,2);
n = length(Segmenty);

U = zeros(1,N);
gradU = zeros(2,N);

for i=1:N
    xi = Body(:,i);

    for j=1:n
       Uzlyj = Uzly(:,Segmenty(:,j));
       yj = sum(Uzlyj,2)/2;
       delkaj = norm(Uzlyj(:,2)-Uzlyj(:,1));
       
       U(i) = U(i) -   q(j) * (1/(2*pi)) * log(norm(xi-yj)) * delkaj;       
       gradU(:,i) = gradU(:,i) - q(j) * (1/(2*pi*(xi-yj)'*(xi-yj))) * (xi-yj) *delkaj;
    end
    
end

        
