0
votes

The If statement inside FindRoot in the following example is evaluating x<100 to be indeterminate. I'm confused as to why and cannot fix it.

The code is:

myroot := FindRoot[If[x < 100, x, x - 1, x - 2], {x, 0}]; myroot

And the output I get is:

{x -> 2.}

where I would expect to see {x -> 0.}. I am using Mathematica 10.0. Thanks!

1

1 Answers

0
votes

The solution is the following piece code:

myroot := FindRoot[If[x < 100, x, x - 1, x - 2], {x, 0}, Evaluated->False]; myroot

FindRoot evaluates the objective function symbolically first which leads to the error of x<100 being indeterminate.