I would like to understand the reasons and find a way to avoid such behaviour of the Solve
function in Mathematica 8.
Solve[x + y + z == 5 && y == 3 , {x, y}]
(* Out[1]= {{x -> 2 - z, y -> 3}} *)
Solve[x + y + z == 5 && y == 3 , {x}]
(* Out[2]= {} (why empty?) *)
I need to get an answer in the second case. Any suggestions on how to persuade the program to calculate an answer that is even simpler than the first?
Answer
In general, when the system of equations is overdetermined, you have an optimization problem and would therefore not expect Solve
or Reduce
to be the right tools because the equations are likely not solvable "exactly" but only in some "best possible" way.
You would then instead formulate the optimization problem in terms of a merit function that you attempt to extremize. For example, in a system of linear equations you would want to minimize the sum of squares of the error for each equation.
A simple implementation of this would be to use Minimize
, and for more specialized solutions one can use PseudoInverse
or SingularValueDecomposition
. Since your example is very simple, I'll just try to illustrate how to treat it with Minimize
:
Last@Minimize[{(x + y + z - 5)^2, y == 3}, {x}]
Here the y == 3
is entered as a constraint whereas the other equation is converted to a squared "merit function" that has to be minimized. That last function would in general be a sum of several squares if you have more equations.
The result is a Piecewise
expression of which we only need the part that actually satisfies y == 3
:
$ \left\{ x\to\begin{cases} 2-z & y=3\\ \text{Indeterminate} & \text{True} \end{cases}\right\} $
An alternative would be:
Last@Minimize[{(x + y + z - 5)^2 + (y - 3)^2}, {x}]
$ \{x \to 5 - y - z\}$
Comments
Post a Comment