Menu

Computational Mathematics [ Lab Programs ]


triangle using for loop

Aim:

 
UNIT - II: Solution of Algebraic and Transcendental Equations:
Bisection method, Newton Raphson Method
Programs:
      • Root of a given equation using Bisection method.
      • Root of a given equation Newton Raphson Method.

Solution :

Root of a given equation using bisection method.

PROGRAM: (Bisection_Method.py)

 
# Function for which root is found
def f(x):
    return x*x - 4   # change this equation as needed

# Bisection method
def bisection(a, b, e):
    if f(a) * f(b) > 0:
        print("Invalid interval. Root not guaranteed.")
        return

    while (b - a) >= e:
        c = (a + b) / 2

        if f(c) == 0.0:
            break
        elif f(a) * f(c) < 0:
            b = c
        else:
            a = c

    print("Root =", c)

# Input from user
a = float(input("Enter a: "))
b = float(input("Enter b: "))
e = float(input("Enter tolerance: "))

bisection(a, b, e)


OUTPUT:

 
Enter a: 0
Enter b: 3
Enter tolerance: 0.001
Root = 2.000244140625




Related Content :

1.
UNIT - I: Eigen values and Eigenvectors:
Programs:
      • Finding real and complex Eigen values.
      • Finding Eigen vectors.    View Solution


2.
UNIT - II: Solution of Algebraic and Transcendental Equations:
Bisection method, Newton Raphson Method
Programs:
      • Root of a given equation using Bisection method.
      • Root of a given equation Newton Raphson Method.    View Solution


3.
UNIT-III: Linear system of equations:
Jacobi's iteration method and Gauss-Seidal iteration method
Programs:
      • Solution of given system of linear equations using Jacobi's method.
      • Solution of given system of linear equations using Gauss-Seidal method.    View Solution


4.
UNIT-IV: First-Order ODEs:
Exact and non-exact equations, Applications: exponential growth/decay, Newton's law of cooling.
Programs:
      • Solving exact and non-exact equations.
      • Solving exponential growth/decay and Newton's law of cooling problems.    View Solution


5.
UNIT-V: Higher order linear differential equations with constant coefficients:
Programs:
      • Solving homogeneous ODEs.
      • Solving non-homogeneous ODEs.    View Solution