Write a program to find thesquare root of a number. (Newton’s Method).
- def func( x ):return x * x * x - x * x + 2def derivFunc( x ):return 3 * x * x - 2 * xdef newtonRaphson( x ):h = func(x) / derivFunc(x)while abs(h) >= 0.0001:h = func(x)/derivFunc(x)x = x - hprint("The value of the root is : ", "%.4f"% x)x0 = -20newtonRaphson(x0)
Output:-
0 Comments