Options for solving a system of non-linear equations

3 views (last 30 days)
I'm building a code to calculate detonation wave velocities for different mixtures and reaction mechanisms. To do so, I need to repeatedly solve a system of non-linear equations involving mass balance and equilibrium constant equations. The mass balance equations are linear, but the other equations are nonlinear. Simple single step reactions can be solved for the species concentrations using solve() or vpasolve(), but these methods are unreliable for more complex multi-step reactions. I've also tried fsolve() to a similar result. I'm trying to find some advice on how to quickly solve these equations in a way that can be easily adapted to different/more complex reaction mechanisms with more reactions and species.
As an example, the following five equations need to be solved for a three-step, five species (x1 - x5) reaction:
syms x1 x2 x3 x4 x5
eqn1 = 2*x2+2*x1+x4+x5 == 2;
eqn2 = 2*x3+x1+x4 == 1;
eqn3 = x1*power(x2,-1)*power(x3,-0.5)*power(po/p2,0.5) == kpR1;
eqn4 = x1*power(x4,-1)*power(x2,-0.5)*power(po/p2,0.5) == kpR2;
eqn5 = x2*power(x5,-2)*(po/p2) == kpR3;
eqns = [eqn1, eqn2, eqn3, eqn4, eqn5];
[sol_xH2O, sol_xH2, sol_xO2, sol_xOH, sol_xH] = vpasolve(eqns, [x1,x2,x3,x4,x5]);
This is all nested within a function inside a loop where an initial temperature guess is compared to the temperature calculated from the Hugoniot equation. The function is called multiple times as the guessed temperature is incremented toward some minimum error value.
Does anyone have any advice on how best to approach this in Matlab, or mathematically in general? Thank you all for your time!

Accepted Answer

Torsten
Torsten on 14 Sep 2022
"fsolve" is the only MATLAB tool to be used for this purpose.

More Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!