Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

So I set a function f[x]

f[x_] := x*E^(-x) - 0.16064

Then I set a variable 'actualroot' to the function FindRoot, starting at 3

actualroot = FindRoot[ f[x], {x, 3} ]

and get the output

{x -> 2.88976}

Later I want to compare this output with a different estimate (-2.88673) of the root, and calculate error, so I have

Abs[ (actualroot - estimateroot)/actualroot ]

and i get this output:

Abs[ (-2.88673 + (x -> 2.88976))/(x -> 2.88976) ]

How do I get mathematica to evaluate this expression? I also tried using N[] to give me a decimal evaluation but it didn't work.

share|improve this question
    
You can use actualroot = FindRoot[f[x], {x, 3}][[1, 2]] –  b.gatessucks Jul 13 '12 at 20:27
add comment

1 Answer

up vote 4 down vote accepted

The usual way to get the values of the results of FindRoot, Solve, etc., which are lists of Rule is the following:

f[x_] := x E^(-x) - 0.16064
actualroot = x /. FindRoot[f[x], {x, 3}]
estimateroot = -2.88673;
Abs[(actualroot - estimateroot)/actualroot]

Output:

2.88976
1.99895

share|improve this answer
    
Thanks, new to mathematica, just diving in –  DWC Jul 13 '12 at 21:05
2  
@DWC well, then it's probably good to know that /. is shorthand for ReplaceAll. Apart from its doc page reading this tutorial on transformation rules will prove fruitful. –  Sjoerd C. de Vries Jul 13 '12 at 21:51
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.