How to update new value in next iteration?

1 view (last 30 days)
How can i update that (ending value) U1t or U2t in next iteration.
U1t and U2t will be changed U1 and U2
(1st iteration ending value -> 2nd iteration starting value).
S12t=6+2*1i;
S01t=10+5*1i;
U1=110;
U2=110;
R12 = 16.2+24*1i;
U0i=115;
R01= 15.75+31.2*1i;
dx01=106.125;
dx12=81;
U20=10;
zoruu=0.01;
iteration_number = 0;
while true
iteration_number = iteration_number + 1;
fprintf('Starting iteration #%d\n', iteration_number);
dQ12=dx12*U2.^2*10.^-6;
S12i=S12t-complex(0,dQ12);
DS12 =((real(S12i).^2+imag(S12i).^2)/U2.^2)*R12;
S12ii=DS12+S12i;
S12e=S12ii-complex(0,dQ12);
S01i=S12e+S01t;
dQ01=dx01*U1.^2*10.^-6;
S01ii=S01i-complex(0,dQ01);
DS01=((real(S01ii).^2+imag(S01ii).^2)/U1.^2)*R01;
dQ01i=dx01*U0i.^2*10.^-6;
S01ii2=S01ii+DS01;
S01iii=S01ii2-complex(0,dQ01i);
dU01i=(real(S01ii2)*real(R01)+imag(S01ii2)*imag(R01))./U0i;
dU01ii=(real(S01ii2)*imag(R01)-imag(S01ii2)*real(R01))./U0i;
U1t=sqrt((U0i-dU01i).^2+dU01ii.^2);
dU12i=(real(S12ii)*real(R12)+imag(S12ii)*imag(R12))./U1t;
dU12ii=(real(S12ii)*imag(R12)-imag(S12ii)*real(R12))./U1t;
U2t=sqrt((U1t-dU12i).^2+dU12ii.^2);
Y=U1t-U1;
H=U2t-U2;
if max(Y,H)<zoruu;
break;
end;
end
Iteration must end when max(Y,H)<0.01
Thank you
  1 Comment
Walter Roberson
Walter Roberson on 26 May 2013
Yes, that is what you programmed, that the iterations will end when that condition holds.

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 26 May 2013
After the assignment to H, assign
U1 = U1t;
U2 = U2t;
Unless, that is, you need the U1 value to be unchanged if the iteration should stop. If that is the case, put those two statements after the "end" for the "if"

More Answers (2)

Artur M. G. Lourenço
Artur M. G. Lourenço on 26 May 2013
Sorry if I misunderstood. It would be just that?
S12t=6+2*1i;
S01t=10+5*1i;
U1=110;
U2=110;
R12 = 16.2+24*1i;
U0i=115;
R01= 15.75+31.2*1i;
dx01=106.125;
dx12=81;
U20=10;
zoruu=0.01;
iteration_number = 0;
while true
iteration_number = iteration_number + 1;
fprintf('Starting iteration #%d\n', iteration_number);
dQ12=dx12*U2.^2*10.^-6;
S12i=S12t-complex(0,dQ12);
DS12 =((real(S12i).^2+imag(S12i).^2)/U2.^2)*R12;
S12ii=DS12+S12i;
S12e=S12ii-complex(0,dQ12);
S01i=S12e+S01t;
dQ01=dx01*U1.^2*10.^-6;
S01ii=S01i-complex(0,dQ01);
DS01=((real(S01ii).^2+imag(S01ii).^2)/U1.^2)*R01;
dQ01i=dx01*U0i.^2*10.^-6;
S01ii2=S01ii+DS01;
S01iii=S01ii2-complex(0,dQ01i);
dU01i=(real(S01ii2)*real(R01)+imag(S01ii2)*imag(R01))./U0i;
dU01ii=(real(S01ii2)*imag(R01)-imag(S01ii2)*real(R01))./U0i;
U1t=sqrt((U0i-dU01i).^2+dU01ii.^2);
dU12i=(real(S12ii)*real(R12)+imag(S12ii)*imag(R12))./U1t;
dU12ii=(real(S12ii)*imag(R12)-imag(S12ii)*real(R12))./U1t;
U2t=sqrt((U1t-dU12i).^2+dU12ii.^2);
Y=U1t-U1;
H=U2t-U2;
U1= U1t;
U2= U2t;
if max(Y,H)<zoruu;
break; end; end
  1 Comment
Jan
Jan on 26 May 2013
Please learn how for format code - follow the "? Help" link. Thanks.

Sign in to comment.


Light
Light on 26 May 2013
Thank you very much!! I put it wrong place :-)
  3 Comments
Light
Light on 27 May 2013
Edited: Light on 27 May 2013
Really? Walter Robinson Please tell me. Where can i put this (U1=U1t, U2=U2t)
Is that right??
....
....
Y=U1t-U1;
H=U2t-U2;
if max(Y,H)<zoruu; break; end;
U1= U1t;
U2= U2t; end
Artur M. G. Lourenço
Artur M. G. Lourenço on 27 May 2013
Y=U1t-U1;
H=U2t-U2;
U1= U1t;
U2= U2t;
if max(Y,H)<zoruu;
break; end; end

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!