function [J] = jacobian1(nodeNum,PVI,PQI,aij,Y1,d,V,PQPVI)
if isempty(PVI)~=1&&isempty(PQI)~=1
H=zeros(size(PQI,1)+size(PVI,1));
N=zeros(size(PQI,1)+size(PVI,1),size(PQI,1));
K=zeros(size(PQI,1),size(PQI,1)+size(PVI,1));
L=zeros(size(PQI,1));
for hi=1:size(PQI,1)+size(PVI,1)%对H矩阵进行构成
for hj=1:size(PQI,1)+size(PVI,1)
if PQPVI(hi)==PQPVI(hj)
for hhi=1:nodeNum
if hhi~=PQPVI(hi)
H(hi,hj)= H(hi,hj)+V(PQPVI(hi))*V(hhi)*(Y1(PQPVI(hi),hhi)*cos(aij(PQPVI(hi),hhi))*sin(d(PQPVI(hi))-d(hhi))-Y1(PQPVI(hi),hhi)*sin(aij(PQPVI(hi),hhi))*cos(d(PQPVI(hi))-d(hhi)));
end
end
else H(hi,hj)=-V(PQPVI(hi))*V(PQPVI(hj))*(Y1(PQPVI(hi),PQPVI(hj))*cos(aij(PQPVI(hi),PQPVI(hj)))*sin(d(PQPVI(hi))-d(PQPVI(hj)))-Y1(PQPVI(hi),PQPVI(hj))*sin(aij(PQPVI(hi),PQPVI(hj)))*cos(d(PQPVI(hi))-d(PQPVI(hj))));
end
end
end
for ni=1:size(PQI,1)+size(PVI,1)%对N矩阵进行构成
for nj=1:size(PQI,1)
if PQPVI(ni)==PQI(nj)
N(ni,nj)=-2*V(PQPVI(ni))*Y1(PQPVI(ni),PQI(nj))*cos(aij(PQPVI(ni),PQI(nj)));
for nni=1:nodeNum
if nni~=PQI(nj)
N(ni,nj)=N(ni,nj)-V(nni)*(Y1(PQPVI(ni),nni)*cos(aij(PQPVI(ni),nni))*cos(d(PQPVI(ni))-d(nni))+Y1(PQPVI(ni),nni)*sin(aij(PQPVI(ni),nni))*sin(d(PQPVI(ni))-d(nni)));
end
end
else N(ni,nj)=-V(PQPVI(ni))*(Y1(PQPVI(ni),PQI(nj))*cos(aij(PQPVI(ni),PQI(nj)))*cos(d(PQPVI(ni))-d(PQI(nj)))+Y1(PQPVI(ni),PQI(nj))*sin(aij(PQPVI(ni),PQI(nj)))*sin(d(PQPVI(ni))-d(PQI(nj))));
end
end
end
for ki=1:size(PQI,1)%对K矩阵进
for kj=1:size(PQI,1)+size(PVI,1)
if PQI(ki)==PQPVI(kj)
for kki=1:nodeNum
if kki~=PQI(ki)
K(ki,kj)=K(ki,kj)-V(PQI(ki))*V(kki)*(Y1(PQI(ki),kki)*cos(aij(PQI(ki),kki))*cos(d(PQI(ki))-d(kki))+Y1(PQI(ki),kki)*sin(aij(PQI(ki),kki)*sin(d(PQI(ki))-d(kki))));
end
end
else K(ki,kj)=V(PQI(ki))*V(PQPVI(kj))*(Y1(PQI(ki),PQPVI(kj))*cos(aij(PQI(ki),PQPVI(kj)))*cos(d(PQI(ki))-d(PQPVI(kj)))+Y1(PQI(ki),PQPVI(kj))*sin(aij(PQI(ki),PQPVI(kj)))*sin(d(PQI(ki))-d(PQPVI(kj))));
end
end
end
for li=1:size(PQI,1)%对L矩阵进行构成
for lj=1:size(PQI,1)
if PQI(li)==PQI(lj)
L(li,lj)=2*V(PQI(li))*Y1(PQI(li),PQI(lj))*sin(aij(PQI(li),PQI(lj)));
for lli=1:nodeNum
if lli~=PQI(li)
L(li,lj)=L(li,lj)-V(lli)*(Y1(PQI(li),lli)*cos(aij(PQI(li),lli))*sin(d(PQI(li))-d(lli))-Y1(PQI(li),lli)*sin(aij(PQI(li),lli))*cos(d(PQI(li))-d(lli)));
end
end
else L(li,lj)=-V(PQI(li))*(Y1(PQI(li),PQI(lj))*cos(aij(PQI(li),PQI(lj)))*sin(d(PQI(li))-d(PQI(lj)))-Y1(PQI(li),PQI(lj))*sin(aij(PQI(li),PQI(lj)))*cos(d(PQI(li))-d(PQI(lj))));
end
end
end
J=[H,N;K,L];%形成雅克比矩阵J
elseif isempty(PVI)==1&&isempty(PQI)~=1%假如没有PV节点
H=zeros(size(PQI,1));
N=zeros(size(PQI,1));
K=zeros(size(PQI,1));
L=zeros(size(PQI,1));
for hi=1:size(PQI,1)%对H矩阵进行构成
for hj=1:size(PQI,1)
if PQI(hi)==PQI(hj)
for hhi=1:nodeNum
if hhi~=PQI(hi)
H(hi,hj)= H(hi,hj)+V(PQI(hi))*V(hhi)*(Y1(PQI(hi),hhi)*cos(aij(PQI(hi),hhi))*sin(d(PQI(hi))-d(hhi))-Y1(PQI(hi),hhi)*sin(aij(PQI(hi),hhi))*cos(d(PQI(hi))-d(hhi)));
end
end
else H(hi,hj)=-V(PQI(hi))*V(PQI(hj))*(Y1(PQI(hi),PQI(hj))*cos(aij(PQI(hi),PQI(hj)))*sin(d(PQI(hi))-d(PQI(hj)))-Y1(PQI(hi),PQI(hj))*sin(aij(PQI(hi),PQI(hj)))*cos(d(PQI(hi))-d(PQI(hj))));
end
end
end
for ni=1:size(PQI,1)%对N矩阵进行构成
for nj=1:size(PQI,1)
if PQI(ni)==PQI(nj)
N(ni,nj)=-2*V(PQI(ni))*Y1(PQI(ni),PQI(ni))*cos(aij(PQI(ni),PQI(ni)));
for nni=1:nodeNum
if nni~=PQI(ni)
N(ni,nj)=N(ni,nj)-V(nni)*(Y1(PQI(ni),nni)*cos(aij(PQI(ni),nni))*cos(d(PQI(ni))-d(nni))+Y1(PQI(ni),nni)*sin(aij(PQI(ni),nni))*sin(d(PQI(ni))-d(nni)));
end
end
else N(ni,nj)=-V(PQI(ni))*(Y1(PQI(ni),PQI(nj))*cos(aij(PQI(ni),PQI(nj)))*cos(d(PQI(ni))-d(PQI(nj)))+Y1(PQI(ni),PQI(nj))*sin(aij(PQI(ni),PQI(nj)))*sin(d(PQI(ni))-d(PQI(nj))));
end
end
end
for ki=1:size(PQI,1)%对K矩阵进行构成
for kj=1:size(PQI,1)
if PQI(ki)==PQI(kj)
for kki=1:nodeNum
if kki~=PQI(ki)
K(ki,kj)=K(ki,kj)-V(PQI(ki))*V(kki)*(Y1(PQI(ki),kki)*cos(aij(PQI(ki),kki))*cos(d(PQI(ki))-d(kki))+Y1(PQI(ki),kki)*sin(aij(PQI(ki),kki)*sin(d(PQI(ki))-d(kki))));
end
end
else K(ki,kj)=V(PQI(ki))*V(PQI(kj))*(Y1(PQI(ki),PQI(kj))*cos(aij(PQI(ki),PQI(kj)))*cos(d(PQI(ki))-d(PQI(kj)))+Y1(PQI(ki),PQI(kj))*sin(aij(PQI(ki),PQI(kj)))*sin(d(PQI(ki))-d(PQI(kj))));
end
end
end
for li=1:size(PQI,1)%对L矩阵进行构成
for lj=1:size(PQI,1)
if PQI(li)==PQI(lj)
L(li,lj)=2*V(PQI(li))*Y1(PQI(li),PQI(li))*sin(aij(PQI(li),PQI(li)));
for lli=1:nodeNum
if lli~=PQI(li)
L(li,lj)=L(li,lj)-V(lli)*(Y1(PQI(li),lli)*cos(aij(PQI(li),lli))*sin(d(PQI(li))-d(lli))-Y1(PQI(li),lli)*sin(aij(PQI(li),lli))*cos(d(PQI(li))-d(lli)));
end
end
else L(li,lj)=-V(PQI(li))*(Y1(PQI(li),PQI(lj))*cos(aij(PQI(li),PQI(lj)))*sin(d(PQI(li))-d(PQI(lj)))-Y1(PQI(li),PQI(lj))*sin(aij(PQI(li),PQI(lj)))*cos(d(PQI(li))-d(PQI(lj))));
end
end
end
J=[H,N;K,L];%形成雅克比矩阵J
else%假如没有PQ节点
H=zeros(size(PVI,1));
for hi=1:size(PVI,1)%对H矩阵进行构成
for hj=1:size(PVI,1)
if PVI(hi)==PVI(hj)
for hhi=1:nodeNum
if hhi~=PVI(hi)
H(hi,hj)= H(hi,hj)+V(PVI(hi))*V(hhi)*(Y1(PVI(hi),hhi)*cos(aij(PVI(hi),hhi))*sin(d(PVI(hi))-d(hhi))-Y1(PVI(hi),hhi)*sin(aij(PVI(hi),hhi))*cos(d(PVI(hi))-d(hhi)));
end
end
else H(hi,hj)=-V(PVI(hi))*V(PVI(hj))*(Y1(PVI(hi),PVI(hj))*cos(aij(PVI(hi),PVI(hj)))*sin(d(PVI(hi))-d(PVI(hj)))-Y1(PVI(hi),PVI(hj))*sin(aij(PVI(hi),PVI(hj)))*cos(d(PVI(hi))-d(PVI(hj))));
end
end
end
J=H;%形成雅克比矩阵J
end
end