Solve

Given an algebraic equation with a specific unknown, there may be values for that unknown such that the equation is satisfied:

[> solve( {x*y - 3*x^2*z - y*z = 4*x + 1}, {x} );

$\left\{x = \frac{y -4+\sqrt{-12 y \,z^{2}+y^{2}-8 y -12 z +16}}{6 z}\right\}$ $\left\{x = -\frac{-y +4+\sqrt{-12 y \,z^{2}+y^{2}-8 y -12 z +16}}{6 z}\right\}$

In this case, you may observe that the original equation can be rewritten as a quadratic equation in $x$:

$(-3z)x^2 + (y - 4)x - yz - 1 = 0$

Thus, we can find the solutions using the quadratic formula.

You will note that the solutions are returned as an expression sequence of sets where the unknown is equated to a specific value. Because of the issues with expression sequences, it is best to put the result of solve(...) immediately into a list:

[> [solve( {x*y - 3*x^2*z - y*z = 4*x + 1}, {x} )];

$\left[ \left\{x = \frac{y -4+\sqrt{-12 y \,z^{2}+y^{2}-8 y -12 z +16}}{6 z}\right\}\right.$ $\left.\left\{x = -\frac{-y +4+\sqrt{-12 y \,z^{2}+y^{2}-8 y -12 z +16}}{6 z}\right\}\right]$

Of course, this solution is not valid if $z = 0$, for in that case, the denominator would be zero. If we substitute the value $z = 0$ into the equation, we get a different answer:

[> [solve( eval( {x*y - 3*x^2*z - y*z = 4*x + 1}, z = 0 ), {x} )];

$\left[\left\{x = \frac{1}{y -4}\right\}\right]$

Note that we are explicitly asking for a solution in terms of one of the unknowns. We can also ask for a solution in the other two unknowns:

[> [solve( {x*y - 3*x^2*z - y*z = 4*x + 1}, {y} )];

$\left[\left\{y = \frac{3 x^{2} z +4 x +1}{x -z}\right\}\right]$

[> [solve( {x*y - 3*x^2*z - y*z = 4*x + 1}, {y} )];

$\left[\left\{z = \frac{x y -4 x -1}{3 x^{2}+y}\right\}\right]$

In general, of course, each equation provides one constraint, and thus if there are fewer equations than what is being solved for, there are likely to be no solutions. Maple indicates this by returning a null sequence.

Here we have two equations, but we are solving it for only one unknown $x$. The output indicates that there are no values for $x$ that satisfy both equations:

[> [solve( {x + y = z, 3*x + 4*y - z = 4}, {x} )];

$[]$

We can,however, ask are there values of $x$ and $y$ that satisfy both equations:

[> [solve( {x + y = z, 3*x + 4*y - z = 4}, {x, y} )];

$[\{x = 3 z - 4, y = -2 z + 4\}]$

As you can see, this is a system of two linear equations in the two unknowns $x$ and $y$, and so a unique solution usually exists.

Here is one example of a nonlinear system of two equations in two unknowns where two solutions exist:

[> [solve( {x^2 + y = 1, x + 2*y = 2}, {x, y} )];

$\left[\left\{x = {\frac{1}{2}}, y = {\frac{3}{4}}\right\}, \{x = 0, y = 1\}\right]$

However, this is usually not the case for nonlinear systems of equations. For example, suppose we try to solve the following:

[> solns := [solve( {x^3 + y = 1, x + 2*x*y = z}, {x, y} )];

$solns := \left[\{x = \mathit{RootOf}\! \left(2 \textit{\_Z}^{3}-3 \textit{\_Z} +z \right), y = -\mathit{RootOf}\! \left(2 \textit{\_Z}^{3}-3 \textit{\_Z} +z \right)^{2}+1\}\right]$

This RootOf(...) is a Maple data structure that takes the place of a solution that may be much more complex: RootOf(2*_Z^3 - 3*_Z + z) represents any one of the roots of the expression in the variable _Z. As the expression is a cubic, there are three solutions to $2\zeta^2 - 3\zeta + z$, but if they can even be represented by algebraic expressions, they are potentially complex. We can, however, ask for all values to a given solution:

[> interface( 'imaginaryunit' = 'j' ):
[> asolns := [allvalues( solns[1] )];

$asolns := \left[\left\{x = \frac{\left(-2 z +2 \sqrt{z^{2}-2}\right)^{\frac{1}{3}}}{2}+\frac{1}{\left(-2 z +2 \sqrt{z^{2}-2}\right)^{\frac{1}{3}}} ,\right. \right.$ $\left. y = -\left(\frac{\left(-2 z +2 \sqrt{z^{2}-2}\right)^{\frac{1}{3}}}{2}+\frac{1}{\left(-2 z +2 \sqrt{z^{2}-2}\right)^{\frac{1}{3}}}\right)^{2}+1 \right\},$ $\left\{x = -\frac{\left(-2 z +2 \sqrt{z^{2}-2}\right)^{\frac{1}{3}}}{4}-\frac{1}{2 \left(-2 z +2 \sqrt{z^{2}-2}\right)^{\frac{1}{3}}}+\frac{\mathrm{j} \sqrt{3}\, \left(\frac{\left(-2 z +2 \sqrt{z^{2}-2}\right)^{\frac{1}{3}}}{2}-\frac{1}{\left(-2 z +2 \sqrt{z^{2}-2}\right)^{\frac{1}{3}}}\right)}{2} ,\right.$ $\left.y = -\left(-\frac{\left(-2 z +2 \sqrt{z^{2}-2}\right)^{\frac{1}{3}}}{4}-\frac{1}{2 \left(-2 z +2 \sqrt{z^{2}-2}\right)^{\frac{1}{3}}}+\frac{\mathrm{j} \sqrt{3}\, \left(\frac{\left(-2 z +2 \sqrt{z^{2}-2}\right)^{\frac{1}{3}}}{2}-\frac{1}{\left(-2 z +2 \sqrt{z^{2}-2}\right)^{\frac{1}{3}}}\right)}{2}\right)^{2}+1 \right\},$ $\left\{x = -\frac{\left(-2 z +2 \sqrt{z^{2}-2}\right)^{\frac{1}{3}}}{4}-\frac{1}{2 \left(-2 z +2 \sqrt{z^{2}-2}\right)^{\frac{1}{3}}}-\frac{\mathrm{j} \sqrt{3}\, \left(\frac{\left(-2 z +2 \sqrt{z^{2}-2}\right)^{\frac{1}{3}}}{2}-\frac{1}{\left(-2 z +2 \sqrt{z^{2}-2}\right)^{\frac{1}{3}}}\right)}{2} ,\right.$ $\left. \left. y = -\left(-\frac{\left(-2 z +2 \sqrt{z^{2}-2}\right)^{\frac{1}{3}}}{4}-\frac{1}{2 \left(-2 z +2 \sqrt{z^{2}-2}\right)^{\frac{1}{3}}}-\frac{\mathrm{j} \sqrt{3}\, \left(\frac{\left(-2 z +2 \sqrt{z^{2}-2}\right)^{\frac{1}{3}}}{2}-\frac{1}{\left(-2 z +2 \sqrt{z^{2}-2}\right)^{\frac{1}{3}}}\right)}{2}\right)^{2}+1 \right\}\right]$

We can see what these values are if, for example, $z = 2$:

[> evalf( eval( asolns, z = 2 ) );

$[\{x = 0.7378432590- 0.3650178405 \,\mathrm{j}, y = 0.5888253490+ 0.5386519061 \,\mathrm{j}\},$ $\{x = - 1.475686518- 2.0\times 10^{-10} \mathrm{j}, y = - 1.177650699- 5.902746072\times 10^{-10} \mathrm{j}\},$ $\{x = 0.7378432585+ 0.3650178406 \,\mathrm{j}, y = 0.5888253498- 0.5386519058 \,\mathrm{j}\}]$

You can tell that the first and third solutions are complex conjugates of each other, and the second solution is likely the real numbers:

$\{x = -1.475686518, y = -1.177650699\}$