8 views (last 30 days)

Show older comments

Robson Luan do Nascimento de Sousa
on 6 Apr 2021 at 22:48

Commented: Robson Luan do Nascimento de Sousa
on 7 Apr 2021 at 0:35

I'm working on some calculations on chemistry, but the final result on the process is being output as just 1 possible set of vars.

Basically, there are several chemical reactions happening, and each one adds 1 var and 1 equation to the system. This one is composed of 7 reactions so I started with:

syms n1 n2 n3 n4 n5 n6 n7

NxNO = NNO-n2+n4-(2*n7);

NxNO2 = NNO2-(2*n1)-n2-n4+n7;

NxN2O4 = NN2O4-n3;

NxO2 = NO2-n7;

NxHNO2 = n1+(2*n2)+n3-n4-n5;

NxHNO3 = n1+n3+n4-n6;

NxHp = n5+n6;

NxNO3n = n6;

NxNO2n = n5;

The Nx vars are the equivalent to the amount of each substance, as it is consumed or produced. also, the vars n1 to n7 need to be positive values.

The equations I need to solve are expressed as:

Eqn1 = K41 == (NxHNO2*NxHNO3)/((NxNO2*R*T2)^2);

Eqn2 = K42 == (NxHNO2^2)/((NxNO*R*T2)*(NxNO2*R*T2));

Eqn3 = K43 == (NxHNO2*NxHNO3)/(NxN2O4*R*T2);

Eqn4 = K44 == (NxHNO3*(NxNO*R*T2))/(NxHNO2*(NxNO2*R*T2));

Eqn5 = K45 == (NxHp*NxNO2n)/(NxHNO2);

Eqn6 = K46 == (NxHp*NxNO3n)/(NxHNO3);

Eqn7 = K47 == ((NxNO2*R*T2)^2)/(((NxNO*R*T2)^2)*NxO2);

Eqns = [Eqn1, Eqn2, Eqn3, Eqn4, Eqn5, Eqn6, Eqn7];

ns = [n1, n2, n3, n4, n5, n6, n7]

Sol1 = vpasolve(Eqns, ns);

Res = double([Sol1.n1, Sol1.n2, Sol1.n3, Sol1.n4, Sol1.n5, Sol1.n6, Sol1.n7]);

The K vars are constants I input on the code, same for R and T2.

As I try to solve them, the var Res is output as a 1x1 struct that contain the 7 syms for n1:n7, but the syms are composed of (1,1) results, which include negative values, implying this is the only set of vars as solution. I expect at least 7 possible sets, since in the same code I solved a 3 reactions system that input 3+ different sets, wich included a set containing only positive values.

If I try to specify using the command assume, it just returns as sets of (0,1) syms.

John D'Errico
on 6 Apr 2021 at 23:34

First, it can be proven that not all mathematical equations of this sort can be "solved". This goes back as far as Abel-Ruffini. In fact, most such problems will have no solution in the form of radicals and algebraic expressions.

Your problem is one that can, if you keep on solving for one variable in an equation, then substituting it into the others, the result will in general be equivalent to a high order polynomial. And if we look at my previous statement, all you need is a polynomial of degree 5 or higher for a solution to fail to exist in general.

So it is irrelevant what you want to see. When no solution exists, wanting the mathematically impossible is not going to fare well.

In terms of a numerical solution, again, it can be proven that it is generally impossible to insure you can find all solutions to an arbitrarily nasty nonlinear system of equations, using purely numerical solvers.

So, at best you can use a numerical solver (that is what vpasolve is) but using a variety of different starting values. This is called a multi-start method. Then you look to see what different solutions arise, compiling the complete set, and clustering those together that are essentially the same.

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

Start Hunting!