Python Programming
Basics
Numerical Methods
- Bisection Method
- Secant Method
- Regular Falsi (False Position) Method
- Newton Raphson Method
- Gauss Elimination Method
- Gauss Jordan Method
- Gauss-Seidel Method
- Lagrange Interpolation Method
- Newton Divided Difference Interpolation
- Newton Forward Difference Interpolation
- Newton Backward Difference Interpolation
- Trapezoidal Rule
- Simpson 1/3rd Rule
- Simpson 3/8 Rule
- Euler’s Method
- Euler’s Modified Method
- Runge-Kutta 2nd Order Method
- Runge-Kutta 4th Order Method
- Cubic Spline Method
- Bilinear Interpolation Method
- Milne’s Method
- More topics coming soon…
Advance Numerical Methods
The bisection method is a root-finding algorithm that applies to equations in the form of f(x) = 0.
It works by repeatedly bisecting the interval between the current lower and upper bounds, and selecting the subinterval where the function changes sign as the new search interval.
The algorithm terminates when the size of the interval is smaller than a specified tolerance.
Bisection method in Python:
- Function
f(x) = $x^{2} – x – 1$
def bisect(f, a, b, tol=1e-9):
"""
f: a function that takes a single argument
a: lower bound of the interval
b: upper bound of the interval
tol: tolerance for the stopping criterion
"""
# Bisection Method [By Bottom Science]
while (b-a) > tol:
c = (a+b) / 2
if f(c) == 0:
return c
elif f(a)*f(c) < 0:
b = c
else:
a = c
return (a+b)/2
# Test
def f(x):
return x**2 - x - 1
root = bisect(f, 0, 2, 1e-6)
print(root)
# Output: 1.61803399