How do I get rid of the arrow ("->") from the output when using
FindRoot?
E.g.
p := FindRoot[x + Log[x] == 5, {x, 1}]
Print[p]
gives the output
{x -> 3.69344}
and then if I change
Print[p]
to
Print[p + 1]
then the output is
{1 + (x -> 3.69344)}
I need to have the output as a number so as to be able to put it into
other functions and plot it.
Cheers,
David
--
David Jones
Very simple :
p = x /. FindRoot[x + Log[x] == 5, {x, 1}]
Greetings !
Florian Jaccard
-----Message d'origine-----
De : David Jones [mailto:djones@REMOVE_THIS.borve.demon.co.uk]
Envoyé : mar., 14. janvier 2003 12:11
À : math...@smc.vnet.net
Objet : Getting rid of the arrow in FindRoot output (newbie
question)
> How do I get rid of the arrow ("->") from the output when using
> FindRoot?
FindRoot will return a rule (indicated by the arrow).
To use the rule value you apply the rule using "/."
Ex.
p := FindRoot[x + Log[x] == 5, {x, 1}]
x /. p
3.69344
Have fun.
J.
p= x/. FindRoot[x + Log[x] == 5, {x, 1}];
Print[p]
??
Regards
Jens
For all people who are new to Mathematica and intend to make some regular
use of it, it strongly advise working through all relevant sections of Part
I in The Mathematica Book. Actually typing in and seeing that each
instruction works properly is a good way to learn. In the long run it will
save a lot of time.
Mathematica generally returns solutions to equations as replacement rules or
a set of replacement rules. These are convenient to use. I would do your
problem this way.
rootsol = FindRoot[x + Log[x] == 5, {x, 1}]
{x -> 3.69344}
Then it can be substituted into any expression in the following manner.
Sin[x] + x^2
% /. rootsol
x^2 + Sin[x]
13.1172
David Park
dj...@earthlink.net
http://home.earthlink.net/~djmp/
From: David Jones [mailto:djones@REMOVE_THIS.borve.demon.co.uk]
should give
3.69344
>
> and then if I change
>
> Print[p]
>
> to
>
> Print[p + 1]
now gives
4.69344
>
> then the output is
>
> {1 + (x -> 3.69344)}
--
Nigel