solving a system of equation using symbolic expressions returns empty solution

7 ビュー (過去 30 日間)
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!

採用された回答

Walter Roberson
Walter Roberson 2022 年 5 月 7 日
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 件のコメント
Torsten
Torsten 2022 年 5 月 9 日
編集済み: Torsten 2022 年 5 月 9 日
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 2022 年 5 月 9 日
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!

サインインしてコメントする。

その他の回答 (0 件)

製品

Community Treasure Hunt

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

Start Hunting!

Translated by