MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: ?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg120809] Re: ?
  • From: Bill Rowe <readnews at sbcglobal.net>
  • Date: Thu, 11 Aug 2011 05:12:08 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com

On 8/10/11 at 6:47 AM, david.kirkby at onetel.net (David Kirkby) wrote:

>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.

The output from FindRoot is a list of replacement rules. When
there is a single replacement rule simply do

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

In[2]:= x /. sol

Out[2]= -9.

When there is more than one replacement rule you will need to
specify which solution you want. For example using Solve

In[3]:= sol = Solve[x^2 == 9, x];

In[4]:= x /. sol[[1]]

Out[4]= -3

In[5]:= x /. sol[[2]]

Out[5]= 3





  • Prev by Date: Re: ?
  • Next by Date: Re: Just another Mathematica "Gotcha"
  • Previous by thread: Re: ?
  • Next by thread: ListDensityPlot and Legend