Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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.

share|improve this question
2  
Use MaxExtraConditions->Infinity (or even just 1). –  Daniel Lichtblau Jun 29 '12 at 17:40

3 Answers 3

up vote 5 down vote accepted

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

share|improve this answer
    
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. –  stevenvh Jun 29 '12 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 '12 at 16:57
    
ConditionalExpression[y==13/2, y==13/2] is not true?? –  stevenvh Jun 29 '12 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 '12 at 17:24
1  
Pretty much what I said in the comment to Jens's answer... :D –  J. M. Jun 30 '12 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
share|improve this answer
    
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 :-). –  stevenvh Jun 29 '12 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. –  Artes Jun 29 '12 at 18:00
    
Nice one! I had no idea of that option +1 –  Rojo Jun 29 '12 at 18:33
    
Very useful (+1) –  Jens Jun 29 '12 at 18:50
    
Rojo and Jens, Thank You ! –  Artes Jun 29 '12 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.

share|improve this answer
5  
More compactly: Solve[y == 3 x + 5 && y == -x + 7, {x}, {y}]. –  J. M. Jun 29 '12 at 17:35

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.