I am playing around with scipy.optimize.root
and I am trying to understand what it does and how it works.
My sample code is as follows:
import numpy as np
from scipy.optimize import root
def func(x):
""" test function x + 2 * np.cos(x) = 0 """
f = x + 2 * np.cos(x)
print x,f
return f
def main():
sol = root(func, 0.3)
if __name__ == "__main__":
main()
With the print statement in func I get following output:
[ 0.3] [ 2.21067298]
[ 0.3] [ 2.21067298]
[ 0.3] [ 2.21067298]
[ 0.3] [ 2.21067298]
[-5.10560121] [-4.33928627]
[-1.52444136] [-1.43176461]
[-0.80729233] [ 0.57562174]
[-1.01293614] [ 0.0458079]
[-1.03071618] [-0.0023067]
[-1.02986377] [ 7.49624786e-06]
[-1.02986653] [ 1.20746968e-09]
[-1.02986653] [ -6.66133815e-16]
So far so good. I was now wondering why it calls with the initial value four times? Thank you very much.