Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question already has an answer here:

If I do


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 '14 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 '14 at 12:41
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.