Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2003

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

Search the Archive

RE: How to use Rules from Solve and FindRoot

  • To: mathgroup at
  • Subject: [mg44804] RE: [mg44750] How to use Rules from Solve and FindRoot
  • From: "David Park" <djmp at>
  • Date: Thu, 27 Nov 2003 11:38:31 -0500 (EST)
  • Sender: owner-wri-mathgroup at


A common question. In solving equations, Mathematica always returns the
solutions as a rule or sets of rules. If you save these they are convenient
to use in evaluating expressions.

Here is an example.

xsol = FindRoot[Cos[x] == x, {x, 1}]
{x -> 0.739085}

Then you can use xsol in evaluating an expression, using the ReplaceAll
operator "/.". For example,

(1 - x)/x^2 /. xsol

Or you could Set a value for x by using an immediate replacement.

x = x /. FindRoot[Cos[x] == x, {x, 1}]

Now any expressions involving x will be immediately evaluated, without
having to do a replacement.

(1 - x)/x^2

Which method is better? It is a matter of taste and what is most convenient
for you. The first method is more controlled. You can manipulate symbolic
expressions involving x and substitute its value at the point you wish. The
point is that xsol, or whatever longer name you choose, is less likely to be
used as a symbolic variable in your work.

The second method is more direct but you can no longer use x as a symbolic
variable - until you Clear it, in which case you can't substitute its value
again - until you reset it.

David Park
djmp at

From: GlennRoberts at [mailto:GlennRoberts at]
To: mathgroup at

hi all
i have used the FindRoot function and it returns an output:
{sd -> 10} say

how do i get the output to return it without the sd -> bit ?

thanks for help

Glenn Roberts - HBOS Treasury Services
Interest Rate Derivatives Trading
glennroberts at - 020-7574-8602
33 Old Broad Street, London, EC2N 1HZ

  • Prev by Date: Re: here's one driving me mad!
  • Next by Date: Re: Table format gets lost while write to outputfile?
  • Previous by thread: Mathematica 4.2 and Mandrake 9.2