Message Boards Message Boards

Get EvaluationMonitor output iterations taken to find root of equation

I was given the following problem:

Consider the equation x = exp(-x2). Plot the two curves on the same plot to get a rough idea of the intersection point. Then use a built - in function (e.g. FindRoot or FixedPoint or Solve) to find the solution to 100 significant digits and use the option "EvaluationMonitor" to find out how many iterations Mathematica took.

I was able to solve it except for the number of iterations it took to fiu=.

  1. Why isn't it giving me the number of iterations it took to solve it?
  2. How do I fix it?

        In[42]:= f = x
        g = Exp[-x^2]
        Block[{c = 0}, {FindRoot[f == g, {x, 0, 1}, WorkingPrecision -> 100, 
           EvaluationMonitor -> c++], c}]
    
        Out[42]= x
    
        Out[43]= E^-x^2
    
        Out[44]= {{x -> 
           0.65291864041920471553508076735319636992011688110299773062492149407\
        50472761980389255118225716068055969}, 1}
    
POSTED BY: Jules Manson
Posted 4 years ago

You need to use RuleDelayed.

EvaluationMonitor :> c++
POSTED BY: Rohit Namjoshi
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract