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
Newton divided difference interpolation is a method of constructing a polynomial that passes through a given set of points.
It is similar to Lagrange interpolation, but it tends to be more efficient for large sets of points.
Newton divided difference method in Python:
import numpy as np
def newton_divided_difference(x, y, t):
"""
Find the Newton polynomial through the points (x, y) and return its value at t.
"""
#Newton Divided Difference Interpolation [By Bottom Science]
# Check that the input arrays have the same length
if len(x) != len(y):
raise ValueError("The arrays x and y must have the same length.")
# Initialize the polynomial
p = [y[0]]
# Loop over the differences
for i in range(1, len(x)):
# Initialize the term
term = y[i]
# Loop over the previous differences
for j in range(i):
term = (term - p[j]) / (x[i] - x[j])
# Add the term to the polynomial
p.append(term)
# Evaluate the polynomial at t
result = 0
for i in range(len(x)):
term = p[i]
for j in range(i):
term *= (t - x[j])
result += term
return result
# DATA POINTS (x,y)
x = [0, 1, 2]
y = [0, 1, 4]
t = 0.5
p = newton_divided_difference(x, y, t)
print(p)
# Output - 0.25