solving a system of equations where some variables are linked to a function
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Emma Van Puyenbroeck
am 18 Feb. 2020
Bearbeitet: darova
am 19 Feb. 2020
I'm analysing a thermodynamic model where I must solve a system of equations for a certain component.
The enthalpy however depends on the temperature and the concentration, which are also unkown variables. is it possible to add the function of the relation between the enthalpy and the concentration in the system of equations?
See below the script that I tried. (eqn 7 and 8 are the ones that don't work currently)
%%variables that are known.
m_3=0.004 ;
h_3=1530;
y_3=0.62;
To=25+273;
P_c=1.5 ;
UA=0.5;
hfg2=2256;
hfg=1815;
%%determine unknown variables.
syms x_5 y_6 m_5 m_6 h_5 h_6 Q_rect T
eqn1= m_3*h_3-m_5*h_5-m_6*h_6-Q_rect==0;
eqn2=Q_rect-m_5*(x_5*hfg+(1-x_5)*hfg2)==0;
eqn3=Q_rect-UA*(T-To)==0;
eqn4=m_3*y_3-m_5*x_5-m_6*y_6==0;
eqn5=m_3-m_6-m_5==0;
eqn6=m_3*(1-y_3)-(1-x_5)*m_5==0;
eqn7=h_5==enthalpyliquid(x_5,T);
eqn8=h_6==enthalpygas(y_6,P_c);
[solm5 ,solm6, solh5, solh6 ,Qrect ,T]=vpasolve([eqn1,eqn2,eqn3,eqn4,eqn5,eqn6,eqn7,eqn8],[x_5, y_6,m_5,m_6,h_5,h_6,Q_rect,T,h_5ex,h_6ex]);
6 Kommentare
Walter Roberson
am 19 Feb. 2020
Those two functions do not do any logical tests on the inputs, and do not use mod() or numeric integration or any complicated functions, and only calculate deterministic values. Under those circumstances, you can pass symbolic variables to the functions to calculate a single formula that expresses the output of the function in terms of the two inputs. The effect is that were you call the function with symbolic inputs it is as-if you replaced the call with the appropriate long formula in construction of the equations, replacing the function call with the expression the function calculates. At that point it stops mattering that you have written a function call: you could have written the messy formula instead right in the equation.
So as far as MATLAB is concerned, under those stated conditions, there is no difference between whether you call a function or write the expression. There is no difference in whether MATLAB can solve the system or not. You really just have a set of simultaneous equations, possibly nonlinear
Akzeptierte Antwort
darova
am 19 Feb. 2020
Bearbeitet: darova
am 19 Feb. 2020
I tried fsolve
%%variables that are known.
m_3=0.004 ;
h_3=1530;
y_3=0.62;
To=25+273;
P_c=1.5 ;
UA=0.5;
hfg2=2256;
hfg=1815;
% x_5 y_6 m_5 m_6 h_5 h_6 Q_rect T
% x(1) x(2) x(3) x(4) x(5) x(6) x(7) x(8)
F = @(x) [m_3*h_3-x(3)*x(5)-x(4)*x(6)-x(7)
x(7)-x(3)*(x(1)*hfg+(1-x(1))*hfg2)
x(7)-UA*(x(8)-To)
m_3*y_3-x(3)*x(1)-x(4)*x(2)
m_3-x(4)-x(3)
m_3*(1-y_3)-(1-x(1))*x(3)
x(5)-enthalpyliquid(x(1),x(8))
x(6)-enthalpygas(x(2),P_c)];
opt1 = optimoptions('fsolve',...
'Display','iter',...
'TolFun',1e-6,...
'TolX',1e-6,...
'MaxIter',1000,...
'MaxFunEvals',6500);
[X,fval] = fsolve(F,ones(1,8)*1,opt1);
X'
fval
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Calculus finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!