Clear Filters
Clear Filters

Solving 4 nonlinear equations with 1 unknown

1 view (last 30 days)
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 Comments
Walter Roberson
Walter Roberson on 4 May 2023
Not much we can do to test without access to values for all of those variables.
John D'Errico
John D'Errico on 4 May 2023
Edited: John D'Errico on 4 May 2023
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.

Sign in to comment.

Answers (1)

Yash
Yash on 17 Nov 2023
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.

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Products


Release

R2023a

Community Treasure Hunt

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

Start Hunting!