To find the square root of an integer by Newton Raphson method | Python

Introduction

     The Newton-Raphson method, also known as Newton's method, is a powerful numerical technique used to find the roots of equations. It provides a fast convergence rate for finding solutions to various types of equations. In this blog post, we'll explore how to apply the Newton-Raphson method to find the square root of an integer. We'll provide a Python implementation and discuss the steps involved in the process.


Newton-Raphson Method:

    The Newton-Raphson method is an iterative process for finding the roots of a function f(x). It iteratively improves the estimate


Code

    
     
    print("Enter an integer:")
    n = int(input())

    def f(x, n):
        return x * x - n

    def f1(x):
        return 2 * x

    x = 0.0
    root = 2.0

    while abs(root - x) > 0.000000000001:
        x = root
        root = root - (f(x, n) / f1(x))
        print(root)

    print("The square root of", n, "is approximately:", root)
        
       
     


Output


    Enter an integer:
    25
    1.5625
    7.63392857143
    5.07851458886
    5.01205791439
    5.00002317825
    5.00000000005
    5.0
    The square root of 25 is approximately: 5.0        
       



Conclusion

     The Newton-Raphson method is a versatile technique for finding roots of equations, including square roots. In this blog post, we've discussed how to apply the Newton-Raphson method to find the square root of an integer. We've provided a Python implementation and explained the steps involved in the process. This method offers fast convergence and is widely used in various fields, including mathematics, engineering, and computer science, for solving equations and finding roots of functions.

Post a Comment

0 Comments