fork download
  1. eps = 0.001
  2. a = 8
  3. p = 3
  4. count = 0
  5. x_n = a
  6. x_n1 = a + 1 # Initialize to something different
  7.  
  8. while abs(x_n1 - x_n) > eps:
  9. x_n = x_n1 if count > 0 else x_n # Only update after first calculation
  10. x_n1 = (1/p) * ((p-1)*x_n + (a/(x_n**(p-1))))
  11. count += 1
  12.  
  13. print(f"Result: {x_n1}")
  14. print(f"Iteration Count: {count}")
Success #stdin #stdout 0.1s 14192KB
stdin
Standard input is empty
stdout
Result: 2.0000000010711885
Iteration Count: 7