RE: How to use Rules from Solve and FindRoot

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

```Glenn,

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
0.47765

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

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

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

(1 - x)/x^2
0.47765

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

From: GlennRoberts at hbosts.com [mailto:GlennRoberts at hbosts.com]
To: mathgroup at smc.vnet.net

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