0% found this document useful (0 votes)
93 views72 pages

Mat Lab Numerical

This document demonstrates using MATLAB to analyze an RLC circuit by: 1) Calculating component values, damping coefficient, natural frequency, and damped resonance frequency. 2) Plotting the voltage response over time for different resistances on the same graph. 3) Representing signals using Fourier series and plotting the magnitude and phase spectra. 4) Calculating the output response to a periodic input by applying the system transfer function to each harmonic in the Fourier series representation.

Uploaded by

Sunil Jain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
93 views72 pages

Mat Lab Numerical

This document demonstrates using MATLAB to analyze an RLC circuit by: 1) Calculating component values, damping coefficient, natural frequency, and damped resonance frequency. 2) Plotting the voltage response over time for different resistances on the same graph. 3) Representing signals using Fourier series and plotting the magnitude and phase spectra. 4) Calculating the output response to a periodic input by applying the system transfer function to each harmonic in the Fourier series representation.

Uploaded by

Sunil Jain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 72

9.

m-1 Analysis of RLC Circuits Using MATLAB


First, set component values >> L=0.1;
>> C=0.001;
>> R=25/3;

Next, calculate the damping coefficient, natural frequency, and the damped >> a=1/(2*R*C)
resonance frequency based on: a =
60.0000

>> w0=1/sqrt(L*C)
w0 =
100

>> wd=sqrt(w0^2 - a^2)


wd =
80.0000

Next, calculate the values of B1 and B2 based on the fact that B1 will always >> B1=10;
be 10 and B2 can be calculated as shown in the book. >> B2=(a/wd)*B1 - 10/(wd*R*C) + 0.6/(wd*C)
B2 =
-1.7764e-15

To start the analysis, calculate the voltage for these coefficients and plot >> t=0:0.001:0.12;
them. Note that the hold on command allows you to use multiple plot >> v=B1*exp(-a*t).*cos(wd*t) + B2*exp(-
a*t).*sin(wd*t);
commands on the same graph while the hold off command makes sure you >> hold off
create a new plot with the next graphing command. The graph right now >> plot(1000*t,v,'b+-')
looks like Figure 9.m-m1 >> hold on

Now you can calculate three more solution sets with differing resistances. >> R=20;
>> a=1/(2*R*C);
Since the hold on command was used, each of the curves will be placed on
>> wd=sqrt(w0*w0 - a*a);
the same graph. Pay special attention to the plot commands used - >> B2=(a/wd)*B1 - 10/(wd*R*C) + 0.6/(wd*C);
specifically which line style refers to a particular resistance. >> v=B1*exp(-a*t).*cos(wd*t) + B2*exp(-
a*t).*sin(wd*t);
>> plot(1000*t,v,'mo-');
>> R=50;
Also, you should note that the initial value for all four curves is the same -
>> a=1/(2*R*C);
10V. This is because the initial condition specified in the problem is that the >> wd=sqrt(w0*w0 - a*a);
voltage at time 0 is 10V. >> B2=(a/wd)*B1 - 10/(wd*R*C) + 0.6/(wd*C);
>> v=B1*exp(-a*t).*cos(wd*t) + B2*exp(-
a*t).*sin(wd*t);
>> plot(1000*t,v,'kx-');
>> R=100;
>> a=1/(2*R*C);
>> wd=sqrt(w0*w0 - a*a);
>> B2=(a/wd)*B1 - 10/(wd*R*C) + 0.6/(wd*C);
>> v=B1*exp(-a*t).*cos(wd*t) + B2*exp(-
a*t).*sin(wd*t);
>> plot(1000*t,v,'rd-');

