Solving 4 nonlinear equations with 1 unknown

I am solving these four nonlinear equations with the goal of finding taf. I tried using vpa solve but the answer is too big and far from the correct answer. How should I fix this?
dhO2out= r*(O2a*(taf-tref)+(O2b/2)*(taf^2 - tref^2)+O2c*(log(taf)-log(tref))+O2d*((taf*log(taf)-taf)-(tref*log(tref)-tref))+(O2e/3)*(taf^3 - tref^3));
dhN2out= r*(N2a*(taf-tref)+(N2b/2)*(taf^2 - tref^2)+N2c*(log(taf)-log(tref))+N2d*((taf*log(taf)-taf)-(tref*log(tref)-tref))+(N2e/3)*(taf^3 - tref^3));
dhCO2 = r*(CO2a*(taf-tref)+(CO2b/2)*(taf^2 - tref^2)+CO2c*(log(taf)-log(tref))+CO2d*((taf*log(taf)-taf)-(tref*log(tref)-tref))+(CO2e/3)*(taf^3 - tref^3));
dhH2O = r*(H2Oa*(taf-tref)+(H2Ob/2)*(taf^2 - tref^2)+H2Oc*(log(taf)-log(tref))+H2Od*((taf*log(taf)-taf)-(tref*log(tref)-tref))+(H2Oe/3)*(taf^3 - tref^3));
hp = dhO2out+dhN2out+dhH2O == sum (var50);
s = vpasolve (hp,taf,'Random',true);
disp ('The adiabatic flame temperature is (K): ')
fprintf('%+.5f%+.5fi\n', real(s))
Someone suggested that I tried plotting it, locating the taf from the graph and solving it by using fsolve:
taf0 = ...;
taf = fzero(hp,taf0)
However, this method gives me an error:
operator '+' is not supported for operands of type 'function_handle'.
This is the part of the code that is said to cause the error:
hhh = dhH2O+hfh2o;
Please help, THANK YOU!

4 个评论

Works okay for me.
syms taf
rng(655321)
r = rand
r = 0.3140
tref = rand
tref = 0.3864
O2a = rand; O2b = rand; O2c = rand; O2d = rand; O2e = rand;
disp([O2a, O2b, O2c, O2d, O2e]);
0.1855 0.8747 0.7840 0.3012 0.7883
N2a = rand; N2b = rand; N2c = rand; N2d = rand; N2e = rand;
disp([N2a, N2b, N2c, N2d, N2e]);
0.9521 0.6083 0.1490 0.1795 0.7996
CO2a = rand; CO2b = rand; CO2c = rand; CO2d = rand; CO2e = rand;
disp([CO2a, CO2b, CO2c, CO2d, CO2e])
0.2098 0.4060 0.0721 0.5344 0.9759
H2Oa = rand; H2Ob = rand; H2Oc = rand; H2Od = rand; H2Oe = rand;
disp([H2Oa, H2Ob, H2Oc, H2Od, H2Oe])
0.1442 0.4044 0.3171 0.1434 0.0333
var50 = rand()*5
var50 = 4.8986
dhO2out= r*(O2a*(taf-tref)+(O2b/2)*(taf^2 - tref^2)+O2c*(log(taf)-log(tref))+O2d*((taf*log(taf)-taf)-(tref*log(tref)-tref))+(O2e/3)*(taf^3 - tref^3));
dhN2out= r*(N2a*(taf-tref)+(N2b/2)*(taf^2 - tref^2)+N2c*(log(taf)-log(tref))+N2d*((taf*log(taf)-taf)-(tref*log(tref)-tref))+(N2e/3)*(taf^3 - tref^3));
dhCO2 = r*(CO2a*(taf-tref)+(CO2b/2)*(taf^2 - tref^2)+CO2c*(log(taf)-log(tref))+CO2d*((taf*log(taf)-taf)-(tref*log(tref)-tref))+(CO2e/3)*(taf^3 - tref^3));
dhH2O = r*(H2Oa*(taf-tref)+(H2Ob/2)*(taf^2 - tref^2)+H2Oc*(log(taf)-log(tref))+H2Od*((taf*log(taf)-taf)-(tref*log(tref)-tref))+(H2Oe/3)*(taf^3 - tref^3));
hp = dhO2out+dhN2out+dhH2O == sum (var50);
s = vpasolve(hp,taf,'Random',true);
disp ('The adiabatic flame temperature is (K): ')
The adiabatic flame temperature is (K):
fprintf('%+.5f%+.5fi\n', real(s))
+2.25283
vpa(subs(hp, s))
ans = 
Yes it works to me too, but the answer is incorrect as I get almost 30,000. If I compute it through excel, the answer is just around 2000, which is the correct answer.
Not much we can do to test without access to values for all of those variables.
Luckily, you don't actually have 4 equations, because in the end, you add things together. You have one equation, and one unknown.
In the example Walter gave, he substituted in random values for all of the other unknown parameters, and so he got an answer. But since the answer will be a function of the unknown parameters, nobody can really help you. So if you want more help, then you need to tell us what are the values of those parameters.
And, yes, you can add things together, but you cannot add function handles. You can only add the result of those function handles.

请先登录,再进行评论。

回答(1 个)

Hi Vernice,
I understand that you are experiencing issues while solving a system of equations in MATLAB. I attempted to solve the equations using random values for the variables you mentioned, and the "vpasolve" function provided a valid solution. Without access to the specific values you are using, it is difficult to determine the exact issue you are facing.
Regarding the error you encountered while plotting the function, it is likely due to the addition of function handles. "dhH2O" and "hfh2o" are not variables; they are function handles, which are essentially aliases for functions. You cannot directly add function handles together. If you want to evaluate them and then add the results, you need to call the function handles first and then perform the addition. Here's an example:
value1 = dhH2O();
value2 = hfh2o();
hhh = value1 + value2;
Note that you may need to provide inputs to the functions based on your specific implementation. You can refer to the following link for the documentation on function handles: https://www.mathworks.com/help/matlab/function-handles.html
Hope this information helps you address the issue.

类别

帮助中心File Exchange 中查找有关 Data Type Identification 的更多信息

产品

版本

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by