Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. %matplotlib inline
  2. import numpy as np
  3. import matplotlib.pyplot as pl
  4. import math as m
  5.  
  6. #y=1
  7.  
  8. def func(x):
  9. return x - 0.5*m.sin(x) - 1
  10.  
  11. def derivFunc(x):
  12. return 1 - 0.5*m.cos(x)
  13.  
  14. x = 1
  15.  
  16. iterations = 0
  17.  
  18. h = func(x) / derivFunc(x)
  19.  
  20. while abs(x - 0.5*m.sin(x) - 1) >= 0.0000000001:
  21. x = x - func(x)/derivFunc(x)
  22. print ("Iteration", iterations + 1, " ", x)
  23. iterations = iterations + 1
  24.  
  25. print(" ")
  26. print("Iterations", iterations)
  27. print(" ")
  28. print("The value of x is: ", "%.16f"% x)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement