what is wrong with this while loop?
Mostrar comentarios más antiguos
function [Gj,Lj,Xij,Yij,Tj]=SR(N,Tj,Fl,Fg,Zij,Qj,TF,Pj)
%inicio
Fj=Fl+Fg;
[Gj,Lj]=MetodoSR(N,Fg,Fl);
Tj0=0;
k=0;
while (((Tj-Tj0)/Tj)^2)>=1e-10 && k<=100
k=k+1;
for k=1:N
Tj0=Tj(N-1);
Kij=ctteK1(Pj,Tj,N);
%Conversion de C a F
Xij=MatrizxijT(N,Fg,Fl,Gj,Kij,Zij);
[Lj,Gj,Xij,Yij]=Flujos(N,Lj,Xij,Fg,Fl,Kij);
Tj=Tj*1.8+32;
TF=Tj*1.8+32;
%Conversion de kmol a lbmol
[MatrizTH]=TH(N,Tj,Xij,Yij,Lj,Gj);
[HFlj,HFgj]=THFeed(N,TF,Zij);
[Tj]=Balance(N,Tj,Yij,Xij,Lj,Gj,Fj,HFlj,HFgj,Qj,MatrizTH);
end
end
2 comentarios
madhan ravi
el 6 de Sept. de 2018
Editada: madhan ravi
el 6 de Sept. de 2018
provide all the datas for (N,Tj,Fl,Fg,Zij,Qj,TF,Pj) and all the functions and paste it here
Giulliana Marin
el 6 de Sept. de 2018
Respuestas (1)
Walter Roberson
el 6 de Sept. de 2018
k=k+1;
for k=1:N
The second of those two lines overwrites the variable 'k' referred to in the first of the lines. After the for loop, k will be left at the last value from the for loop, which is to say N . The while loop will be testing that value against 100. If N < 100, then k will never exceed 100.
6 comentarios
Giulliana Marin
el 6 de Sept. de 2018
Walter Roberson
el 6 de Sept. de 2018
We do not know if you want Tj0 to be repeatedly calculated for each k value. But yes, probably you should be deleting the "for k" loop.
Giulliana Marin
el 6 de Sept. de 2018
Walter Roberson
el 6 de Sept. de 2018
for k = 1 : 100
Kij=ctteK1(Pj,Tj,N);
%Conversion de C a F
Xij=MatrizxijT(N,Fg,Fl,Gj,Kij,Zij);
[Lj,Gj,Xij,Yij]=Flujos(N,Lj,Xij,Fg,Fl,Kij);
Tj=Tj*1.8+32;
TF=Tj*1.8+32;
%Conversion de kmol a lbmol
[MatrizTH]=TH(N,Tj,Xij,Yij,Lj,Gj);
[HFlj,HFgj]=THFeed(N,TF,Zij);
[Tj]=Balance(N, Tj, Yij, Xij, Lj, Gj, Fj, HFlj, HFgj, Qj, MatrizTH);
if abs((Tj-Tj0)/Tj) <= 1e-10; break; end
Tj0 = Tj;
end
Giulliana Marin
el 6 de Sept. de 2018
Walter Roberson
el 6 de Sept. de 2018
That should not be the case, since you had
Tj0=0;
before your loop.
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!