- #1
tim9000
- 867
- 17
Homework Statement
All the necessary data is in the code, I'm just trying to converge NR, I decided to use the equation S = V^2 / Z since I had the admittance matrix and powers (needed voltages)
I think my simple algorithm has a slight issue I can't find.
Homework Equations
Thank you!
The Attempt at a Solution
% ** ENTER THE AMOUNT OF BUS NODES FOR THE SIZE OF THE NETWORK **bus_num = 4 % FOR A N = 4 BUS NETWORK
initial_guess = 1 % Guess voltage in P.U.
slack_bus = 1 % Which bus number is the slack bus
convergence_criterion = input('What do you want the convergence criteria to be? (difference < 1): '); %assignment spec was 0.0001
Imax = input('What do you want the maximum iteration to be? ');
volts = [1; 1; 1; 1]; % Known P.U. bus voltages (inc slack bus Estimation)
real_powers = [0; 0.2; 0.02; 0.2]; % Known P.U. bus P
reactive_powers = [0; 0.15; 0.15; 0.15];% Known P.U. bus Q
Conj_power = conj(complex(real_powers, reactive_powers)); % *** Add Power to create Conjugate Apparent Power ***
bus_row1 = [0, 0.5882-j*2.3529, 0, 1.1765-j*4.7059]; % ENTER THE
bus_row2 = [0.5882-j*2.3529, 0, 0.3846-j*1.9231, 0.5882-j*2.3529]; % ADMITTANCES
bus_row3 = [0, 0.3846-j*1.9231, 0, 1.1765-j*4.7059]; % BETWEEN BUSES
bus_row4 = [1.1765-j*4.7059, 0.5882-j*2.3529, 1.1765-j*4.7059, 0]; % FOR MATRIX BELOW
%{
The above variables represent admittances
corresponding to the following matrix:
[Y11 Y12 Y13 Y14]
|Y21 Y22 Y23 Y24|
Y_mat = |Y31 Y32 Y33 Y34|
[Y41 Y42 Y43 Y44]
User will need define more 'bus_row' variables
as above and add them to the Y_mat below if there
is more than 4 buses:
%}
Y_mat = [bus_row1; bus_row2; bus_row3; bus_row4];
% *** Make the appropreate Admittance matrix for the network: ***
for r = 1 : bus_num,
for c = 1 : bus_num,
if (r ~= c)
Y_mat(r,r) = Y_mat(r,r) + Y_mat(r,c);
end
end
end
% *** Turn the Admittances that arn't on
% the diagonal negative: ***
for I = 1 : bus_num,
for k = 1 : bus_num,
if (I ~= k)
Y_mat(I,k) = -1*Y_mat(I,k);
end
end
end
% ** Newton-Raphson Method ***
volts = [1; 1; 1; 1]; % P.U. bus voltages (inc slack bus Estimation)
last_guess = [0; 0; 0; 0];
itterations = 0;
tol = max(abs(volts - last_guess)); % (volts)^2)*Y_mat = Conj_power(I)
% so:
% function = (volts)^2)*Y_mat
% constant is Conj_power(I)
% Jacobian is (2*volts*Y_mat)
while (tol > convergence_criterion) & itterations < Imax
last_guess = volts; % FOR TESTING CONVERGENCE
for I = 1 : bus_num,
if (I ~= slack_bus)
for k = 1 : bus_num,
C3 = 0;
if (I ~= k)
C3 = (Conj_power(I) - ((volts(k))^2)*Y_mat(I,k))/(2*volts(k)*Y_mat(I,k));
end
end
volts(I) = last_guess(I) + C3; % Residual I believe
tol = max(abs(volts - last_guess));
end
end
itterations = itterations + 1;
end
% *** Display converged result ***
if itterations >= Imax,
disp('Did not converge Newton-Raphson within itteration limit');
else
fprintf('\nBonus: The number of itterations required for Newton-Raphson was: %d.\n\n', itterations)
for I = 1 : bus_num,
fprintf('The voltage for bus %d is %0.4f V real and %0.4f V reactive, with angle %0.2f degrees \n', I, real(volts2(I, 1)), imag(volts2(I, 1)), angle(volts2(I, 1))*180/pi)
if (angle(volts2(I, 1))*180/pi >= 45),
disp('\n This solution seems dodgy, might be wrong convergence answer, try a new initial guess sunshine!')
end
end
end