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 secant method is a root-finding algorithm that uses a succession of roots of secant lines to better approximate a root of a function.
It is similar to the Newton-Raphson method, but does not require the computation of derivatives.
Secant method in Python:
- Function
f(x) = $x^{2} – x – 1$
def secant(f, x0, x1, tol=1e-9):
"""
f: a function that takes a single argument
x0: initial estimate for the root
x1: second initial estimate for the root
tol: tolerance for the stopping criterion
"""
# Secant Method [By Bottom Science]
while abs(x1 - x0) > tol:
x2 = x1 - f(x1)*(x1 - x0)/(f(x1) - f(x0))
x0, x1 = x1, x2
return x1
# Test
def f(x):
return x**2 - x - 1
root = secant(f, 0, 2, 1e-6)
print(root)
# Output: 1.61803399