Finally, add some labels and a legend. The legend command is used by >> legend('R=25/3','R=20','R=50','R=100')
>> ylabel('v_n(t), V');
specifying labels for each of the curves in the order they were created. The
>> xlabel('t, ms');
final graph is shown in Figure 9.m-2 >> title('Natural Response of an
Underdamped Parallel RLC Circuit');

EE341 EXAMPLE 7: SYSTEM SPECTRA (GAIN AND PHASE) AND OUTPUT FOR PERIODIC INPUT

Matlab m-file example7.m:


%
% Filename: example7.m
%
% Description: M-file for displaying RLC circuit response to
% periodic input.
%

%** System Spectra **%


clear; % clear matlab memory
R = 100; L = 1e-3; C = 100e-9; % define circuit parameters
w = -250000:2:250000; % frequency values for spectra
H = (R/L)*j*w./((j*w).^2 + (R/L)*j*w + 1/(L*C)); % system TF
figure(1); clf; % open and clear figure 1
subplot(2,1,1); plot(w,abs(H)); % plot magnitude spectrum
xlabel('\omega rad/sec'); ylabel('|H(\omega)|');
title('RLC Circuit Gain/Magnitude Spectra');
subplot(2,1,2); plot(w,angle(H)*180/pi); % plot phase spectrum
xlabel('\omega rad/sec'); ylabel('\angle {H(\omega) deg}');
title('RLC Circuit Phase/Phase Spectra');

%** System Specta as Bode Plots **%


figure(2); clf; % open and clear figure 2
w = 1:2:1e6; % frequency values for spectra
H = (R/L)*j*w./((j*w).^2 + (R/L)*j*w + 1/(L*C)); % system TF
subplot(2,1,1); semilogx(w,20*log10(abs(H))); % plot magnitude spectrum
xlabel('\omega rad/sec'); ylabel('|H(\omega)| dB');
title('RLC Circuit Gain/Magnitude Spectra as Bode Plot');
subplot(2,1,2); semilogx(w,angle(H)*180/pi); % plot phase spectrum
xlabel('\omega rad/sec'); ylabel('\angle {H(\omega)} deg');
title('RLC Circuit Phase/Phase Spectra as Bode Plot');

%** Input FS Representation **%


figure(3); clf; % open and clear figure 3
N = 100; % +/- number of FS terms taken
To = 100e-6; wo = 2*pi/To; % fundamental period and frequency
D0 = 0.5; % signal offset
t = -100e-6:1e-6:200e-6; % time over which we'll plot signal

f = D0*ones(size(t)); % start out with DC bias term


for n = -N:-1, % loop over negative n
Dn = (1-exp(-j*pi*n))./(j*2*pi*n); % Fourier coefficient
f = f + real(Dn*exp(j*n*wo*t)); % add FS terms
end;

for n = 1:N, % loop over positive n


Dn = (1-exp(-j*pi*n))./(j*2*pi*n); % Fourier coefficient
f = f + real(Dn*exp(j*n*wo*t)); % add FS terms
end;

subplot(2,2,1); plot(t,f); % plot truncated f(t) FS


xlabel('t '); ylabel('f(t)');
title('FS Representation of Input');

%** Input exponential magnitude and phase spectra for 1st 5 harmonics **%
i = 1; % vector index to help store Dn and w
w = 0; Dn = 0; % reinitialize FS variables

for n = -5:-1, % loop over negative n


Dn(i) = (1-exp(-j*pi*n))./(j*2*pi*n); % Fourier coefficient
w(i) = n*wo; % store associated frequency
i = i + 1; % increment vector index
end;

Dn(i) = D0; w(i) = 0; % store 0 frequency terms


i = i + 1; % increment vector index

for n = 1:5, % loop over positive n


Dn(i) = (1-exp(-j*pi*n))./(j*2*pi*n); % Fourier coefficient
w(i) = n*wo; % store associated frequency
i = i + 1; % increment vector index;
end;

subplot(2,2,2); % plot magnitude spectrum of f(t)


stem(w,abs(Dn),'filled');
xlabel('\omega ');ylabel('|D_n|');
title('Magnitude Spectrum of f(t)');

subplot(2,2,3); % plot phase spectrum of f(t)


stem(w,angle(Dn),'filled');
xlabel('\omega '); ylabel('\angle D_n ');
title('Phase Spectrum of f(t)');

%** Output FS Representation **%


figure(4); clf; % open and clear figure 3
H0 = 0; % DC system gain
y = D0*H0*ones(size(t)); % start out with DC bias term

for n = -N:-1, % loop over negative n


Dn = (1-exp(-j*pi*n))./(j*2*pi*n); % input Fourier coefficient
H = (R/L)*j*n*wo./((j*n*wo).^2 + (R/L)*j*n*wo + 1/(L*C)); % system TF
y = y + real(Dn*H*exp(j*n*wo*t)); % add FS terms
end;

for n = 1:N, % loop over positive n


Dn = (1-exp(-j*pi*n))./(j*2*pi*n); % input Fourier coefficient
H = (R/L)*j*n*wo./((j*n*wo).^2 + (R/L)*j*n*wo + 1/(L*C)); % system TF
y = y + real(Dn*H*exp(j*n*wo*t)); % add FS terms
end;

subplot(2,2,1); plot(t,y); % plot truncated y(t) FS


xlabel('t '); ylabel('y(t)');
title('FS Representation of Output');

%** Output exponential magnitude and phase spectra for 1st 5 harmonics **%
i = 1; % vector index to help store DnH and w
w = 0; Dn = 0; % reinitialize FS variables
for n = -5:-1, % loop over negative n
Dn = (1-exp(-j*pi*n))./(j*2*pi*n); % input Fourier coefficient
H = (R/L)*j*n*wo./((j*n*wo).^2 + (R/L)*j*n*wo + 1/(L*C)); % system TF
DnH(i) = Dn*H; % output Fourier coefficient
w(i) = n*wo; % store associated frequency
i = i + 1; % increment vector index
end;

DnH(i) = D0*H0; w(i) = 0; % store 0 frequency terms


i = i + 1; % increment vector index

for n = 1:5, % loop over positive n


Dn = (1-exp(-j*pi*n))./(j*2*pi*n); % input Fourier coefficient
H = (R/L)*j*n*wo./((j*n*wo).^2 + (R/L)*j*n*wo + 1/(L*C)); % system TF
DnH(i) = Dn*H; % output Fourier coefficient
w(i) = n*wo; % store associated frequency
i = i + 1; % increment vector index;
end;

subplot(2,2,2); % plot magnitude spectrum of y(t)


stem(w,abs(DnH),'filled');
xlabel('\omega ');ylabel('|D_nH|');
title('Magnitude Spectrum of y(t)');

subplot(2,2,3); % plot phase spectrum of y(t)


stem(w,angle(DnH),'filled');
xlabel('\omega '); ylabel('{\angle D_nH} ');
title('Phase Spectrum of y(t)');
Matlab Plots Generated:
SERIES RLC CIRCUITS

The principles and formulas that have been presented in this chapter are used in all ac circuits. The
examples given have been series circuits.

This section of the chapter will not present any new material, but will be an example of using all the
principles presented so far. You should follow each example problem step by step to see how each formula
used depends upon the information determined in earlier steps. When an example calls for solving for square
root, you can practice using the square-root table by looking up the values given.
The example series RLC circuit shown in figure 4-11 will be used to solve for XL, XC, X, Z, IT, true power,
reactive power, apparent power, and power factor.

The values solved for will be rounded off to the nearest whole number.

First solve for XL and XC.

Figure 4-11. - Example series RLC circuit


Now solve for X

Use the value of X to solve for Z.


This value of Z can be used to solve for total current (IT ).

Since current is equal in all parts of a series circuit, the value of IT can be used to solve for the
various values of power.
The power factor can now be found using either apparent power and true power or resistance and impedance.
The mathematics in this example is easier if you use impedance and resistance.
PARALLEL RLC CIRCUITS

When dealing with a parallel ac circuit, you will find that the concepts presented in this chapter for
series ac circuits still apply. There is one major difference between a series circuit and a parallel
circuit that must be considered. The difference is that current is the same in all parts of a series
circuit, whereas voltage is the same across all branches of a parallel circuit. Because of this difference,
the total impedance of a parallel circuit must be computed on the basis of the current in the circuit.

You should remember that in the series RLC circuit the following three formulas were used to find
reactance, impedance, and power factor:

When working with a parallel circuit you must use the following formulas instead:
NOTE: If no value for E is given in a circuit, any value of E can be assumed to find the values of IL, IC,
IX, IR, and IZ. The same value of voltage is then used to find impedance.

For example, find the value of Z in the circuit shown in figure 4-12.

The first step in solving for Z is to calculate the individual branch currents.
Figure 4-12. - Parallel RLC circuit.
Using the values for IR, IL, and IC, solve for IX and IZ.

Using this value of IZ, solve for Z.


If the value for E were not given and you were asked to solve for Z, any value of E could be assumed. If,
in the example problem above, you assume a value of 50 volts for E, the solution would be:

First solve for the values of current in the same manner as before.
Solve for IX and IZ.
Solve for Z.

When the voltage is given, you can use the values of currents, I R, IX, and IZ, to calculate for the true
power, reactive power, apparent power, and power factor. For the circuit shown in figure 4-12, the
calculations would be as follows.

To find true power,

To find reactive power, first find the value of reactance (X).


To find apparent power,

The power factor in a parallel circuit is found by either of the following methods.
Q.31 What is the difference between calculating impedance in a series ac circuit and in a parallel ac
circuit?

% IMPLEMENTATION OF NEWTON RAPHSON METHOD IN MATLAB

% DESIGNED BY:

% HAFIZ KASHIF KHALEEL B-12588

% CREATED: 16-JAN-2010

% SEMESTER # 7, EE(POWER).

% SUBJECT: POWER SYSTEM OPERATION AND CONTROL.


% TEXT BOOK: POWER SYSTEM ANALYSIS BY WILLIAM D. STEVENSON, JR.

% CHAPTER # 9.3 - 9.4 (PAGE # 342 - 356).

% UNIVERSITY OF SOUTH ASIA. LAHORE. PAKISTAN.

%======================================================= DATA INPUT


=======================================================%

format short g

disp (' TABLE 9.2 PAGE # 337 LINE DATA FOR EXAMPLE 9.2 ')

linedata=[1 2 0.01008, 0.05040, 3.815629, -19.078144, 10.25, 0.05125;

1 3 0.00744, 0.03720, 5.169561, -25.847809, 7.75, 0.03875;

2 4 0.00744, 0.03720, 5.169561, -25.847809, 7.75, 0.03875;

3 4 0.01272, 0.06360, 3.023705, -15.118528, 12.75, 0.06375]

disp (' TABLE 9.3 PAGE # 338 BUS DATA FOR EXAMPLE 9.2 ')

busdata=[1 0, 0, 50, 30.99, 1.00, 0 1;

2 0, 0, 170, 105.35, 1.00, 0 2;

3 0, 0, 200, 123.94, 1.00, 0 2;

4 318, 0 , 80, 49.58, 1.02, 0 3]

% Last column shows Bus Type: 1.Slack Bus 2.PQ Bus 3.PV Bus
%=================================================== PROGRAM STARTS HERE
===================================================%

ss=i*linedata(:,8); % Y/2

y=linedata(:,5)+i*linedata(:,6);

totalbuses = max(max(linedata(:,1)),max(linedata(:,2))); % total buses

totalbranches = length(linedata(:,1)); % no. of branches

ybus = zeros(totalbuses,totalbuses);

w=0;

u=0;

for n=1:totalbuses % total no of PV busses

if busdata(n,2)>0

w=w+1;

end

end

for n=2:totalbuses % total no of PQ busses

if busdata(n,2)==0

u=u+1;

end

end
% ------ INITIALLIZING YBUS ------

for b=1:totalbranches

ybus((linedata(b,1)),(linedata(b,2)))=-y(b);

ybus((linedata(b,2)),(linedata(b,1))) =ybus((linedata(b,1)),(linedata(b,2)));

end

for c=1:totalbuses

for d=1:totalbranches

if linedata(d,1) == c || linedata(d,2) == c

ybus(c,c) = ybus(c,c) + y(d) + ss(d);

end

end

end

disp('TABLE 9.3 PAGE # 338 BUS ADMITTANCE MATRIX FOR EXAMPLE 9.2')

ybus

ybusR=zeros(totalbuses,totalbuses);

ybusA=zeros(totalbuses,totalbuses);

z=zeros(totalbuses,8);

busnumber=busdata(:,1);

PG=busdata(:,2);

QG=busdata(:,3);
PL=busdata(:,4);

QL=busdata(:,5);

V=busdata(:,6);

VV=V;

ANG=busdata(:,7);

type = busdata(:,8);

s=(2*totalbuses)-w-2;

J=zeros(s,s); % initiallizing empty jacobian matrix

MM=zeros(s,1);

AN=ANG;

P = (PG-PL)./100; % per unit active power at buses

Q = (QG-QL)./100; % per unit reactive power at buses

tol=1;

iter=0;

kk=input('Enter the tolerance for iteration ');

%------------------------------Rect to Polar--------------------------------

for b=1:totalbranches

% Real part of ybus

ybusR((linedata(b,1)),(linedata(b,2)))=abs(-y(b));
ybusR((linedata(b,2)),(linedata(b,1))) =ybusR((linedata(b,1)),(linedata(b,2)));

ybusR(b,b)=abs(-ybus(b,b));

% Angle of ybus

ybusA((linedata(b,1)),(linedata(b,2)))=angle(-y(b));

ybusA((linedata(b,2)),(linedata(b,1))) =ybusA((linedata(b,1)),(linedata(b,2)));

ybusA(b,b)=angle(-ybus(b,b));

end

ybusR;

ybusA;

while tol > kk

%------------------------ Delta P --------------------------------%

for i = 2:totalbuses

YVV = 0;

for n = 1:totalbuses
if i~=n

YVV = YVV + (ybusR(i,n)* V(n)*V(i))*cos((ybusA(i,n))+busdata(n,7)-busdata(i,7)); % multiplying


admittance & voltage

end

YVV;

end

Pc(i) = ((abs(V(i))^2)*real(ybus(i,i)))+YVV; % Compute Calculated P.

deltaP(i)=P(i)-Pc(i);

end

Pc;

dp=deltaP';

for i=2:totalbuses

MM(i-1,1)=dp(i);

end

%------------------------ Delta Q -----------------------------%

for i = 2:totalbuses-w

if busdata(i,8)== 2

YVV = 0;

for n = 1:totalbuses

if i~=n
YVV = YVV + (ybusR(i,n)* V(n)*V(i))*sin((ybusA(i,n))+busdata(n,7)-busdata(i,7)); % multiplying
admittance & voltage

end

YVV;

end

Qc(i) = -((abs(V(i))^2)*imag(ybus(i,i)))-YVV; % Compute Calculated Q.

deltaQ(i)=Q(i)-Qc(i);

end

end

Qc;

dq=deltaQ';

for i=2:totalbuses-w

if busdata(i,8)== 2

MM(totalbuses-2+i,1)=dq(i);

else

i=i-1;

end

end
J11=zeros(totalbuses-1,totalbuses-1);

J12=zeros(totalbuses-1,u);

J21=zeros(u,totalbuses-1);

J22=zeros(u,u);

%----------------------------J11-------------------------------%

for i=2:totalbuses

for j=2:totalbuses

if i~=j

J11(i-1,j-1)= -abs(((ybusR(i,j)* V(i)*V(j)))*sin((ybusA(i,j))+busdata(j,7)-busdata(i,7)));

end

if i==j

for n=1:totalbuses

if n~=i

J11(i-1,i-1)=J11(i-1,i-1)+( abs(((ybusR(i,n)* V(i)*V(n)))*sin((ybusA(i,n))+busdata(n,7)-


busdata(i,7))));

end

end

end

end

end

J11;

%----------------------------J12-------------------------------%
for i=2:totalbuses

for j=2:totalbuses-w

if busdata(j,8)== 2

if i~=j

J12(i-1,j-1)= (abs(V(j))*abs((ybusR(i,j)* V(i))))*cos((ybusA(i,j))+busdata(j,7)-busdata(i,7));

end

yv12=0;

if i==j

for n=1:totalbuses

if n~=i

yv12=yv12 + abs((ybusR(i,n)* V(n)))*cos((ybusA(i,n))+busdata(n,7)-busdata(i,7));

end

end

J12(i-1,j-1) = abs(V(i))*(2*abs(V(i))*real(ybus(i,i))+yv12);

end

end

end

end

J12;
%----------------------------J21-------------------------------%

for i=2:totalbuses-w

if busdata(i,8)== 2

for j=2:totalbuses

if i~=j

J21(i-1,j-1)= abs(((ybusR(i,j)* V(i)*V(j)))*cos((ybusA(i,j))+busdata(j,7)-busdata(i,7)));

end

if i==j

for n=1:totalbuses

if n~=i

J21(i-1,j-1)=J21(i-1,j-1)+( -abs(((ybusR(i,n)* V(i)*V(n)))*cos((ybusA(i,n))+busdata(n,7)-


busdata(i,7))));

end

end

end

end

end

end

J21;

%----------------------------J22-------------------------------%
for i=2:totalbuses-w

for j=2:totalbuses-w

if busdata(i,8)== 2 && busdata(j,8)== 2

if i~=j

J22(i-1,j-1)= -(abs(V(j))*abs((ybusR(i,j)* V(i))))*sin((ybusA(i,j))+busdata(j,7)-busdata(i,7));

end

yv12=0;

if i==j

J22(i-1,j-1)=-(J11(i-1,i-1)) - (2*(abs(V(i))^2)*imag(ybus(i,i)));

end

end

end

end

J22;

%---------------------------------------------------------------------------------%

for k=1:totalbuses-1

for l=1:totalbuses-1

J(k,l)=J11(k,l);
end

end

for k=1:u

for l=1:totalbuses-1

J(l,k+totalbuses-1)=J12(l,k);

end

end

for k=1:u

for l=1:totalbuses-1

J(k+totalbuses-1,l)=J21(k,l);

end

end

for k=1:u

for l=1:u

J(l+totalbuses-1,k+totalbuses-1)=J22(l,k);

end

end
MM;

J;

format short g

k=inv(J)*MM;

for n=1:totalbuses-1

S(n)=(ANG(n+1)+k(n));

sa=radtodeg(S);

%-------------

busdata(n+1,7)=S(n);

%-------------

end

ANG=busdata(:,7);

sa;

for m=2:u+1

V(m)=abs(busdata(m,6)+k(totalbuses-2+m));

%abs(VV)

busdata(m,6)=V(m);

end

V;
tol=max(abs(abs(V) - abs(VV))) && max(abs(abs(ANG) - abs(AN)));

iter=iter+1;

VV=V;

AN=ANG;

end

iter

%-------------------------DISPLAYING OUTPUTS---------------------------%

%real(VACC')

z(1:totalbuses,1)=busdata(:,1);

z(1:totalbuses,2)=busdata(:,8);

z(1:totalbuses,3)=abs(busdata(:,6));

z(1:totalbuses,4)=radtodeg(busdata(:,7));

z(1:totalbuses,5)=PG;

z(1:totalbuses,7)=busdata(:,4);

z(1:totalbuses,8)=busdata(:,5);
disp(' |Bus No.| |Bus Type| |Voltage| |Angle| |MW(G)| |Mvar(G)| |MW(L)| |Mvar(L)| ');

format short g

Forming Ybus Matrix

This is a function that can be called by various programs. The function can be invoked by the statement

[yb,ych]=ybus;

where 'yb' and 'ych' are respectively the Ybus matrix and a matrix containing the line charging admittances. It is assumed that the system data of
Table 4.1 are given in matrix form and the matrix that contains line impedances is 'zz', while 'ych' contains the line charging information. This
program is stored in the file ybus.m. The program listing is given below.

% Function ybus
% THIS IS THE PROGRAM FOR CREATING Ybus MATRIX.

function [yb,ych]=ybus

% The line impedances are

zz=[0 0.02+0.1i 0 0 0.05+0.25i


0.02+0.1i 0 0.04+0.2i 0 0.05+0.25i
0 0.04+0.2i 0 0.05+0.25i 0.08+0.4i
0 0 0.05+0.25i 0 0.1+0.5i
0.05+0.25i 0.05+0.25i 0.08+0.4i 0.1+0.5i 0];

% The line chargings are

ych=j*[0 0.03 0 0 0.02


0.03 0 0.025 0 0.020
0 0.025 0 0.02 0.01
0 0 0.02 0 0.075
0.02 0.02 0.01 0.075 0];

% The Ybus matrix is formed here

for i=1:5
for j=1:5
if zz(i,j) == 0
yb(i,j)=0;
else
yb(i,j)=-1/zz(i,j);
end
end
end

for i=1:5
ysum=0;
csum=0;
for j=1:5
ysum=ysum+yb(i,j);
csum=csum+ych(i,j);
end
yb(i,i)=csum-ysum;
end

Newton-Raphson Load Flow

The Newton-Raphson load flow program is stored in the files loadflow_nr.m. The outputs of the program can be checked by typing

indx the number of iterations

v bus voltages in Cartesian form

abs(v) magnitude of bus voltages


angle(v)/d2r angle of bus voltage in degree

preal real power in MW

preac reactive power in MVAr

pwr power flow in the various line segments

qwr reactive power flow in the various line segments

q reactive power entering or leaving a bus

pl real power losses in various line segments

ql reactive drops in various line segments

It is to be noted that in calculating the power and reactive power the conventions that the power entering a node is positive and leaving it is
negative are maintained. The program listing for the Newton-Raphson load flow is given below.

% Program loadflow_nr
% THIS IS THE NEWTON-RAPHSON POWER FLOW PROGRAM

clear all

d2r=pi/180;w=100*pi;

% The Ybus matrix is

[ybus,ych]=ybus;

g=real(ybus);b=imag(ybus);

% The given parameters and initial conditions are

p=[0;-0.96;-0.35;-0.16;0.24];
q=[0;-0.62;-0.14;-0.08;-0.35];
mv=[1.05;1;1;1;1.02];
th=[0;0;0;0;0];

del=1;indx=0;

% The Newton-Raphson iterations starts here

while del>1e-6
for i=1:5
temp=0;
for k=1:5
temp=temp+mv(i)*mv(k)*(g(i,k)-j*b(i,k))*exp(j*(th(i)-th(k)));
end
pcal(i)=real(temp);qcal(i)=imag(temp);
end

% The mismatches

delp=p-pcal';
delq=q-qcal';

% The Jacobian matrix

for i=1:4
ii=i+1;
for k=1:4
kk=k+1;
j11(i,k)=mv(ii)*mv(kk)*(g(ii,kk)*sin(th(ii)-th(kk))-b(ii,kk)*cos(th(ii)-th(kk)));
end
j11(i,i)=-qcal(ii)-b(ii,ii)*mv(ii)^2;
end

for i=1:4
ii=i+1;
for k=1:4
kk=k+1;
j211(i,k)=-mv(ii)*mv(kk)*(g(ii,kk)*cos(th(ii)-th(kk))-b(ii,kk)*sin(th(ii)-th(kk)));
end
j211(i,i)=pcal(ii)-g(ii,ii)*mv(ii)^2;
end
j21=j211(1:3,1:4);

j12=-j211(1:4,1:3);
for i=1:3
j12(i,i)=pcal(i+1)+g(i+1,i+1)*mv(i+1)^2;
end

j22=j11(1:3,1:3);
for i=1:3
j22(i,i)=qcal(i+1)-b(i+1,i+1)*mv(i+1)^2;
end

jacob=[j11 j12;j21 j22];

delpq=[delp(2:5);delq(2:4)];

corr=inv(jacob)*delpq;

th=th+[0;corr(1:4)];

mv=mv+[0;mv(2:4).*corr(5:7);0];

del=max(abs(delpq));

indx=indx+1;

end

preal=(pcal+[0 0 0 0 0.24])*100;

preac=(qcal+[0 0 0 0 0.11])*100;

% Power flow calculations

for i=1:5
v(i)=mv(i)*exp(j*th(i));
end
for i=1:4
for k=i+1:5
if (ybus(i,k)==0)
s(i,k)=0;s(k,i)=0;
c(i,k)=0;c(k,i)=0;
q(i,k)=0;q(k,i)=0;
cur(i,k)=0;cur(k,i)=0;
else
cu=-(v(i)-v(k))*ybus(i,k);
s(i,k)=-v(i)*cu'*100;
s(k,i)=v(k)*cu'*100;
c(i,k)=100*abs(ych(i,k))*abs(v(i))^2;
c(k,i)=100*abs(ych(k,i))*abs(v(k))^2;
cur(i,k)=cu;cur(k,i)=-cur(i,k);
end
end
end

pwr=real(s);
qwr=imag(s);

q=qwr-c;

% Power loss

ilin=abs(cur);

for i=1:4
for k=i+1:5
if (ybus(i,k)==0)
pl(i,k)=0;pl(k,i)=0;
ql(i,k)=0;ql(k,i)=0;
else
z=-1/ybus(i,k);
r=real(z);
x=imag(z);
pl(i,k)=100*r*ilin(i,k)^2;pl(k,i)=pl(i,k);
ql(i,k)=100*x*ilin(i,k)^2;ql(k,i)=ql(i,k);
end
end
end

Solving Nonlinear Equations using Newton-Raphson

This program gives the solution of the nonlinear equations of Example 4.1 using the Newton-Raphson method. The equations and the Jacobian
matrix are explicitly entered in the program itself. The program gives the number of iterations and the final values of x1 , x2 and x3 . The program
listing is given below.

% Program nwtraph
% THIS IS A NEWTON-RAPHSON PROGRAM
% We have to solve three nonlinear equations given by
%
% g1=x1^2-x2^2+x3^2-11=0
% g2=x1*x2+x2^2-3x3-3=0
% g3=x1-x1*x3+x2*x3-6=0
%
% Let us assume the initial conditions of x1=x2=x3=1
%
% The Jacobian matrix is
%
% J=[2x1 -2x2 2x3
% x2 x1+2x2 -3
% 1-x3 x3 -x1+x2];

clear all

x=[1;1;1];

% The Newton-Raphson iterations starts here

del=1;
indx=0;
while del>1e-6

g=[x(1)^2-x(2)^2+x(3)^2-11;x(1)*x(2)+x(2)^2-3*x(3)-
3;x(1)-x(1)*x(3)+x(2)*x(3)-6];
J=[2*x(1) -2*x(2) 2*x(3);x(2) x(1)+2*x(2) -3;1-x(3)
x(3) -x(1)+x(2)];
delx=-inv(J)*g;
x=x+delx;

del=max(abs(g));
indx=indx+1;

end

'NEWTON-RAPHSON SOLUTION CONVERGES IN


ITERATIONS',indx,pause

'FINAL VALUES OF x ARE',x

Introduction

The two major problems that the modern power systems are facing are voltage and angle stabilities. There are various approaches to overcome
the problem of stability arising due to small signal oscillations in an interconnected power system. As mentioned in the previous chapter, installing
power system stabilizers with generator excitation control system provides damping to these oscillations. However, with the advancement in the
power electronic technology, various reactive power control equipment are increasingly used in power transmission systems.

A power network is mostly reactive. A synchronous generator usually generates active power that is specified by the mechanical power input. The
reactive power supplied by the generator is dictated by the network and load requirements. A generator usually does not have any control over it.
However the lack of reactive power can cause voltage collapse in a system. It is therefore important to supply/absorb excess reactive power
to/from the network. Shunt compensation is one possible approach of providing reactive power support.

A device that is connected in parallel with a transmission line is called a shunt compensator , while a device that is connected in series with the
transmission line is called a series compensator . These are referred to as compensators since they compensate for the reactive power in the ac
system. We shall assume that the shunt compensator is always connected at the midpoint of transmission system, while the series compensator
can be connected at any point in the line. We shall demonstrate that such connections in an SMIB power system improves

 voltage profile
 power-angle characteristics
 stability margin
 damping to power oscillations

A static var compensator ( SVC ) is the first generation shunt compensator. It has been around since 1960s. In the beginning it was used for
load compensation such as to provide var support for large industrial loads, for flicker mitigation etc. However with the advancement of
semiconductor technology, the SVC started appearing in the transmission systems in 1970s. Today a large number of SVCs are connected to
many transmission systems all over the world. An SVC is constructed using the thyristor technology and therefore does not have gate turn off
capability.

With the advancement in the power electronic technology, the application of a gate turn off thyristor (GTO) to high power application became
commercially feasible. With this the second generation shunt compensator device was conceptualized and constructed. These devices use
synchronous voltage sources for generating or absorbing reactive power. A synchronous voltage source (SVS) is constructed using a voltage
source converter (VSC). Such a shunt compensating device is called static compensator or STATCOM . A STATCOM usually contains an SVS
that is driven from a dc storage capacitor and the SVS is connected to the ac system bus through an interface transformer. The transformer steps
the ac system voltage down such that the voltage rating of the SVS switches are within specified limit. Furthermore, the leakage reactance of the
transformer plays a very significant role in the operation of the STATCOM.

Like the SVC, a thyristor controlled series compensator ( TCSC ) is a thyristor based series compensator that connects a thyristor controlled
reactor ( TCR ) in parallel with a fixed capacitor. By varying the firing angle of the anti-parallel thyristors that are connected in series with a reactor
in the TCR, the fundamental frequency inductive reactance of the TCR can be changed. This effects a change in the reactance of the TCSC and it
can be controlled to produce either inductive or capacitive reactance.

Alternatively a static synchronous series compensator or SSSC can be used for series compensation. An SSSC is an SVS based all GTO
based device which contains a VSC. The VSC is driven by a dc capacitor. The output of the VSC is connected to a three-phase transformer. The
other end of the transformer is connected in series with the transmission line. Unlike the TCSC, which changes the impedance of the line, an
SSSC injects a voltage in the line in quadrature with the line current. By making the SSSC voltage to lead or lag the line current by 90 ° , the
SSSC can emulate the behavior of an inductance or capacitance.

In this chapter, we shall discuss the ideal behavior of these compensating devices. For simplicity we shall consider the ideal models and broadly
discuss the advantages of series and shunt compensation.

Section I: Ideal Shunt Compensator

 Improving Volatage Profile


 Improving Power-Angle Characteristics
 Improving Stability Margin
 Improving Damping to Power Oscillations

The ideal shunt compensator is an ideal current source. We call this an ideal shunt compensator because we assume that it only supplies reactive
power and no real power to the system. It is needless to say that this assumption is not valid for practical systems. However, for an introduction,
the assumption is more than adequate. We shall investigate the behavior of the compensator when connected in the middle of a transmission line.
This is shown in Fig. 10.1, where the shunt compensator, represented by an ideal current source, is placed in the middle of a lossless
transmission line. We shall demonstrate that such a configuration improves the four points that are mentioned above.
Fig 10.1 Schematic diagram of an ideal, midpoint shunt compensation

Improving Voltage Profile

Let the sending and receiving voltages be given by and respectively. The ideal shunt compensator is expected to regulate the
midpoint voltage to

(10.1)

against any variation in the compensator current. The voltage current characteristic of the compensator is shown in Fig. 10.2. This ideal behavior
however is not feasible in practical systems where we get a slight droop in the voltage characteristic. This will be discussed later.

Fig. 10.2 Voltage-current characteristic of an ideal shunt compensator.

Under the assumption that the shunt compensator regulates the midpoint voltage tightly as given by (10.1), we can write the following expressions
for the sending and receiving end currents
(10.2)

(10.3)

Again from Fig. 10.1 we write

(10.4)

Combing (10.2)-(10.4) and solving we get

(10.5)
We thus have to generate a current that is
in phase with the midpoint voltage and has a magnitude of (4V / XL ){1 - cos( δ /2)}. The apparent power injected by the shunt compensator to the
ac bus is then

(10.6)

Since the real part of the injected power is zero, we conclude that the ideal shunt compensator injects only reactive power to the ac system and no
real power.

Improving Power-Angle Characteristics

The apparent power supplied by the source


is given by

(10.7)
Similarly the apparent power delivered at
the receiving end is

(10.8)

Hence the real power transmitted over the


line is given by

(10.9)

Combining (10.6)-(10.8), we find the


reactive power consumed by the line as

(10.10)

The power-angle characteristics of the shunt compensated line are shown in Fig. 10.3. In this figure Pmax = V2/X is chosen as the power base.
Fig. 10.3 Power-angle characteristics of ideal shunt compensated line.

Fig. 10.3 depicts Pe - δ and QQ - δ characteristics. It can be seen from fig 10.4 that for a real power transfer of 1 per unit, a reactive power injection
of roughly 0.5359 per unit will be required from the shunt compensator if the midpoint voltage is regulated as per (10.1). Similarly for increasing the
real power transmitted to 2 per unit, the shunt compensator has to inject 4 per unit of reactive power. This will obviously increase the device rating
and may not be practical. Therefore power transfer enhancement using midpoint shunt compensation may not be feasible from the device rating
point of view.
Fig. 10.4 Variations in transmitted real power and reactive power injection by the shunt compensator with load angle for perfect
midpoint voltage regulation.

Let us now relax the condition that the midpoint voltage is regulated to 1.0 per unit. We then obtain some very interesting plots as shown in Fig.
10.5. In this figure, the x-axis shows the reactive power available from the shunt device, while the y-axis shows the maximum power that can be
transferred over the line without violating the voltage constraint. There are three different P-Q relationships given for three midpoint voltage
constraints. For a reactive power injection of 0.5 per unit, the power transfer can be increased from about 0.97 per unit to 1.17 per unit by lowering
the midpoint voltage to 0.9 per unit. For a reactive power injection greater than 2.0 per unit, the best power transfer capability is obtained for VM =
1.0 per unit. Thus there will be no benefit in reducing the voltage constraint when the shunt device is capable of injecting a large amount of
reactive power. In practice, the level to which the midpoint voltage can be regulated depends on the rating of the installed shunt device as well the
power being transferred.
Fig. 10.5 Power transfer versus shunt reactive injection under midpoint voltage constraint.

Improving Stability Margin

This is a consequence of the improvement in the power angle characteristics and is one of the major benefits of using midpoint shunt
compensation. As mentioned before, the stability margin of the system pertains to the regions of acceleration and deceleration in the power-angle
curve. We shall use this concept to delineate the advantage of mid point shunt compensation.

Consider the power angle curves shown in Fig. 10.6.


The curve of Fig. 10.6 (a) is for an uncompensated system, while that of Fig. 10.6 (b) for the compensated system. Both these curves are drawn
assuming that the base power is V2/X . Let us assume that the uncompensated system is operating on steady state delivering an electrical power
equal to Pm with a load angle of δ0 when a three-phase fault occurs that forces the real power to zero. To obtain the critical clearing angle for the
uncompensated system is δcr , we equate
the accelerating area A1 with the
decelerating area A2 , where

with δmax = π - δ0 . Equating the areas we


obtain the value of δcr as
(10.11)

Let us now consider that the midpoint shunt compensated system is working with the same mechanical power input Pm. The operating angle in this
case is δ1 and the maximum power that can be transferred in this case is 2 per unit. Let the fault be cleared at the same clearing angle δcr as
before. Then equating areas A3 and A4 in Fig. 10.6 (b) we get δ2, where
Example 10.1

Improving Damping to Power Oscillations

The swing equation of a synchronous machine is given by (9.14). For any variation in the electrical quantities, the mechanical power input remains
constant. Assuming that the magnitude of the midpoint voltage of the system is controllable by the shunt compensating device, the accelerating
power in (9.14) becomes a function of two independent variables, | VM | and δ . Again since the mechanical power is constant, its perturbation with
the independent variables is zero. We then
get the following small perturbation
expression of the swing equation
(10.12)

where Δ indicates a perturbation around the nominal values.

If the mid point voltage is regulated at a


constant magnitude, Δ| VM | will be equal to
zero. Hence the above equation will reduce
to (10.13)

The 2nd order differential equation given in (10.13) can be written in the Laplace domain by neglecting the initial conditions as
(10.14

The roots of the above equation are located on the imaginary axis of the s-plane at locations ± j ωm where

This implies that the load angle will oscillate with a constant frequency of ωm . Obviously, this solution is not acceptable. Thus in order to provide
damping, the mid point voltage must be
varied according to in sympathy with the
rate of change in Δδ . We can then write
(10.15)

where KM is a proportional gain. Substituting (10.15) in (10.12) we get

(10.16)

Provided that KM is positive definite, the introduction of the control action (10.15) ensures that the roots of the second order equation will have
negative real parts. Therefore through the feedback, damping to power swings can be provided by placing the poles of the above equation to
provide the necessary damping ratio and undamped natural frequency of oscillations.

Example 10.2

Section II: Ideal Series Compensator


 Impact of Series Compensator on Voltage Profile
 Improving Power-Angle Characteristics
 An Alternate Method of Voltage Injection
 Improving Stability Margin
 Comparisons of the Two Modes of Operation
 Power Flow Control and Power Swing Damping

Ideal Series Compensator

Let us assume that the series compensator is represented by an ideal voltage source. This is shown in Fig. 10.10. Let us further assume that the
series compensator is ideal, i.e., it only supplies reactive power and no real power to the system. It is needless to say that this assumption is not
valid for practical systems. However, for an introduction, the assumption is more than adequate. It is to be noted that, unlike the shunt
compensator, the location of the series compensator is not crucial, and it can be placed anywhere along the transmission line.

Fig. 10.10 Schematic diagram of an ideal series compensated system.

Impact of Series Compensator on Voltage Profile

In the equivalent schematic diagram of a series compensated power system is shown in Fig. 10.10, the receiving end current is equal to the
sending end current, i.e., IS = IR . The series voltage VQ is injected in such a way that the magnitude of the injected voltage is made proportional to
that of the line current. Furthermore, the
phase of the voltage is forced to be in
quadrature with the line current. We then
have (10.20)
The ratio λ/X is called the compensation level and is often expressed in percentage. This compensation level is usually measured with respect
to the transmission line reactance. For example, we shall refer the compensation level as 50% when λ = X /2. In the analysis presented below, we
assume that the injected voltage lags the line current. The implication of the voltage leading the current will be discussed later.

Applying KVL we get

Assuming VS = V < δ and VR = V <0° , we


get the following expression for the line
current
(10.21)

When we choose VQ = λ IS e- j90° , the line current equation becomes

Thus we see that λ is subtracted from X . This choice of the sign corresponds to the voltage source acting as a pure capacitor. Hence we call this
as the capacitive mode of operation . In contrast, if we choose VQ = λIS e+j90° , λ is added to X , and this mode is referred to as the inductive
mode of operation . Since this voltage injection using (10.20) add λ to or subtract λ from the line reactance, we shall refer it as voltage injection in
constant reactance mode. We shall consider the implication of series voltage injection on the transmission line voltage through the following
example.

Example 10.3

Improving Power-Angle Characteristics

Noting that the sending end apparent power is VS IS* , we can write
(10.22)

Similarly the receiving end apparent power is given by

(10.23)

Hence the real power transmitted over the line is given by

(10.24)

The power-angle characteristics of a series compensated power system are given in Fig. 10.12. In this figure the base power is
chosen as V2 / X . Three curves are shown, of which the curve P0 is the power-angle curve when the line is not compensated.
Curves which have maximum powers greater than the base power pertain to capacitive mode of operation. On the other hand, all
curves the inductive mode of operation will have maximum values less than 1. For example, in Fig. 10.12, the curve P1 is for
capacitive mode and the curve P2 is for inductive mode of operation.
Fig. 10.12 Power-angle characteristics in constant reactance mode.

Let us now have a look at the reactive power. For simplicity let us restrict our attention to capacitive mode of operation only as this
represents the normal mode of operation in which the power transfer over the line is enhanced. From (10.20) and (10.21) we get the
reactive power supplied by the compensator as

Solving the above equation we get

(10.25)

In Fig. 10.13, the reactive power injected by the series compensator is plotted against the maximum power transfer as the
compensation level changes from 10% to 60%. As the compensation level increases, the maximum power transfer also increases.
However, at the same time, the reactive injection requirement from the series compensator also increases. It is interesting to note
that at 50% compensation level, the reactive power injection requirement from a series compensator is same that from shunt
compensator that is regulating the midpoint voltage to 1.0 per unit.

Fig. 10.13 Reactive power injection by a series compensator versus maximum power transfer as the level of
compensation changes in constant reactance mode.

An Alternate Method of Voltage Injection

So far we have assumed that the series compensator injects a voltage that is in quadrature with the line current and its magnitude is
proportional to the magnitude of the line current. A set of very interesting equations can be obtained if the last assumption about the
magnitude is relaxed. The injected voltage is then given by

(10.26)

We can then write the above equation as

(10.27)
i.e., the voltage source in quadrature with the current is represented as a pure reactance that is either inductive or capacitive. Since
in this form we injected a constant voltage in quadrature with the line current, we shall refer this as constant voltage injection
mode. The total equivalent inductance of the line is then

Defining VS = V < δ and VR < 0° , we can then write the power transfer equation as

Since | VQ | / | IS | = XQ , we can modify the above equation as

(10.28)

Consider the phasor diagram of Fig. 10.14 (a), which is for capacitive operation of the series compensator. From this diagram we get

Similarly from the inductive operation phasor diagram shown in Fig. 10.14 (b), we get

Substituting the above two equations in (10.28) and rearranging we get


(10.29)

where the positive sign is for capacitive operation.

Fig. 10.14 Phasor diagram of series compensated system: (a) capacitive operation and (b) inductive operation

Contd...An Alternate Method of Voltage Injection

The power-angle characteristics of this particular series connection are given in Fig. 10.15. In this figure the base power is chosen as
V2/X . Three curves are shown, of which the curve P0 is the power-angle curve when the line is not compensated. Curves which
have maximum powers greater than the base power pertain to capacitive mode of operation. On the other hand, all curves the
inductive mode of operation will have maximum values less than 1. For example, in Fig. 10.15, the curve P1 is for capacitive mode
and the curve P2 is for inductive mode of operation.
Fig. 10.15 Power-angle characteristics for constant voltage mode.

The reactive power supplied by the compensator in this case will be

(10.30)

Improving Stability Margin

From the power-angle curves of Figs. 10.13 and 10.15 it can be seen that the same amount of power can be transmitted over a
capacitive compensated line at a lower load angle than an uncompensated system. Furthermore, an increase in the height in the
power-angle curve means that a larger amount of decelerating area is available for a compensated system. Thus improvement in
stability margin for a capacitive series compensated system over an uncompensated system is obvious.

Comparisons of the Two Modes of Operation

As a comparison between the two different modes of voltage injection, let us first consider the constant reactance mode of voltage
injection with a compensation level of 50%. Choosing V2 / X as the base power, the power-angle characteristic reaches a maximum
of 2.0 per unit at a load angle π / 2. Now | VQ | in constant voltage mode is chosen such that the real power is 2.0 per unit at a load
angle of π / 2. This is accomplished using (10.29) where we get

per unit

The power-angle characteristics of the two different modes are now drawn in Fig. 10.16 (a). It can be seen that the two curves match
at π / 2. However, the maximum power for constant voltage case is about 2.1 per unit and occurs at an angle of 67° .

Fig. 10.16 (b) depicts the line current for the two cases. It can be seen that the increase in line current in either case is monotonic.
This is not surprising for the case of constant reactance mode since as the load angle increases, both real power and line currents
increase. Now consider the case of constant voltage control. When the load angle moves backwards from π /2 to 67° , the power
moves from 2.0 per unit to its peak value of 2.1 per unit. The line current during this stage decreases from about 2.83 to 2.50 per
unit. Thus, even though the power through the line increases, the line current decreases.

Power Flow Control and Power Swing Damping

One of the major advantages of series compensation is that through its use real power flow over transmission corridors can be
effectively controlled. Consider, for example, the SMIB system shown in Fig. 10.17 in which the generator and infinite bus are
connected through a double circuit transmission line, labeled line-1 and line-2. Of the two transmission lines, line-2 is compensated
by a series compensator. The compensator then can be utilized to regulate power flow over the entire system.
(a) (b)

Fig. 10.16 Power-angle and line current-angle characteristics of the two different methods of voltage injection: solid
line showing constant reactance mode and dashed line showing constant voltage mode.

For example, let us consider that the system is operating in the steady state delivering a power of Pm0 at a load angle of δ0 . Lines 1
and 2 are then sending power Pe1 and Pe2 respectively, such that Pm0 = Pe1 + Pe2 . The mechanical power input suddenly goes up to
Pm1 . There are two ways of controlling the power in this situation:

 Regulating Control: Channeling the increase in power through line-1. In this case the series compensator maintains the
power flow over line-2 at Pe2 . The load angle in this case goes up in sympathy with the increase in Pe1 .
 Tracking Control: Channeling the increase in power through line-2. In this case the series compensator helps in maintaining
the power flow over line-1 at Pe1 while holding the load angle to δ0 .

Let us illustrate these two aspects with the help of a numerical example.

Example 10.4
% Program for Newton-Raphson Load Flow Analysis..

nbus = 14; % IEEE-14, IEEE-30, IEEE-57..

Y = ybusppg(nbus); % Calling ybusppg.m to get Y-Bus Matrix..

busd = busdatas(nbus); % Calling busdatas..

BMva = 100; % Base MVA..

bus = busd(:,1); % Bus Number..

type = busd(:,2); % Type of Bus 1-Slack, 2-PV, 3-PQ..

V = busd(:,3); % Specified Voltage..


del = busd(:,4); % Voltage Angle..

Pg = busd(:,5)/BMva; % PGi..

Qg = busd(:,6)/BMva; % QGi..

Pl = busd(:,7)/BMva; % PLi..

Ql = busd(:,8)/BMva; % QLi..

Qmin = busd(:,9)/BMva; % Minimum Reactive Power Limit..

Qmax = busd(:,10)/BMva; % Maximum Reactive Power Limit..

P = Pg - Pl; % Pi = PGi - PLi..

Q = Qg - Ql; % Qi = QGi - QLi..

Psp = P; % P Specified..

Qsp = Q; % Q Specified..

G = real(Y); % Conductance matrix..

B = imag(Y); % Susceptance matrix..

pv = find(type == 2 | type == 1); % PV Buses..

pq = find(type == 3); % PQ Buses..

npv = length(pv); % No. of PV buses..

npq = length(pq); % No. of PQ buses..

Tol = 1;

Iter = 1;

while (Tol > 1e-5) % Iteration starting..


P = zeros(nbus,1);

Q = zeros(nbus,1);

% Calculate P and Q

for i = 1:nbus

for k = 1:nbus

P(i) = P(i) + V(i)* V(k)*(G(i,k)*cos(del(i)-del(k)) + B(i,k)*sin(del(i)-del(k)));

Q(i) = Q(i) + V(i)* V(k)*(G(i,k)*sin(del(i)-del(k)) - B(i,k)*cos(del(i)-del(k)));

end

end

% Checking Q-limit violations..

if Iter <= 7 && Iter > 2 % Only checked up to 7th iterations..

for n = 2:nbus

if type(n) == 2

QG = Q(n)+Ql(n);

if QG < Qmin(n)

V(n) = V(n) + 0.01;

elseif QG > Qmax(n)

V(n) = V(n) - 0.01;

end

end
end

end

% Calculate change from specified value

dPa = Psp-P;

dQa = Qsp-Q;

k = 1;

dQ = zeros(npq,1);

for i = 1:nbus

if type(i) == 3

dQ(k,1) = dQa(i);

k = k+1;

end

end

dP = dPa(2:nbus);

M = [dP; dQ]; % Mismatch Vector

% Jacobian

% J1 - Derivative of Real Power Injections with Angles..

J1 = zeros(nbus-1,nbus-1);

for i = 1:(nbus-1)

m = i+1;
for k = 1:(nbus-1)

n = k+1;

if n == m

for n = 1:nbus

J1(i,k) = J1(i,k) + V(m)* V(n)*(-G(m,n)*sin(del(m)-del(n)) + B(m,n)*cos(del(m)-del(n)));

end

J1(i,k) = J1(i,k) - V(m)^2*B(m,m);

else

J1(i,k) = V(m)* V(n)*(G(m,n)*sin(del(m)-del(n)) - B(m,n)*cos(del(m)-del(n)));

end

end

end

% J2 - Derivative of Real Power Injections with V..

J2 = zeros(nbus-1,npq);

for i = 1:(nbus-1)

m = i+1;

for k = 1:npq

n = pq(k);

if n == m

for n = 1:nbus

J2(i,k) = J2(i,k) + V(n)*(G(m,n)*cos(del(m)-del(n)) + B(m,n)*sin(del(m)-del(n)));


end

J2(i,k) = J2(i,k) + V(m)*G(m,m);

else

J2(i,k) = V(m)*(G(m,n)*cos(del(m)-del(n)) + B(m,n)*sin(del(m)-del(n)));

end

end

end

% J3 - Derivative of Reactive Power Injections with Angles..

J3 = zeros(npq,nbus-1);

for i = 1:npq

m = pq(i);

for k = 1:(nbus-1)

n = k+1;

if n == m

for n = 1:nbus

J3(i,k) = J3(i,k) + V(m)* V(n)*(G(m,n)*cos(del(m)-del(n)) + B(m,n)*sin(del(m)-del(n)));

end

J3(i,k) = J3(i,k) - V(m)^2*G(m,m);

else

J3(i,k) = V(m)* V(n)*(-G(m,n)*cos(del(m)-del(n)) - B(m,n)*sin(del(m)-del(n)));

end
end

end

% J4 - Derivative of Reactive Power Injections with V..

J4 = zeros(npq,npq);

for i = 1:npq

m = pq(i);

for k = 1:npq

n = pq(k);

if n == m

for n = 1:nbus

J4(i,k) = J4(i,k) + V(n)*(G(m,n)*sin(del(m)-del(n)) - B(m,n)*cos(del(m)-del(n)));

end

J4(i,k) = J4(i,k) - V(m)*B(m,m);

else

J4(i,k) = V(m)*(G(m,n)*sin(del(m)-del(n)) - B(m,n)*cos(del(m)-del(n)));

end

end

end

J = [J1 J2; J3 J4]; % Jacobian Matrix..


X = inv(J)*M; % Correction Vector

dTh = X(1:nbus-1); % Change in Voltage Angle..

dV = X(nbus:end); % Change in Voltage Magnitude..

% Updating State Vectors..

del(2:nbus) = dTh + del(2:nbus); % Voltage Angle..

k = 1;

for i = 2:nbus

if type(i) == 3

V(i) = dV(k) + V(i); % Voltage Magnitude..

k = k+1;

end

end

Iter = Iter + 1;

Tol = max(abs(M)); % Tolerance..

end

loadflow(nbus,V,del,BMva); % Calling Loadflow.m..

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy