Effacer les filtres
Effacer les filtres

how to implement a recursion function in the following code?

1 vue (au cours des 30 derniers jours)
B
B le 29 Mar 2015
Modifié(e) : James Tursa le 29 Mar 2015
hello: In the following code, a while loop was used to converge the variable Mpw that was first defined based on an assumed value(Mpwini). Convergence criteria is the tolerance between Mpwinitial -Mpw calculated through the equations. I want matlab to take the converging values from the loop at stage n=1 and repeat the calculations again using the previous values in a recursion function for the second stage (function y=stages(n+1)) for n=20 stages. Could you please guide me on that? --------------------------------------------------------------------------------------------------------
function y=stages(n);
Mbint=390;
Tbguess=110;
TCini=107.26;
Tv=80
TV=110;
Mpwini=3;
tolMpw=2;
s0=0.45;
Cp_cavg=4.18;
Tc=103.25;
x=0;
tc=TCini-4;
Tbini=108;
tolTb=2;
Cp=4.18;
n=1;
while tolMpw > 0.0001
A = 8.325e-2 + 1.883e-4*TV + 4.02e-6 *TV^2;
B = - 7.625e-4 + 9.02e-5*TV- 5.2e-7*TV^2;
C = 1.522e-4 - 3e-6*TV - 3e-8*TV^2;
delTv=TV-Tv;
NEA=((33*delTv)^0.33)/TV;
hf= 2501.897149 - 2.407064037* TV + 1.192217e-3*TV^2-1.5863e-5*TV^3;
s=s0+0.001;
BPE=A*s + B*s^2 + C*s^3;
Tv=Tbini-NEA-BPE
Mb=Mbint-Mpwini
Q= Mb*Cp_cavg*(TCini-Tc)
x=0;
Tb=(Mbint*Tbini*Cp-(Q))/(Cp*(Mb))
Mpw=Q/hf
tolMpw=abs(Mpw-Mpwini)
Mpwini=Mpw;
s0=s;
TV=Tv;
end
%values for the next stage
y=stgaes(n+1)
TV=Tv;
Mpwini=Mpw;
Mbint=Mb;
Tbini=Tb;
end
---------------------------------------------------------------------------------------------------------

Réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by