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.

This question already has an answer here:

If I do

sol=Solve[{2x+2==y,3x+9==y},{x,y}]

then Mathematica will tell me

{{x -> -7, y -> -12}}

But I would like to store values to x and y even if I don't write the following thing explicitly.

x = -7
y = -12

At least I know this is possible, because I found how to do it by myself. But now I forgot. But I am sure it is possible.

share|improve this question

marked as duplicate by Kuba, george2079, bobthechemist, m_goldberg, Artes Apr 2 at 14:22

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
Take a look here –  Kuba Apr 2 at 12:41

1 Answer 1

up vote 1 down vote accepted

You can store the pair as follows (in this case in a and b).

{a, b} = {x, y} /. First@Solve[{2 x + 2 == y, 3 x + 9 == y}, {x, y}]

You can relable as you see fit.

Similarly, you can just substitute in an expression, e.g.

x^2 + y^2 /. First@Solve[{2 x + 2 == y, 3 x + 9 == y}, {x, y}]

yields 193.

Note in this case there is a unique solution so First is fine.

share|improve this answer

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