solving a system of equation using symbolic expressions returns empty solution

7 Ansichten (letzte 30 Tage)
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!

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 7 Mai 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 Kommentare
Torsten
Torsten am 9 Mai 2022
Bearbeitet: Torsten am 9 Mai 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).
Tae Lim
Tae Lim am 9 Mai 2022
Hi Walter and Torsten, thank you for your comments! I ended up simplifying my codes to evaluate just one function with one unknown since I can fix all the other variables into certain values (for now). I don't need to worry about a system of equations in this case. I appreciate all your help!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by