Home > equation solving > How to solve an overdetermined system in Mathematica

# How to solve an overdetermined system in Mathematica

May 30Hits:4

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?

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:

[email protected]/* <![CDATA[ */!function(t,e,r,n,c,a,p){try{t=document.currentScript||function(){for(t=document.getElementsByTagName('script'),e=t.length;e--;)if(t[e].getAttribute('data-cfhash'))return t[e]}();if(t&&(c=t.previousSibling)){p=t.parentNode;if(a=c.getAttribute('data-cfemail')){for(e='',r='0x'+a.substr(0,2)|0,n=2;a.length-n;n+=2)e+='%'+('0'+('0x'+a.substr(n,2)^r).toString(16)).slice(-2);p.replaceChild(document.createTextNode(decodeURIComponent(e)),c)}p.removeChild(t)}}catch(u){}}()/* ]]> */[{(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:

[email protected]/* <![CDATA[ */!function(t,e,r,n,c,a,p){try{t=document.currentScript||function(){for(t=document.getElementsByTagName('script'),e=t.length;e--;)if(t[e].getAttribute('data-cfhash'))return t[e]}();if(t&&(c=t.previousSibling)){p=t.parentNode;if(a=c.getAttribute('data-cfemail')){for(e='',r='0x'+a.substr(0,2)|0,n=2;a.length-n;n+=2)e+='%'+('0'+('0x'+a.substr(n,2)^r).toString(16)).slice(-2);p.replaceChild(document.createTextNode(decodeURIComponent(e)),c)}p.removeChild(t)}}catch(u){}}()/* ]]> */[{(x + y + z - 5)^2 + (y - 3)^2}, {x}]



$\{x \to 5 - y - z\}$

You could use Reduce in this case:

Reduce[x + y + z == 5 && y == 3, {x}]

(* output: y == 3 && x == 2 - z *)



ToRules will transform this expression to a list of rules, e.g.

ToRules[Reduce[x + y + z == 5 && y == 3, {x}]]

(* output: {y -> 3, x -> 2 - z} *)



You'll find the explanation in the documentation page of Solve under Options -> MaxExtraConditions, as well as under Possible Issues (in a less obvious form).

You can coerce Solve to give you a solution like this:

In[1]:= Solve[x + y + z == 5 && y == 3, {x}, MaxExtraConditions -> All]
Out[1]= {{x -> ConditionalExpression[2 - z, y == 3]}}



The MaxExtraConditions -> All setting will allow Solve to generate extra conditions, and return a solution that is valid only under these special conditions. By default Solve does not attempt this (usually computationally expensive) manoeuvre. In your specific example it tells you that there are no solutions because there are indeed no solutions unless the very specific condition that y is equal to 3 is true.

I realize that this interpretation of the equations is counterintuitive at first.

The other solution is using Reduce which always attempts to generate all conditions that are necessary for the solution to be valid, even very special ones (e.g. that a must not be zero for a x == 1 to have a solution).

## Related Articles

• ### How to solve an overdetermined system in MathematicaMay 30

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}]

• ### Solving numerically system with MathematicaMay 29

I'm trying to solve the following system with Mathematica: Poblacion = { {1900, 1.65}, {1910, 1.75}, {1920, 1.86}, {1930, 2.07}, {1940, 2.30}, {1950, 2.53}, {1960, 3.02}, {1970, 3.70}, {1980, 4.45}, {1990, 5.30}, {2000, 7.29} } P[t_] := 1 / (-q (K t

• ### Overdetermined System of PDEsFebruary 20

EDIT: Just to clarify a large part of my question is whether there is a way to make Mathematica solve a system with more equations than independent variables (so a system that is overdetermined but has redundancies in it). I'm trying to solve a syste

• ### Solve overdetermined set using Mathematica?August 12

As shown below, this is a overdetermined system. Could you teach me how to find the optimized solution in Mathematica? I know it could be solved by the method of least square, but how to realize it in Mathematica? {E0 - 2 x + 2 y + 2 a - 2 c == 0., E

• ### How to solve a nonlinear overdetermined system of equationsJuly 6

i'm trying to solve a nonlinear overdetermined system of equations (124 equations, 123 variables) i tried this procedure (newton raphson) NewtonExtended[f_List, x_List, x0_List, eps_: 10^-12, n_: 100] := With[{jac = N[Outer[D, f, x]]}, FixedPoint[(#

• ### How to solve this system in mathematicaJanuary 31

I want to solve this system in mathematica and i have applied various functions such as Solve, NSolve, etc. but none of them worked. could you help me how could i find my answer?

• ### Havin the problem with solving a nonlinear overdetermined system of equationsFebruary 5

I am having a problem to solve a nonlinear overdetermined system of equations. According to one of the previous posts, I tried NMinimize, but it didn't work. Shall I use any other method? I will appreciate if somebody can give me some helps. This is

• ### Solving a tridiagonal system of linear equations using the Thomas algorithmMarch 9

I'm trying to write a function that can solve a tridiagonal system of linear equations using the Thomas algorithm. It basically solves the following equation. (Details can be found at the Wiki page here Tridiagonal matrix algorithm.)  \begin{bmatri

• ### Solve huge symbolic system of linear equationsJuly 2

I have a system of 76 symbolic linear equations (i.e. some coefficients are symbolic) with a sparse coefficient matrix. However, neither Solve[] nor LinearSolve[] can solve this system in a reasonable amount of time (I have not received an answer in

• ### How to solve a large system of non-linear equationsFebruary 15

I would like to solve Saha equations on Fe, which have 27 unknowns. Saha equations basically give you the ratios of the unknowns, but the unknowns are subject to constraints. What function shall I use to solve this large system of equations? Because

• ### Solving differential equations with Wolfram MathematicaMarch 25

So i saw this differential equations in my textbook $\frac{{{d^4}\omega }}{{d{x^4}}} + 4{\lambda ^4}\omega = 0$ and i figured why not solve it with majestic Wolfram Mathematica, so i write this code: DSolve[ω''''[x] + 4*λ^4*ω[x] == 0, ω[x],x] the res

• ### How do I solve this ODE numerically in Mathematica?June 17

I want to solve these equations numerically in Mathematica and plot them. $$u'(t)=1.5\,u(t)\,v(t)-u(t) \space \space \space \text{and} \space \space u(0)=0.001$$ v'(t)=-1.5\,u(t)\,v(t) \space \space \space

• ### Are there suitable versioning systems for Mathematica notebooks?September 29

I am considering a project using Mathematica and openCL. I know that the openCL C source code can be tracked. Has anyone used a versioning site or software so multiple developers can modify a common notebook? Is it possible to: check out a notebook n

• ### How to solve this trigonometric system of equations numerically?December 14

How can the following trigonometric system of equations be solved numerically? sys= { 1 - Cos[theta1] - 2/3 Sin[phi + π/6] == 0.227746, h + 2/3 Cos[phi + π/6] - Sin[theta1] == -0.714585, -1. - Cos[theta2] - 2/3 Sin[phi - π/6] == (3 Cos[psi2])/4, 2/5