Asked by Harish S
on 14 Oct 2018 at 6:31

I want Mg values stored in Mgnew everytime and this Mgnew should get updated in the omega so that the loop runs again. Unfortunately the loop is running only one time. What should i do to run the loop several times?. My end goal is to run the loop until Tsintial=1373 and display the values of Mg,omega,Tgout at that particular temperature(Tsintial).

Ms=2; Cs=850; Cg=1.2463; Tsin=473; Tgin=1560; St=8.79; Mg=1; Tsintial=1200; Tsouttemp=1373; while(abs(Tsouttemp-Tsintial)>=1) omega=(Ms*Cs)/(Mg*Cg*1000); Tmid=(Tgin*exp(St*(1-omega))-(omega*Tsin))/(exp(St*(1-omega))-omega; Tsintial=(Tsin-Tmid)*exp(-(1-omega)*St)+Tmid; Tgout=(Tgin-Tmid)*exp((1-omega)*St)+Tmid; Mgnew=Mg+((1373-Tsintial)/10000); Tsouttemp=Tsintial; end Unew=(Ms*Cs)/(Mgnew*Cg*1000) disp(Tsouttemp); disp(Mg); disp(Tgout);

Answer by KALYAN ACHARJYA
on 14 Oct 2018 at 7:04

Edited by KALYAN ACHARJYA
on 14 Oct 2018 at 7:19

**Please note that total numbers of iterations depending on how fast the value Tsintial increasing, maybe it takes a very long time if Tsintial increases in very slow.**

Second case when Tsintial greater than Tsouttemp, while logic will fail.

I dont have the data, if it possible then try it for some small range of values Tsintial & Tsouttemp.

**Be attention during** while loop, if the logic true always, it run continue

I have tested it, it seems to continue, are you sure the following expression increasing the value of Tsintial?

Tsintial=(Tsin-Tmid)*exp(-(1-omega)*St)+Tmid;

Or Increasing in very small steps.

If somehow Tsintial decreasing, the loop runs infinitely.

When Tsintial>Tsouttemp, then Tsintial-Tsouttemp<0, logic fails. loop stop, when Tsintial=Tsouttemp=1373

Tsin=473; Tgin=1560; St=8.79; Mg=1; Ms=2;Cs=850; Cg=1246.3; Tsintial=1200; Tsouttemp=1373; while((Tsouttemp-Tsintial)>=0) omega=(Ms*Cs)/(Mg*Cg*1000); t1=Tgin*exp(St*(1-omega))-omega*Tsin; t2=exp(St*(1-omega))-omega; Tmid=t1/t2; Tsintial=(Tsin-Tmid)*exp(-(1-omega)*St)+Tmid; Tgout=(Tgin-Tmid)*exp((1-omega)*St)+Tmid; Mgnew=Mg+((1373-Tsintial)/10000); Tsouttemp=Tsintial; end Unew=(Ms*Cs)/(Mgnew*Cg*1000); disp(Tsouttemp); disp(Mg); disp(Tgout);

Harish S
on 14 Oct 2018 at 7:44

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 4 Comments

## madhan ravi (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/423881-how-to-update-my-new-mass-flow-rate-value-to-the-previous-value-in-the-loop#comment_622133

format your code by clicking the code button{}

## KALYAN ACHARJYA (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/423881-how-to-update-my-new-mass-flow-rate-value-to-the-previous-value-in-the-loop#comment_622139

What are Ms and Cs in the following line?

## Harish S (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/423881-how-to-update-my-new-mass-flow-rate-value-to-the-previous-value-in-the-loop#comment_622140

I am sorry Ms and Cs are already predefined values. Ms=2, Cs=850,Cg=1.2463.

## KALYAN ACHARJYA (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/423881-how-to-update-my-new-mass-flow-rate-value-to-the-previous-value-in-the-loop#comment_622141

Cg?

Sign in to comment.