solving a system of equation using symbolic expressions returns empty solution
7 views (last 30 days)
Show older comments
Hello,
I'm trying to solve a system of equation using symbolic expressions but it outputs empty value.
% values are predefined for the following variables: CG0, HC, R, T, K0, Cm0, beta
syms RH q_H2O CG K Cm
eq1 = q_H2O == Cm * CG*K*RH / ((1-K*RH)*(1+(CG-1)*K*RH));
eq2 = CG == CG0*exp(HC/R/T);
eq3 = K == K0*exp(HK/R/T);
eq4 = Cm == Cm0*exp(beta/T);
eqns = [eq1, eq2, eq3, eq4];
[~, ~, ~, q_H2O] = solve(eqns);
Running this code yields:
ans =
struct with fields:
CG: [0×1 sym]
K: [0×1 sym]
RH: [0×1 sym]
q_H2O: [0×1 sym]
I was expecting a result that is a function of 'RH' (q_H2O = f(RH))
But if I predefine 'RH' and run the code (e.g. RH=0.5), this code outputs a value as a result.
I would appreciate any comments!
0 Comments
Accepted Answer
Walter Roberson
on 7 May 2022
syms CG0 HC R T K0 Cm0 beta
syms RH q_H2O CG K Cm HK
eq1 = q_H2O == Cm * CG*K*RH / ((1-K*RH)*(1+(CG-1)*K*RH));
eq2 = CG == CG0*exp(HC/R/T);
eq3 = K == K0*exp(HK/R/T);
eq4 = Cm == Cm0*exp(beta/T);
eqns = [eq1, eq2, eq3, eq4];
sol = solve(eqns, [q_H2O, CG, K, Cm] )
7 Comments
Torsten
on 9 May 2022
Edited: Torsten
on 9 May 2022
As Walter already said:
In your previous code, you specified to solve for one solution variable q_H2O with four equations. This is not possible with solve - the number of equations mustn't exceed the number of variables solved for.
In the code above, you didn't specify the variables to solve for. So MATLAB chose b, ns, q and t as sympathic and expressed q in terms of the last of the five symbolic variables, namely P_CO2. If you try harder, you might find the rule MATLAB applied to choose the variables it solved for (maybe alphabetic order or something similar).
More Answers (0)
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!