# Why won't Mathematica Solve a set of two equations for one variable? [duplicate]

For example, if I try to Solve this set of equations

Solve[y == 3 x + 5 && y == -x + 7, {x, y}]


Mathematica gives the right values for x and y. But if I try

Solve[y == 3 x + 5 && y == -x + 7, {x}]


it returns nothing. Why is that? There doesn't seem to be a mathematical reason for it.

• Use MaxExtraConditions->Infinity (or even just 1). Jun 29, 2012 at 17:40

That syntax makes Mathematica assume that y can be anything, and if y is different from 13/2, then there's no x, so it can't solve it for the general case.

In other words, Solve must return results that satisfy the equalities. Replacing x by 1/2, the solution you're looking for, doesn't make the equalities be true. For them to be true, you need to solve for y also

EDIT

It seems Solve's third argument also serves as a list of variables to eliminate. So, you should do

Solve[y == 3 x + 5 && y == -x + 7, {x}, {y}]


{{x -> 1/2}}

• I see. Thanks for your answer. But couldn't it return a conditional expression then: ConditionalExpression[1/2, y=13/2]? Too far-fetched? Also, it knows y isn't assigned. Jun 29, 2012 at 16:34
• @stevenvh ConditionalExpression doesn't fit here. If we replaced x->ConditionalExpression[1/2, y==13/2], the equality would turn into something like ConditionalExpression[y==13/2, y==13/2], which is not True. There's nothing I can think of that you can put in place of x (that doesn't assign y an actual value) that would render the equation True. However, I see your point and your intentions. What you want is perhaps more suited for Reduce's spirit I think. This is not my strong area so if you are not satisfied, be hopeful and wait for other answers
– Rojo
Jun 29, 2012 at 16:57
• ConditionalExpression[y==13/2, y==13/2] is not true?? Jun 29, 2012 at 17:08
• @stevenvh it's as much true as If[x == True, True]. The condition is a prerrequisite, not an assumption
– Rojo
Jun 29, 2012 at 17:24
• Pretty much what I said in the comment to Jens's answer... :D Jun 30, 2012 at 3:47

Solve works directly with MaxExtraConditions (new in Mathematica 8) option set All or 1 :

Solve[y == 3 x + 5 && y == -x + 7, x, MaxExtraConditions -> All]

{{x -> ConditionalExpression[1/2, y == 13/2]}}


or solving with respect to y :

Solve[ y == 3 x + 5 && y == -x + 7, {y}, MaxExtraConditions -> 1]

{{y -> ConditionalExpression[13/2, x == 1/2]}}


ConditionalExpression is also new in M8.

In another case one has to use Eliminate :

Eliminate[ y == 3 x + 5 && y == -x + 7, {#}] & /@ {x, y}

{2 y == 13, 2 x == 1}


However using Reduce (it is more universal) there is no need for elimination of variables or using any options :

Reduce[y == 3 x + 5 && y == -x + 7, x]

y == 13/2 && x == 1/2

• Thanks for your answer. You might have guessed that the example wasn't my real problem :-), and eliminating y like in your Solve example is no option. It's a set of 3 equations with 7 variables in $\mathbb{C}$, so I'm not going to eliminate by hand :-). Jun 29, 2012 at 17:58
• @stevenvh Anyway MaxExtraConditions in Solve or Reduce without any option satisfies your needs I hope, as you can read from the answer. Jun 29, 2012 at 18:00
• Nice one! I had no idea of that option +1
– Rojo
Jun 29, 2012 at 18:33
• Very useful (+1)
– Jens
Jun 29, 2012 at 18:50
• Rojo and Jens, Thank You ! Jun 29, 2012 at 20:34

Maybe this is what you want:

Solve[Eliminate[y == 3 x + 5 && y == -x + 7, y], x]

(* ==> {{x -> 1/2}} *)


I first tell Mathematica to reduce the two equations to one by eliminating the variable I don't want to solve for (y), and then solve for the remaining one, x.

• More compactly: Solve[y == 3 x + 5 && y == -x + 7, {x}, {y}]. Jun 29, 2012 at 17:35