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

Getting rid of the arrow in FindRoot output (newbie question)

710 views
Skip to first unread message

David Jones

unread,
Jan 14, 2003, 6:18:41 AM1/14/03
to
Hi, this is a newbie question, I am just starting to learn how to use
Mathematica.

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

Florian Jaccard

unread,
Jan 15, 2003, 2:21:01 AM1/15/03
to
Hello !

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)

Harvey P. Dale

unread,
Jan 15, 2003, 2:23:05 AM1/15/03
to

David:
x /. FindRoot[x+Log[x],{x,1}]
Read section 2.4.1 in the Mathematica book.
Best,
Harvey
Harvey P. Dale
University Professor of Philanthropy and the Law
Director, National Center on Philanthropy and the Law
New York University School of Law
Room 206A
110 West 3rd Street
New York, N.Y. 10012-1074

Jeff Williams

unread,
Jan 15, 2003, 2:25:08 AM1/15/03
to
David Jones wrote:

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


Jens-Peer Kuska

unread,
Jan 15, 2003, 2:26:10 AM1/15/03
to
Hi,

p= x/. FindRoot[x + Log[x] == 5, {x, 1}];
Print[p]

??

Regards
Jens

David Park

unread,
Jan 15, 2003, 2:37:36 AM1/15/03
to
David,

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]

Nigel King

unread,
Jan 16, 2003, 3:26:06 AM1/16/03
to
> Hi, this is a newbie question, I am just starting to learn how to use
> Mathematica.
>
> 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}
p := x/.FindRoot[x + Log[x] == 5, {x, 1}]
Print[p]

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

0 new messages