MATLAB Answers

Harish S
0

how to update my new mass flow rate value to the previous value in the loop

Asked by Harish S
on 14 Oct 2018 at 6:31
Latest activity Commented on by Harish S
on 14 Oct 2018 at 7:44

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);

  4 Comments

Show 1 older comment

What are Ms and Cs in the following line?

omega=(Ms*Cs)/(Mg*Cg*1000); 

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

Sign in to comment.

1 Answer

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);

  1 Comment

I did the same stuff in Ms Excel by incrementing Mg value by 0.005. It turns out Tsintial is actually increasing 3to4K(kelvin) each time. I know it is much easier to do this kind of problem in excel but i want to improve my matlab coding. Anyway thanks man for checking my code.

Sign in to comment.