Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def square_root(a):
- v1 = 1.0
- v2 = 1.0
- r0 = 0
- r = -555
- i = 0
- while(abs(r0 - r) > 0.000001):
- r0 = r
- r = (v1*((a/2)*v1 + a*v2) + v2*(v1 + (a/2)*v2))/(v1*v1 + v2*v2)
- a1 = (a/2) - r
- a2 = -a
- a3 = -1.0
- a4 = (a/2) - r
- v1, v2 = (a1*v1 + a2*v2, a3*v1 + a4*v2)
- v2 = v2/v1
- v1 = 1.0
- i += 1
- print(str(i) + " iterations")
- return r - a/2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement