Professional Documents
Culture Documents
Expt 7
Expt 7
: 07
PROBLEM:
Write a MATLAB Code to analyse the power flow using Newton-Raphson Method (using Polar Coordinates) for the
system shown in Fig. 1. Take base MVA as 100 MVA. Perform iterations till tolerance𝜀=0.0001is reached. The final
results should display the following:
a. The bus voltages (magnitude and angles)
b. Active and reactive power flows in the lines
c. Active and reactive power losses in the lines
d. Active and reactive power supplied by the slack bus
for p=1:row
a=input(p,1);
b=input(p,2);
X=input(p,3);
Ybus(a,b)=-Ybus(a,b)-1/X;
Ybus(b,a)=-Ybus(b,a)-1/X;
Ybus(a,a)=Ybus(a,a)+1/X;
Ybus(b,b)=Ybus(b,b)+1/X;
End
Yabs = abs(Ybus);
Yangle = angle(Ybus);
Base_MVA=100;
v1abs = 1.025;
angle1 = 0;
v2abs = 1.03;
angle2 = 0;
P2given = 300/basemva;
v3abs = 1;
angle3 = 0;
P3given = -400/basemva;
Q3given = -200/basemva;
Vabs = [v1abs v2abs v3abs];
Vangle = [angle1, angle2, angle3];
EELR17 Power Systems Laboratory 2
e = 0.0001;
limrad2 = 1;
limrad3 = 1;
limV3 = 1;
while(limrad2>e&&limrad3>e&&limV3>e)
Vabsold = Vabs;
Vangleold = Vangle;
n = 3;
P2cal = 0;
P3cal = 0;
Q3cal = 0;
for j=1:n
term1 = Vabs(2)*Yabs(2,j)*Vabs(j);
P2cal = P2cal + term1*cos(Yangle(2,j)+Vangle(j)-Vangle(2));
End
for j=1:n
term1 = Vabs(3)*Yabs(3,j)*Vabs(j);
P3cal = P3cal + term1*cos(Yangle(3,j)+Vangle(j)-Vangle(3));
term1 = Vabs(3)*Yabs(3,j)*Vabs(j);
Q3cal = Q3cal + term1*sin(Vangle(3)-Yangle(3,j)-Vangle(j));
End
deltaP2 = P2given-P2cal;
deltaP3 = P3given-P3cal;
deltaQ3 = Q3given-Q3cal;
J1 = -1*Vabs(2)*Yabs(2,1)*Vabs(1)*sin(Vangle(2)-Vangle(1)-Yangle(2,1));
J1 = J1-Vabs(2)*Yabs(2,3)*Vabs(3)*sin(Vangle(2)-Vangle(3)-Yangle(2,3));
J2 = Vabs(2)*Yabs(2,3)*Vabs(3)*sin(Vangle(2)-Vangle(3)-Yangle(2,3));
J3 = Vabs(2)*Yabs(2,3)*cos(Vangle(2)-Vangle(3)-Yangle(2,3));
J4 = Vabs(3)*Yabs(3,2)*Vabs(2)*sin(Vangle(3)-Vangle(2)-Yangle(3,2));
J5 = -1*Vabs(3)*Yabs(3,1)*Vabs(1)*sin(Vangle(3)-Vangle(1)-Yangle(3,1));
EELR17 Power Systems Laboratory 3
J5 = J5-Vabs(3)*Yabs(3,2)*Vabs(2)*sin(Vangle(3)-Vangle(2)-Yangle(3,2));
J6 = Yabs(3,1)*Vabs(1)*cos(Yangle(3,1)+Vangle(1)-Vangle(3));
J6 = J6+Yabs(3,2)*Vabs(2)*cos(Yangle(3,2)+Vangle(2)-Vangle(3));
J6 = J6+2*Yabs(3,3)*cos(Yangle(3,3));
J7 = -1*Vabs(3)*Yabs(3,2)*Vabs(2)*cos(Vangle(3)-Vangle(2)-Yangle(3,2));
J8 = Vabs(3)*Vabs(1)*Yabs(3,1)*cos(Yangle(3,1)+Vangle(1)-Vangle(3));
J8 = J8+Vabs(3)*Vabs(2)*Yabs(3,2)*cos(Yangle(3,2)+Vangle(2)-Vangle(3));
J9 = -1*Vabs(3)*Yabs(3,3)*sin(Yangle(3,3));
J9 = J9+Yabs(3,1)*Vabs(1)*sin(Vangle(3)-Vangle(1)-Yangle(3,1));
J9 = J9+Yabs(3,2)*Vabs(2)*sin(Vangle(3)-Vangle(2)-Yangle(3,2));
J9 = J9+Yabs(3,3)*Vabs(3)*sin(-1*Yangle(3,3));
J = [J1 J2 J3;
J4 J5 J6;
J7 J8 J9;];
Jinv = inv(J);
Pmismatch = [deltaP2;
deltaP3;
deltaQ3;];
correction_matrix = (Jinv)*Pmismatch;
del_angle2 = correction_matrix(1);
del_angle3 = correction_matrix(2);
del_V3_mag = correction_matrix(3);
Vangle(2) = Vangle(2) + del_angle2;
Vangle(3) = Vangle(3) + del_angle3;
Vabs(3) = Vabs(3) + del_V3_mag;
limrad2 = abs(Vangle(2)-Vangleold(2));
limrad3 = abs(Vangle(3)-Vangleold(3));
limV3 = abs(Vabs(3)-Vabsold(3));
end
V1 = Vabs(1)*exp(1i*Vangle(1));
V2 = Vabs(2)*exp(1i*Vangle(2));
V3 = Vabs(3)*exp(1i*Vangle(3));
S12 = V1*conj((V1-V2)/input(1,3))*basemva;
S21 = V2*conj((V2-V1)/input(1,3))*basemva;
EELR17 Power Systems Laboratory 4
S13 = V1*conj((V1-V3)/input(2,3))*basemva;
S31 = V3*conj((V3-V1)/input(2,3))*basemva;
S23 = V2*conj((V2-V3)/input(3,3))*basemva;
S32 = V3*conj((V3-V2)/input(3,3))*basemva;
P12loss=real(S12)+real(S21);
P13loss=real(S13)+real(S31);
P23loss=real(S23)+real(S32);
Q12loss=imag(S12)+imag(S21);
Q13loss=imag(S13)+imag(S31);
Q23loss=imag(S23)+imag(S32);
MATLAB OUTPUT:
Newton-Raphson load flow method:
PROBLEM:
2)Write a MATLAB Code to analyse the power flow using Decoupled Method for the system shown in Fig. 1. Take
base MVA as 100 MVA. Perform iterations till tolerance 𝜀=0.0001is reached. The final results should display the
following:
a. the bus voltages (magnitude and angles)
b. active and reactive power flows in the lines
c. active and reactive power losses in the lines
d. active and reactive power supplied by the slack bus
for p=1:rows
a=input(p,1);
b=input(p,2);
X=input(p,3);
Ybus(a,b)=-Ybus(a,b)-1/X;
Ybus(b,a)=-Ybus(b,a)-1/X;
Ybus(a,a)=Ybus(a,a)+1/X;
Ybus(b,b)=Ybus(b,b)+1/X;
End
Yabs = abs(Ybus);
Yangle = angle(Ybus);
basemva=100;
v1abs = 1.025;
angle1 = 0;
v2abs = 1.03;
angle2 = 0;
P2given = 300/basemva;
v3abs = 1;
angle3 = 0;
P3given = -400/basemva;
Q3given = -200/basemva;
Vabs = [v1abs v2abs v3abs];
Vangle = [angle1, angle2, angle3];
limit = 0.0001;
lim_rad2 = 1;
EELR17 Power Systems Laboratory 8
lim_rad3 = 1;
lim_V3 = 1;
while(lim_rad2>limit&&lim_rad3>limit&&lim_V3>limit)
Vabs_old = Vabs;
Vangle_old = Vangle;
n = 3;
P2cal = 0;
P3cal = 0;
Q3cal = 0;
for j=1:n
term1 = Vabs(2)*Yabs(2,j)*Vabs(j);
P2cal = P2cal + term1*cos(Yangle(2,j)+Vangle(j)-Vangle(2));
End
for j=1:n
term1 = Vabs(3)*Yabs(3,j)*Vabs(j);
P3cal = P3cal + term1*cos(Yangle(3,j)+Vangle(j)-Vangle(3));
term1 = Vabs(3)*Yabs(3,j)*Vabs(j);
Q3cal = Q3cal + term1*sin(Vangle(3)-Yangle(3,j)-Vangle(j));
End
deltaP2 = P2given-P2cal;
deltaP3 = P3given-P3cal;
deltaQ3 = Q3given-Q3cal;
J1 = -1*Vabs(2)*Yabs(2,1)*Vabs(1)*sin(Vangle(2)-Vangle(1)-Yangle(2,1));
J1 = J1-Vabs(2)*Yabs(2,3)*Vabs(3)*sin(Vangle(2)-Vangle(3)-Yangle(2,3));
J2 = Vabs(2)*Yabs(2,3)*Vabs(3)*sin(Vangle(2)-Vangle(3)-Yangle(2,3));
J3 = 0;
J4 = Vabs(3)*Yabs(3,2)*Vabs(2)*sin(Vangle(3)-Vangle(2)-Yangle(3,2));
J5 = -1*Vabs(3)*Yabs(3,1)*Vabs(1)*sin(Vangle(3)-Vangle(1)-Yangle(3,1));
J5 = J5-Vabs(3)*Yabs(3,2)*Vabs(2)*sin(Vangle(3)-Vangle(2)-Yangle(3,2));
J6 = 0;
J7 = 0;
EELR17 Power Systems Laboratory 9
J8 = 0;
J9 = -1*Vabs(3)*Yabs(3,3)*sin(Yangle(3,3));
J9 = J9+Yabs(3,1)*Vabs(1)*sin(Vangle(3)-Vangle(1)-Yangle(3,1));
J9 = J9+Yabs(3,2)*Vabs(2)*sin(Vangle(3)-Vangle(2)-Yangle(3,2));
J9 = J9+Yabs(3,3)*Vabs(3)*sin(-1*Yangle(3,3));
J = [J1 J2 J3;
J4 J5 J6;
J7 J8 J9;];
J_inv = inv(J);
Pmismatch = [deltaP2;
deltaP3;
deltaQ3;];
correction_matrix = (J_inv)*Pmismatch;
del_angle2 = correction_matrix(1);
del_angle3 = correction_matrix(2);
del_V3_mag = correction_matrix(3);
Vangle(2) = Vangle(2) + del_angle2;
Vangle(3) = Vangle(3) + del_angle3;
Vabs(3) = Vabs(3) + del_V3_mag;
lim_rad2 = abs(Vangle(2)-Vangle_old(2));
lim_rad3 = abs(Vangle(3)-Vangle_old(3));
lim_V3 = abs(Vabs(3)-Vabs_old(3));
end
V1 = Vabs(1)*exp(1i*Vangle(1));
V2 = Vabs(2)*exp(1i*Vangle(2));
V3 = Vabs(3)*exp(1i*Vangle(3));
S12 = V1*conj((V1-V2)/input(1,3))*basemva;
S21 = V2*conj((V2-V1)/input(1,3))*basemva;
S13 = V1*conj((V1-V3)/input(2,3))*basemva;
S31 = V3*conj((V3-V1)/input(2,3))*basemva;
S23 = V2*conj((V2-V3)/input(3,3))*basemva;
S32 = V3*conj((V3-V2)/input(3,3))*basemva;
P12_loss=real(S12)+real(S21);
P13_loss=real(S13)+real(S31);
P23_loss=real(S23)+real(S32);
Q12_loss=imag(S12)+imag(S21);
Q13_loss=imag(S13)+imag(S31);
Q23_loss=imag(S23)+imag(S32);
OUTPUT:
Decoupled load flow method
MATLAB CODE:
clc
clear all
BaseMVA=100;
V1=1.025*exp(1i*0);
mod_V2=1.03;
V2=1.03+0i;
P2=300/BaseMVA;
V3=1+0i;
P3=400/BaseMVA;
Q3=200/BaseMVA;
impedance=[1 2 0.05i;1 3 0.025i;2 3 0.025i];
n=max(impedance(:,2));
l=numel(impedance(:,1));
Ybus=zeros(n);
for r=1:1
p=impedance(r,1);
q=impedance(r,2);
X=impedance(r,3);
Ybus(p,q)=-Ybus(p,q)-1/X;
Ybus(q,p)=-Ybus(q,p)-1/X;
Ybus(p,p)=Ybus(p,p)+1/X;
Ybus(q,q)=Ybus(q,q)+1/X;
End
e2=1;
e3=1;
tolerance=0.0001;
s12=V1*conj(-Ybus(1,2)*(V1-V2))*BaseMVA;
s13=V1*conj(-Ybus(1,3)*(V1-V3))*BaseMVA;
s21=V2*conj(-Ybus(2,1)*(V2-V1))*BaseMVA;
s23=V2*conj(-Ybus(2,3)*(V2-V3))*BaseMVA;
s31=V3*conj(-Ybus(3,1)*(V3-V1))*BaseMVA;
s32=V3*conj(-Ybus(3,2)*(V3-V2))*BaseMVA;
fprintf("Bus Voltage:\n \n")
fprintf('1.Bus-1:magnitude = %.3f V angle = %f \n',abs(V1),angle(V1))
fprintf("2.Bus-2:magnitude = %.3f V angle = %f \n",abs(V3),angle(V3))
fprintf('3.Bus-3:magnitude = %.3f V angle = %f \n',abs(V2),angle(V2))
fprintf('\n')
fprintf('Active Power flow\n')
fprintf('Bus 1-3 = %.2f MW\n',real(s13))
fprintf('Bus 2-3 = %.2f MW\n',real(s23))
fprintf('Bus 2-1 = %.2f MW\n',real(s21))
fprintf('Bus 3-1 = %.2f MW\n',real(s31))
fprintf('Bus 3-2 = %.2f MW\n',real(s32))
fprintf('Bus 1-2 = %.2f MW\n',real(s12))
fprintf('\n')
fprintf('Reactive power flow\n')
fprintf('Bus 1-3 = %.2f MW\n',imag(s13))
fprintf('Bus 2-3 = %.2f MW\n',imag(s23))
fprintf('Bus 2-1 = %.2f MW\n',imag(s21))
fprintf('Bus 3-1 = %.2f MW\n',imag(s31))
fprintf('Bus 3-2 = %.2f MW\n',imag(s32))
fprintf('Bus 1-2 = %.2f MW\n',imag(s12))
fprintf('\n')
EELR17 Power Systems Laboratory 14
fprintf('Active Power loss\n')
fprintf('Bus 1-3 = %.2f MW\n',real(s12)+real(s21))
fprintf('Bus 2-3 = %.2f MW\n',real(s13)+real(31))
fprintf('Bus 1-2 = %.2f MW\n',real(s13)+real(31))
fprintf('\n')
fprintf('Reactive power loss\n')
fprintf('Bus 1-3 = %.2f MW\n',imag(s12)+imag(s21))
fprintf('Bus 2-3 = %.2f MW\n',imag(s13)+imag(31))
fprintf('Bus 1-2 = %.2f MW\n',imag(s13)+imag(31))
fprintf('\n')
fprintf('active power supplied by slack bus= %.2f\n',real(13)+real(31))
fprintf('Reactive power supplied by slack bus=%.2f\n',imag(13)+imag(31))
MATLAB OUTPUT:
Bus Voltage:
1.Bus-1:magnitude = 1.025 V angle = 0.000000
2.Bus-2:magnitude = 1.014 V angle = -0.036073
3.Bus-3:magnitude = 1.030 V angle = 0.023830
Active Power flow
Bus 1-3 = 149.92 MW
Bus 2-3 = 250.08 MW
Bus 2-1 = -150.31 MW
Bus 3-1 = 49.92 MW
Bus 3-2 = 250.08 MW
Bus 1-2 = 150.31 MW
Reactive power flow
Bus 1-3 = -8.14 MW
Bus 2-3 = -103.75 MW
Bus 2-1 = -100.90 MW
Bus 3-1 = -12.24 MW
Bus 3-2 = -157.73 MW
Bus 1-2 = -92.65 MW
Active Power flow
Bus 1-3 = 0.00 MW
Bus 2-3 = 0.00 MW
Bus 1-2 = 0.00 MW
EELR17 Power Systems Laboratory 15
Reactive power loss
Bus 1-3 = 1.25 MW
Bus 2-3 = 18.42 MW
Bus 1-2 = 7.76 MW
active power supplied by slack bus= 99.61
Reactive power supplied by slack bus=90.49
OBSERVATIONS:
For Gauss Seidel:
• Slowest convergence
• Low computation time per iteration
• Number of iterations increases as size of system increases
• Requires less memory.
For Newton-Raphson:
• Fastest convergence
• High computation time per iteration
• Number of iterations is independent of size of system
• Requires more memory
For Decoupled:
• Faster convergence
• Low computation time per iteration
• Number of iterations is independent of size of system
• Requires less memory