0
$\begingroup$

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.

$\endgroup$
4
  • $\begingroup$ 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! $\endgroup$
    – Michael E2
    Commented Jul 26, 2015 at 19:36
  • $\begingroup$ 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. $\endgroup$
    – Michael E2
    Commented Jul 26, 2015 at 19:38
  • $\begingroup$ Look up ReplaceAll[]. $\endgroup$ Commented Jul 26, 2015 at 19:39
  • $\begingroup$ See reference.wolfram.com/language/howto/UseRuleSolutions.html and support.wolfram.com/kb/12505. Related Q&A: (3175), (6669) $\endgroup$
    – Michael E2
    Commented Jul 26, 2015 at 19:47

1 Answer 1

1
$\begingroup$

I would use

{x1, x2} = x /. solutions

The key is ReplaceAll.

$\endgroup$

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