solving iterative equations in matlab

5 views (last 30 days)
fert
fert on 5 Mar 2016
Commented: Walter Roberson on 6 Mar 2016
For a heat exchanger modelling, I would like to give different equations into the Matlab, and solve the unknowns with respect to equations' relationship. For example these are different equations, and parameters:
. . .
rhogi=rhogo*Pin1g*Tout1g/(Pout1g*Tin1g);
rhog=0.5*(rhogo+rhogi);
Gg=m1g/**Aflow**;
Dh=4***Aflow**/n*pi*Do;
Redh=Gg*Dh/nug;
fo=(delpag-(Gg^2*(1/rhogo-1/rhogi)))*rhog*0.5*Dh/(L*Gg^2);
ratio=Redh/Red;
fo=f*ratio^-0.2; %f=0.046*Redh^-0.2
h=0.95*Ga*0.5*f*(power(Pra,-2/3));
ho=cpg*Gg*0.5*fo*(power(Prg,-2/3));
X=Do/D;
UAh=UA/(h*n*pi*D*L);UAho=UA/(ho.n.pi.Do*L);
UAho=1-Uah;
Adim=**Aflow**/n*D^2;
...
, and among them for example "Aflow" shall exist in three different equations; but in the first line, Matlab stops due to "undefined variable Aflow". I need Matlab to go over all the equations, and find Aflow itself. How can I handle this?

Answers (1)

Walter Roberson
Walter Roberson on 6 Mar 2016
There are three approaches:
  1. Use the Symbolic Toolbox with symbolic equations and use dsolve() or like routines to find a symbolic solution if possible. This would involve defining Aflow as a symbolic variable and solving for it
  2. Use iterative equations. Initialize Aflow to something (0 perhaps) and run a calculation using that value and use the results of the calculation to refine the Aflow value, repeating this process until Aflow stabilizes, indicating consistent equations
  3. Use an ODE routine such as ode45() or ode15s() or possibly bvp4c() depending what you are trying to do.
  7 Comments
fert
fert on 6 Mar 2016
Lets forget about the "solve" function. How can I solve this with "for" loops?
Walter Roberson
Walter Roberson on 6 Mar 2016
After you defined Do as being a symbol, you used
Do=1.2*D;
which redefined it in terms of the symbol D. It is now an expression rather than a symbol by itself, so it cannot be solved for.
Caution: you define
fo=(delpag-(Gg^2*(1/rhogo-1/rhogi)))*rhog*0.5*Dh/(L*Gg^2);
but a couple of lines later you have
fo=f*ratio^-0.2; %f=0.046*Redh^-0.2
which redefines fo as being completely different. There is no point in calculating the first expression if you are going to change the variable before even using it ?

Sign in to comment.

Tags

No tags entered yet.

Community Treasure Hunt

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

Start Hunting!