0

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.

iso
  • 145
  • 3

1 Answers1

1

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.

ubpdqn
  • 60,617
  • 3
  • 59
  • 148