# Newton's method to approximate a solution of f(x)=0 given an initial guess, x0. # The user input is between the hashtags. You can run the code by cutting and # pasting into a SageMath Cell. # def f(x): return x - math.cos(x) def fp(x): return 1.0 + math.sin(x) x0 = 1 N = 10 # x = x0 print(0, x) for i in range(1, N+1): x = x - f(x)/fp(x) print(i, x)