Asked by fert
on 5 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?

Answer by Walter Roberson
on 6 Mar 2016

There are three approaches:

- 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
- 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
- Use an ODE routine such as ode45() or ode15s() or possibly bvp4c() depending what you are trying to do.

fert
on 6 Mar 2016

%%%Recuperator 1

Tin1g=197.17+273; Tin1a=29.71+273;

Tout1g=90+273;Tout1a=167.21+273;

Pin1g=1.023;Pin1a=1.176;

Pout1g=1.013;Pout1a=1.166;

m1g=13.53;m1a=11.16;

%%Heat Exchanger Design

Cair1=0.95*m1a; %Tairaverage=371.46 [K]

Cgas1=Cair1*(Tout1a-Tin1a)/(Tin1g-Tout1g); cpg=Cgas1/m1g;

%Cmin=Cair

E=Cair1*(Tout1a-Tin1a)/(Cair1*(Tin1g-Tin1a));

NTU=log((1-(E*Cair1/Cgas1))/(1-E))/(1-(Cair1/Cgas1));

UA=Cair1*NTU;

%%Pressure Drop in Air Side

delpaa=Pin1a-Pout1a;

rhoai=(Pin1a/287*Tin1a);

rhoao=rhoai*Pout1a*Tin1a/(Pin1a*Tout1a);

rhoa=0.5*(rhoao+rhoai);

nua=3.407;

nug=3.600;

Pra=0.685;

Prg=0.686;

syms D L n Aflow Do

Ga=m1a/(pi*D^2/4*n);

Red=Ga*D/nua;

f=(delpaa-(Ga^2*(1/rhoao-1/rhoai)))*rhoa*0.5*D/(L*Ga^2); %%Equation 1

%%Pressure Drop in Gas Side

delpag=Pin1g-Pout1g;

rhogo=(Pout1g/287*Tout1g)

rhogi=rhogo*Pin1g*Tout1g/(Pout1g*Tin1g);

rhog=0.5*(rhogo+rhogi);

Gg=m1g/(Aflow);

Do=1.2*D;

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

F5=(UA/(h*n*pi*D*L))+(UA/(ho*n*pi*Do*L))-1;

% UAho=1-Uah;

Adim=Aflow/n*D^2;

S = solve(f,fo,h,ho,F5,D, L, n, Aflow,Do);

S.D

S.L

S.n

S.Aflow

S.Do

This is my whole code. Now I am getting the error of: "Reference to non-existent field 'Do'.

Error in EnergySystem (line 69) S.Do "

fert
on 6 Mar 2016

Lets forget about the "solve" function. How can I solve this with "for" loops?

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.

Opportunities for recent engineering grads.

Apply Today
## 0 Comments

Sign in to comment.