Code Newton Raphson

Embed Size (px)

DESCRIPTION

newton code

Citation preview

%Step 1; Bus admittance matrixz12=0.0+0.12i; %Given Impedance Z12y12=1/z12; % Convert impeddance to admittanceY11=y12; %Y11Y12=-y12; %Y11Y21=Y12; %Y11Y22=y12; %Y11%Step 2: Power Injections: The number in the brackets indicated the bus%numberPQ=[];%Load Bus 2 is equal to 0.8+j0.25;So the power injection is:PQ(2)=-0.8-0.25i%Step 3:Initialise the power flow solutionsVK=[];VK1=[];IK=[];%Voltage at Black Bus(Bus 1) is given as:VK(1)=1.05+0.0i;VK1(1)=1.05+0.0i;%Voltage at Bus 2(flat start) is assumed:VK(2)=1.0+0.0iVK1(2)=1.0+0.0iDelta1=angle(1.05+0.0i);Delta2=angle(1+0.0i);IK(2)=0.0+0.0i%Step 4:Enter the convergence ToleranceEp=input('Convergence Tolerance,Ep:');fprintf('\n');fprintf('%12.5e\n',Ep);%Newton-Raphson Iterationsfor k=1:1000 p=-0.8; q=-0.25; %Power mismatch equation/Derivation Missmatchp1=abs(VK(1))*(real(Y21)*cos(Delta2-Delta1)+imag(Y21)*sin(Delta2-Delta1)); Missmatchp2=abs(VK(2))*(real(Y22)); deltap=p-(abs(VK(2))*(Missmatchp1+Missmatchp2)); %Reactive power mismatch equation/Derivation Missmatchq1=abs(VK(1))*(real(Y21)*sin(Delta2-Delta1)-imag(Y21)*cos(Delta2-Delta1)); Missmatchq2=abs(VK(2))*(-imag(Y22)); deltaq=q-(abs(VK(2))*(Missmatchq1+Missmatchq2)); %Step 5:Determining components of Jacobian Matrix j1=(VK(2)*VK(1)*real(Y21)*sin(Delta2-Delta1))-(VK(2)*VK(1)*imag(Y21)*cos(Delta2-Delta1)); j2=(-VK(1)*real(Y21)*cos(Delta2-Delta1))-(VK(1)*imag(Y21)*sin(Delta2-Delta1))-(2*VK(2)*real(Y22)); j3=(-VK(2)*VK(1)*real(Y21)*cos(Delta2-Delta1))-(VK(2)*VK(1)*imag(Y21)*sin(Delta2-Delta1)); j4=(-VK(1)*real(Y21)*sin(Delta2-Delta1))+(VK(1)*imag(Y21)*cos(Delta2-Delta1))+(2*VK(2)*imag(Y22)); %Jacobian Matrix construction jacobian=[j1,j2;j3,j4]; %deltapq matrix construction deltapq=[deltap;deltaq]; %Calculating delta2 and VK1(2) deltax=-(inv(jacobian))*deltapq; %New delta delta2new=deltax(1)+Delta2; %New VK1(2) VK1(2)=deltax(2)+VK(2); %Print Commands fprintf('Number of iteration:%4i Max|Vk+1-Vk|=%12.5e voltage magnitude at bus 2:%12.9e \n', k, abs(VK1(2)-VK(2)), abs(VK1(2))); fprintf('Voltage Angle at bus 2: %12.9e delta p : %12.9e delta q: %12.9e\n', delta2new*180/pi,deltapq(1),deltapq(2)); fprintf('\n'); %Convergence if ((abs(VK1(2)-VK(2)))