import numpy as np import matplotlib.pyplot as plt #Computing negative eigenvalue of problem 8.46 by Newton's method. def f(x): return np.tanh(x)-x/(2.-x*x) def df(x): return 1./(np.cosh(x)**2)-(2.+x*x)/((2-x*x)**2) eps = 0.0000001 #Tolerance x = 1.3 #Initial value n = 0 print n,': ', x while (np.abs(f(x)) >= eps and n < 50): x = x - f(x)/df(x) n = n+1 print n, ': ', x