Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python3
- def nsolve(n, a):
- e = 1e-16
- x = float(a)
- while True:
- x2 = x - (x**n - a) / (n * x**(n - 1))
- if abs(x2 - x) < e:
- break
- x = x2
- return x
- for n, a in [(2, 5), (4, 2)]:
- x = nsolve(n, a)
- print(f'x**{n} = {a}, x = {x}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement