How to update variables in a simple iteration
5 views (last 30 days)
Show older comments
Hello everone,
I am trying to solve an equation of which i want to be using the new value as an update. The idea is to use the P and Q calculated in 1 and 2 in equation 3, and the values obtained in 3 is then used in equation 1 and 2 untill delta in equation 3 converges. Is the undelined letters P and Q in 1 and 2 respectively correct?
The expected result is to display P, Q and delta.
% P(i) = P(i) + formula.... % trying to update P and Q
% Q(i) = Q(i) + formula...
THANK YOU
% The formula for calculating the P and Q at each buses 1 & 2
%{
P(i) = sum(j=1->n) |Vi||Vj|(Gij * cos(delta_i - delta_j) +
Bij * sin(delta_i - delta_j)
Q(i) = sum(j=1->n) |Vi||Vj|(Gij * sin(delta_i - delta_j) -
Bij * cos(delta_i - delta_j)
%}
% ........................................................................................................
delta = zeros(2,1);
Ybuskron = [Y11 - Y12*inv(Y22)*Y21];
G = real(Ybuskron); % conductance (G) <- real part of admittance
B = imag(Ybuskron); % susceptance (B) <- the imaginary part of admittance
while (delta_tolerance > 1e-7 || E_angle_tol > 1e-7)
for i = 1:2
for j = 1 : 2
P(i) = P(i) + E(i)*E(j)*(G(i,j)*cos(delta(i)-delta(j)) + ... equation (1)
B(i,j)*sin(delta(i)-delta(j)))
Q(i) = Q(i) + E(i)*E(j)*(G(i,j)*sin(delta(i)-delta(j)) - ... equation (2)
B(i,j)*cos(delta(i)-delta(j)));
end
end
delta(2) = 0;
delta(1) = delta(2) + atan((P(1)/Q(1))); equation (3)
E11(iteration+1,1:2)= abs(E);
E_tolerance = max(abs((E)-(Eprev)));
E_angle_tol = max(abs((angle(E))- angle(Eprev)));
delta_tolerance = max(abs(delta - delta_prev));
Eprev = E; % Vprev is required for next iteration
delta_prev = delta;
iteration = iteration + 1; % Increment iteration count
end
ybus;
E;
delta;
P
Q
Answers (0)
See Also
Categories
Find more on Matrix Computations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!