0

I'm a beginner to Mathematica. Here's my question.

I'd like to store the output(s) of a Solve command to variable(s) that can be manipulated later.

For example, I would like x1 and x2 to be the two solutions of x^2 - x - 1. I start with this

Clear[f, x]; f[x_] = x^2 - x - 1; solutions = Solve[f[x] == 0, x]

To be clear, I want x1 to have value

(1/2)(1 - Sqrt[5])

and NOT {x -> (1 - Sqrt[5])/2}

so that I could input

x1 + Sqrt[5]

and get output

(1/2)(1 - Sqrt[5])

How do I do this? Any help is much appreciated.

user31012
  • 1
  • 1
  • Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Read the faq! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! – Michael E2 Jul 26 '15 at 19:36
  • You can format inline code and code blocks by selecting the code and clicking the {} button above the edit window. The edit window help button ? is also useful for learning how to format your questions and answers. – Michael E2 Jul 26 '15 at 19:38
  • Look up ReplaceAll[]. – J. M.'s missing motivation Jul 26 '15 at 19:39
  • See http://reference.wolfram.com/language/howto/UseRuleSolutions.html and http://support.wolfram.com/kb/12505. Related Q&A: (3175), (6669) – Michael E2 Jul 26 '15 at 19:47

1 Answers1

1

I would use

{x1, x2} = x /. solutions

The key is ReplaceAll.

Szabolcs
  • 234,956
  • 30
  • 623
  • 1,263