Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %matplotlib inline
- import numpy as np
- import matplotlib.pyplot as pl
- import math as m
- #y=1
- def func(x):
- return x - 0.5*m.sin(x) - 1
- def derivFunc(x):
- return 1 - 0.5*m.cos(x)
- x = 1
- iterations = 0
- h = func(x) / derivFunc(x)
- while abs(x - 0.5*m.sin(x) - 1) >= 0.0000000001:
- x = x - func(x)/derivFunc(x)
- print ("Iteration", iterations + 1, " ", x)
- iterations = iterations + 1
- print(" ")
- print("Iterations", iterations)
- print(" ")
- print("The value of x is: ", "%.16f"% x)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement