Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How do I get a numeric value from FindRoot[] ?

1,866 views
Skip to first unread message

David Kirkby

unread,
Aug 10, 2011, 6:52:56 AM8/10/11
to
The output of FindRoot[] when trying to find a root is like:

{x -> 0.49454545}

How can I convert that list, into the number 0.49454545?

In[1]:= FindRoot[x+9,{x,-5}]

Out[1]= {x -> -9.}

In[2]:= Head[%]

Out[2]= List

I can't seem to find any "normal" operations on the list which give me
the number.

Dave

Glenn Carlson

unread,
Aug 11, 2011, 5:20:47 AM8/11/11
to
In[1]:= sol = FindRoot[x + 9, {x, -5}]
x = x /. sol
x + 2.5

Out[1]:= {x -> -9.}

Out[2]:= -9.
Out[3]:= -6.5

Regards,
Glenn

Gary Wardall

unread,
Aug 13, 2011, 6:52:31 AM8/13/11
to

One could also do:

FindRoot[x + 9, {x, -5}][[1]][[2]]

Gary Wardall

Yves Klett

unread,
Aug 14, 2011, 8:20:49 AM8/14/11
to
Notably, Part arguments can be supplied in quite a number of ways,
saving lots of square brackets...

FindRoot[x + 9, {x, -5}][[1, 2]]

Regards,
Yves

0 new messages