Re: How do you input a solution from FindRoot into another equation?
- To: mathgroup at christensen.cybernetics.net
- Subject: [mg760] Re: How do you input a solution from FindRoot into another equation?
- From: wagner at bullwinkle.cs.Colorado.EDU (Dave Wagner)
- Date: Tue, 18 Apr 1995 00:51:00 -0400
- Organization: University of Colorado, Boulder
In article <3mfauj$l4o at news0.cybernetics.net>,
Robert Dack <rdack at acs.ucalgary.ca> wrote:
>
>Can someone tell me how to take the output from the FindRoot
>cammand and input it into the next command line? The output
>comes out in the form { x -> 2.435 }, so the usual [%] command on
>the next line won't work.
>
You can extract the right-hand side of a rule by subscripting part 2:
(x -> 2.435)[[2]] => 2.435
In the example, since the rule is inside a list, you would need to use the
subscript [[1,2]], as shown below:
In[18]:=
FindRoot[BesselJ[0,x], {x,2.}]
Out[18]=
{x -> 2.40483}
In[19]:=
%[[1,2]]
Out[19]=
2.40483
Note that the Solve command returns doubly-nested lists. Here are
some examples of how to extract the answers.
In[20]:=
Solve[x^2==2, x]
Out[20]=
{{x -> -Sqrt[2]}, {x -> Sqrt[2]}}
In[21]:=
{ %[[1,1,2]], %[[2,1,2]] }
Out[21]=
{-Sqrt[2], Sqrt[2]}
In[22]:=
Solve[{x^2-2 == y, x+y==0}]
Out[22]=
{{y -> -1, x -> 1}, {y -> 2, x -> -2}}
In[23]:=
{ %[[1,1,2]], %[[1,2,2]], %[[2,1,2]] }
Out[23]=
{-1, 1, 2}
Extracting the x-value of the second solution in the last example
is left as an exercise for the reader.
Dave Wagner
Principia Consulting
(303) 786-8371
princon at csn.net
http://www.csn.net/princon