Message Boards Message Boards

0
|
1374 Views
|
2 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Access elements of a result from the Solve function.

Posted 10 years ago
If I do this:
S = Solve[x^3 - 2*x^2 + 1 == 0, x]
I get this returned:
{{x -> 1}, {x -> 1/2 (1 - Sqrt[5])}, {x -> 1/2 (1 + Sqrt[5])}}
But I want to be able to take, say, the third expression and assign it to a function called y like:
y=1/2 (1 + Sqrt[5])
But without copy-paste because the actual expression I need to deal with is lengthy and ugly.
So I tried  S[[3]] and that got be something that looks closer, but is still not right.  How do I do it?
POSTED BY: M F
2 Replies
 In[1]:= s = Solve[x^3 - 2*x^2 + 1 == 0, x]
 
 Out[1]= {{x -> 1}, {x -> 1/2 (1 - Sqrt[5])}, {x -> 1/2 (1 + Sqrt[5])}}
 
 In[2]:= y = x /. s[[3]]
 
 Out[2]= 1/2 (1 + Sqrt[5])
 
 In[3]:= y

Out[3]= 1/2 (1 + Sqrt[5])
POSTED BY: Frank Kampas
Please see this article covering the topic:

http://support.wolfram.com/kb/3825
POSTED BY: Sean Clarke
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract