solving a system of equation using symbolic expressions returns empty solution

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!

 채택된 답변

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

Remember, when you do not specify which variables to solve for, solve will choose by itself
Hi Walter, thank you for your reponse. the other variables not defined as symbolic variable have predefined values. Please see below.
CG0 = 7;
HC = -4;
K0 = 2;
HK = -2.5;
Cm0 = 0.02;
beta = 1500;
R = 8;
T = 300;
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];
sol = solve(eqns, [q_H2O])
sol =
Empty sym: 0-by-1
In this case I still have the same issue. I am not sure what went wrong as 'q_H2O' is the only unknown here.
When you solve(), the number of equality equations cannot exceed the number of unknowns being solved for.
sol = solve(eqns, [q_H2O, CG, K, Cm] )
You are not required to use all of the components returned.
Hi Walter, Thank you again for your comments. I am still confused since I previously used the code to solve another system of equations without issues. Please see below:
ns0 = 2;
chi = 2;
T0 = 296;
T = 300;
b0 = 2e5;
H_CO2 = 60;
R = 8;
t0 = 1;
alpha = 1;
syms P_CO2 q ns b t
eq1 = q == ns*b*P_CO2 / (1+(b*P_CO2)^t)^(1/t);
eq2 = ns == ns0 * exp(chi * (1-T0/T)); % maximum adsorption capacity
eq3 = b == b0 * exp(H_CO2/R/T0 * (T0/T-1)); % adsorption affinity
eq4 = t == t0 + alpha * (1-T0/T); % heterogeneity of the adsorption system
eqns = [eq1, eq2, eq3, eq4];
solve(eqns)
ans =
struct with fields:
b: 3434813230887443/17179869184
ns: 4625311226299041/2251799813685248
q: (15887080197064170033712929842163*P_CO2)/(38685626227668133590597632*(((3434813230887443*P_CO2)/17179869184)^(76/75) + 1)^(75/76))
t: 76/75
I do not really see the primary difference between this code and the code above. In essence, I'm just trying to generate an equation in the form y=f(x) so I can either evaluate 'y' in specific values of 'x' or generate plots of 'y' as a function of 'x'. I appreciate your help!
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).
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개)

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

제품

질문:

2022년 5월 6일

댓글:

2022년 5월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by