How to update variables in a simple iteration
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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
2 Kommentare
John D'Errico
am 24 Jan. 2023
Bearbeitet: John D'Errico
am 24 Jan. 2023
I doubt I'd call it Gauss-Seidel, since that has a very well defined meaning in mathematics. But you are just performing a simple fixed point iteration.
Anyway, why would you not consider a solving tool, like fsolve instead? Use a tool that is designed to solve a class of problems, rather than trying to invent a possibly poorly convergent tool your own.
Antworten (0)
Siehe auch
Kategorien
Mehr zu Calculus finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!