How to update variables in a simple iteration

조회 수: 2 (최근 30일)
Kamilu Sanusi
Kamilu Sanusi 2023년 1월 24일
편집: per isakson 2023년 1월 24일
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
John D'Errico
John D'Errico 2023년 1월 24일
편집: John D'Errico 2023년 1월 24일
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.
Kamilu Sanusi
Kamilu Sanusi 2023년 1월 24일
@John D'Errico, thank you so much. First I am still a learner and I need it seriously for my research. I later removed the Gauss Siedel from the title. In order to determine P1, P2, Q1, and Q2, delta(1) and delta(2) must be specified in equations (1 and 2). So, i am using equation (3) to determine delta(2) while delta(1) is set to zero (i.e refrence). I want to be using new values of delta(2) to update equations 1 & 2. My expected results is to display delta(1), delta(2), P1, P2, Q1, and Q2. Please any assistance to improve the program would be highly appreciated

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Calculus에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by