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!
0 个评论
采纳的回答
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
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).
更多回答(0 个)
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!