You are on page 1of 4

Four bus problem by Newton Raphson Technique.

Screen capture and file listings (Octave)


A Run of the 4 bus power flow problem screen capture using diary filename
octave:21> format long;
octave:22> V=newton_4bus_driver()
iter = 1
print_this =
1.000000000000000
0.983352701232794
0.970953570630931
1.020000000000000

0.000000000000000
-0.930935711658702
-1.787902462719329
1.543833697509041

iter = 2
print_this =
1.000000000000000
0.982422150285440
0.969009823608479
1.020000000000000

0.000000000000000
-0.976035443078277
-1.871974933734553
1.523146505234706

iter = 3
print_this =
1.000000000000000
0.982421039154458
0.969004803661605
1.020000000000000

0.000000000000000
-0.976121969650424
-1.872176708448824
1.523055283209118

iter = 4
print_this =
1.000000000000000
0.982421039171550
0.969004803637172
1.020000000000000

0.000000000000000
-0.976121968687044
-1.872176708580311
1.523055284961013

Powers =
-1.70000000000000
-2.00000000000000
2.38000000000000
-1.05349999999999
-1.23940000000000
V=
1.000000000000000 + 0.000000000000000i
0.982278471825826 - 0.016736247919655i
0.968487547438563 - 0.031657225531476i
1.019639644899401 + 0.027110782899513i
octave:23> diary off

Four bus problem by Newton Raphson Technique. Screen capture and file listings (Octave)

File: newton_4bus_driver.m
function V=newton_4bus_driver();
% routine to drive newton_4bus the 4 bus problem in text using Newton-Raphson method
% uses Ybus=Y4bus()
% uses Powers=S_calc(Ybus,V)
% uses [J,delta_powers,correction,V_updt]=newton_4bus(V,Ybus,Psch,tol)
Ybus=Y4bus(); % get the ybus matrix for the 4 bus problem
V=[1;1;1;1.02]; % initial voltage guess as per Grainger and Stevenson Table 9.3 pg. 338
c=[1;1;1;1;1]; % initial correction vector not used just to get into while loop
tol=1e-8;
% tolerance can be changed computing to approximately 5 decimals.
iter=1;
% keep track of # of iterations
% This is the Pscheduled converted to per unit on 100MVA base See Table 9.2 footnote of text
Psch=[-170;-200;318-80;-105.35;-123.94]/100;
% Main NR iterations
while(norm(c)>tol)
iter
[J,dp,c,V_u]=newton_4bus(V,Ybus,Psch,tol);
print_this = [abs(V_u) angle(V_u)*180/pi] % display the updated magnitude & angle(degrees) of voltages
V=V_u;
% update the voltage at each bus and iterate again if need be.
iter=iter+1;
end;
Powers = S_calc_4bus(Ybus,V)

% calculate final powers at each node and display

Four bus problem by Newton Raphson Technique. Screen capture and file listings (Octave)

File: newton_4bus.m
function [J,delta_powers,correction,V_updt]=newton_4bus(V,Ybus,Psch,tol)
delta2=angle(V(2,1)); % extract angle of V(2,1)
first perturbation variable
V2=abs(V(2,1));
% extract magnitude of V(2,1) fourth perturbation variable
delta3=angle(V(3,1)); % extract angle of V(3,1)
second perturbation variable
V3=abs(V(3,1));
% extract magnitude of V(3,1) fifth perturbation variable
delta4=angle(V(4,1)); % extract angle of V(4,1)
third perturbation variable
V4=abs(V(4,1));
% extract magnitude of V(5,1) NOT PERTURBED
h=tol/1000; % partial derivatives are computed using this step size [f(x+h)-f(x)]/h
% here are the 5 perturbed variables
Vpert1=V;Vpert1(2,1)=V2*exp(j*(delta2+h));
Vpert2=V;Vpert2(3,1)=V3*exp(j*(delta3+h));
Vpert3=V;Vpert3(4,1)=V4*exp(j*(delta4+h));
Vpert4=V;Vpert4(2,1)=(V2+h)*exp(j*delta2);
Vpert5=V;Vpert5(3,1)=(V3+h)*exp(j*delta3);
Powers_unpert=S_calc_4bus(Ybus,V);

%unperturbed Powers has P 3 elements and last two are Q

% perturbed powers one by one


Powers_pert_col1=S_calc_4bus(Ybus,Vpert1);
Powers_pert_col2=S_calc_4bus(Ybus,Vpert2);
Powers_pert_col3=S_calc_4bus(Ybus,Vpert3);
Powers_pert_col4=S_calc_4bus(Ybus,Vpert4);
Powers_pert_col5=S_calc_4bus(Ybus,Vpert5);
% Setup an approx Jacobian using the perturbed and unperturbed powers
J=[(Powers_pert_col1-Powers_unpert)/h (Powers_pert_col2-Powers_unpert)/h (Powers_pert_col3-Powers_unpert)/h
(Powers_pert_col4-Powers_unpert)/h (Powers_pert_col5-Powers_unpert)/h];
% Rhs of Newton Rapshon is delta_powers
delta_powers=Psch-Powers_unpert;
% compute the correction
correction=inv(J)*(delta_powers);
% Convert from correction data (correction_to_delta2, correction_to_delta3, correction_to_delta4,
correction_to_magnitudeV2, correction_to_magnitudeV3)
V_updt=zeros(4,1);V_updt(1,1)=V(1,1);
V_updt(2,1)=(V2+correction(4,1))*exp(j*(delta2+correction(1,1)));

Four bus problem by Newton Raphson Technique. Screen capture and file listings (Octave)
V_updt(3,1)=(V3+correction(5,1))*exp(j*(delta3+correction(2,1)));
V_updt(4,1)=V4*exp(j*(delta4+correction(3,1)));

File: S_calc_4bus.m
function [Powers] = S_calc_4bus(Ybus,V)
I=Ybus*V; % Current
S=V.*conj(I); % Power at each node
P=real(S);Q=imag(S); %Real and reactive parts of the power
P=P(2:4); % Powers needed for 4 bus problem
Q=Q(2:3); % Reactive powers for 4 bus problem
Powers=[P;Q]; % put them together into a vector and return
File: Y4bus.m
function Ybus = Y4bus()
% data from Grainger and Stevenson Table 9.2 in perunit
Y1to2 = 1/(0.01008 + j*0.0504); shuntY1and2=j*0.05125;
Y1to3 = 1/(0.00744 + j*0.03720); shuntY1and3=j*0.03875;
Y2to4 = 1/(0.00744 + j*0.03720); shuntY2and4=j*0.03875;
Y3to4 = 1/(0.01272 + j*0.06360); shuntY3and4=j*0.06375;
% put together the the Ybus matrix as we did in lecture 1 and lecture 2
Ybus=[Y1to2+Y1to3+shuntY1and2+shuntY1and3 -Y1to2 -Y1to3 0;
-Y1to2 Y1to2+Y2to4+shuntY1and2+shuntY2and4 0 -Y2to4;
-Y1to3 0 Y1to3+Y3to4+shuntY1and3+shuntY3and4 -Y3to4;
0 -Y2to4 -Y3to4 Y3to4+Y2to4+shuntY2and4+shuntY3and4];