function [c,Cx]=eq_constr_polar(VV,connect_m,YBUS,z_Pinj,z_Qinj,slack)
% Purpose:   To form the jacobian as well as its value corresponding
%            to zero real and reactive power injection
%            w.r.t. voltage angle and magnitude in order
%
nob=length(VV(:,1));
G=real(YBUS);B=imag(YBUS);
S_calc=VV.*conj(YBUS*VV);%complex power injection vector (calculated)
VM=abs(VV);VA=angle(VV);

Cx=[];c=[];
J11=zeros(length(z_Pinj),nob);
J12=zeros(length(z_Pinj),nob);
if isempty(z_Pinj)==0
    for i=1:length(z_Pinj)
        k=z_Pinj(i);
        temp1=real(S_calc(k));temp2=imag(S_calc(k));
        for j=1:nob            
            if k==j
                J11(i,j)=-temp2-VM(k)*VM(k)*B(k,k);
                J12(i,j)=(temp1+VM(k)*VM(k)*G(k,k))/VM(k);
            else
                if connect_m(k,j)==1
                    J11(i,j)=VM(k)*VM(j)*(G(k,j)*sin(VA(k)-VA(j))-B(k,j)*cos(VA(k)-VA(j)));
                    J12(i,j)=VM(k)*(G(k,j)*cos(VA(k)-VA(j))+B(k,j)*sin(VA(k)-VA(j)));
                end
            end
        end
        [c]=[c;temp1];
    end
end
[Cx]=[Cx;J11 J12];

J31=zeros(length(z_Qinj),nob);
J32=zeros(length(z_Qinj),nob);
if isempty(z_Qinj)==0
    for i=1:length(z_Qinj)
        k=z_Qinj(i);
        temp1=real(S_calc(k));temp2=imag(S_calc(k));
        for j=1:nob            
            if k==j
                J31(i,j)=temp1-VM(k)*VM(k)*G(k,k);
                J32(i,j)=(temp2-VM(k)*VM(k)*B(k,k))/VM(k);
            else
                if connect_m(k,j)==1
                    J31(i,j)=-VM(k)*VM(j)*(G(k,j)*cos(VA(k)-VA(j))+B(k,j)*sin(VA(k)-VA(j)));
                    J32(i,j)=VM(k)*(G(k,j)*sin(VA(k)-VA(j))-B(k,j)*cos(VA(k)-VA(j)));
                end
            end
        end
        [c]=[c;temp2];        
    end
end
[Cx]=[Cx;J31 J32];

temp=Cx;clear Cx;
if isempty(temp)==0
    if slack==1
        Cx=temp(:,2:2*nob);
    else
        Cx=[temp(:,1:slack-1) temp(:,slack+1:2*nob)];
    end
end