# Solving a system of nonlinear equations? [closed]

I'm relatively new to using Mathematica so I'm not sure if this is really even possible, but I figured it may be worth a try.

In my Physical Chemistry class today, we were learning about acid/base equilibria, and for one particular problem it came to a point where we had a system of 6 unknowns in 7 equations, however these were nonlinear equations so simple calculator tools and matrices wouldn't be sufficient to calculate them. So I thought perhaps Mathematica would be powerful enough to be able to write a script of some sort to be able to solve them.

The equations in question are as follows. Typically these variables are actually concentrations of some compound, but I've just replaced them with letters to make it simple:

1: x + y = 2z + a + b

2: x + c = 2(z + a)

3: 276 = (x^2)(z)

4: 5.7x10^-10 = [(y)(c)]/(x)

5: 9.8x10^-13 = [(b)(a)]/(z)

6: 9.25 = -log(y)

7: 1x10^-14 = y + c

and we need to solve for x, y, z, a, b, and c. Can this really be done in a simple way? Thanks for any input!

-

## closed as unclear what you're asking by belisarius, Sjoerd C. de Vries, Yves Klett, Kuba, RunnyKineNov 16 '13 at 6:50

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question.If this question can be reworded to fit the rules in the help center, please edit the question.

Your equations aren't in the Mathematica language. Have you ever used it? –  belisarius Nov 13 '13 at 1:23
You have 7 equations, but I keep counting only 6 variables. If you get rid of one equation, it will help. –  Nasser Nov 13 '13 at 1:35
Is your log the natural log or the base-10 log?. That is, can y be expressed as E^-9.25 or 10.^-9.25? –  m_goldberg Nov 13 '13 at 1:37
normally in acid base equilibria you can make approximations such that some variables are so small that they can be assumed to be var->0 (e.g. simplified derivation of weak acid, weak base formulas) in which case this condition can be used as a replacement to obtain a more simplified set of equations. –  Mike Honeychurch Nov 13 '13 at 2:05
HAre the square brackets just brackets, or some kind of operator? If they are just brackets then this can be easily solved manually (apart from the superfluous equation). 6->y, 7-> c, 4->x, 3->z, 2->a, 1->b in that order. Leaves 5 unused. Could be used for a consistency check. If it fails you're out of luck, and your set cannot be solved exactly. –  Sjoerd C. de Vries Nov 13 '13 at 6:46

Your equations don't seem to be consistent.

y = E^-9.25


0.0000961117

c = 10.^-14 - y


-0.0000961117

x = c y/5.7 10.^10


-16.2061

z = 276/x^2


1.05088

a = (x + c)/2 - z


-9.15396

b = x + y - 2 z - a


-9.15377

However,

a b /z


79.7359

while your remaining equation states

9.8x10^-13 = [(b)(a)]/(z)

-
Are you saying all this hard work to come up with some solution and I was using bad equations to start with? oh well....next time I'll avoid Chemistry questions ;) –  Nasser Nov 13 '13 at 2:14

Here are the equations converted to Mathematica code, and 2 ways to solve them. However, since you have more equations than unknowns, I removed one equation. May be someone else can find how to solve them as is using optimiziation or other techniques. (since they are non-linear).

Here it is

eq1 = x + y == 2 z + a + b;
eq2 = x + c == 2 (z + a);
eq3 = 276 == x^2 z;
eq4 = 5.7*10^-(10) x == y c;
eq5 = 9.8*10^(-13) z == (b a);
eq6 = 9.25 == -Log[y];
eq7 = 10^(-14) == y + c;
vars = {x, y, z, a, b, c};

eqs = {eq1, eq2, eq3, eq4, eq5, eq7}; %get rid of eq6


One way is to use FindRoot

FindRoot[eqs, {#, 1} & /@ vars]

{x -> 4.87386225471167, y -> 0.403484099429935, z -> 0.83041781254181,
a -> 5.74150631697568, b -> -0.271918502116189,
c -> 6.41690891852181}


Or if you get rid of equation 6, you can use least squares, since they are linear now:

{bb, mm, dd, cc} = CoefficientArrays[{eq1, eq2, eq3, eq4, eq5, eq7}, vars]
LeastSquares[mm, -bb]

{-8.53857466587453*10^-24, 5.98782155809086*10^-23,
1.71132136027344*10^-23, 1.06957585684783*10^-23,
6.41745514108699*10^-24, 6.41565190082999*10^-23}


I need to work on the overdetermined case for the non-linear.... but you can see the result is all zeros really. May be I made a mistake reading your equations.

-