1

Below is an example from Power programming with Mathematica by David Wagner. The example is implemented in Mathematica 3.

The sequence of iterates that are generated by FindRoot's internal algorithm can be printed using the following technique:

enter image description here

I did exactly as the one above with Mathematica 10.4 but couldn't get the result as above. Here is what I got:

FindRoot[Print[x];Sin[x]-Cos[x],{x,.5}]

x

{x->0.785398}

Can anyone help me do the same with Mathematica 10.4?

kglr
  • 394,356
  • 18
  • 477
  • 896
emnha
  • 2,101
  • 13
  • 26
  • Hm... Wagner's book was written a long time ago. Seams that things have changed a bit. I recently encountered another issue regarding context & context search (Chapter 8.1.1) which might be closely related to your problem. The explanation in the book is different than in Mathematica documentation. Nevertheless, it goes against encapsulation that you could just like that gain insights into internal operation of FindRoot. I'm also interested in to hear opinion of more experienced users. – ercegovac Sep 29 '17 at 10:58
  • 1
    @ercegovac As to the context issue, check this post: https://mathematica.stackexchange.com/q/43381/1871 – xzczd Sep 29 '17 at 11:24

1 Answers1

2

StepMonitor option seems to work as expected.

In[3]:= FindRoot[Sin[x] - Cos[x], {x, 0.5}, StepMonitor :> Print[x]]

During evaluation of In[3]:= 0.793408

During evaluation of In[3]:= 0.785398

During evaluation of In[3]:= 0.785398

Out[3]= {x -> 0.785398}

Although this does not print the initial value of x as 0.5

Lotus
  • 2,671
  • 11
  • 10