Menu Close

Newton Backward Difference Interpolation Method | Python

Newton’s Backward Difference Interpolation is a method used to estimate the value of a function at a particular point based on a set of discrete data points.

It is similar to Newton’s Forward Difference Interpolation, but it uses the backward differences of the function values instead of forward differences.

Newton Backward difference interpolation in Python:

				
					import math

# Define the function for Newton's Backward Difference Interpolation
def newton_backward_interpolation(x, y, x_new):
    # Get the number of data points
    n = len(y)

    # Get the common spacing between the x-values
    h = x[1] - x[0]

    # Compute the backward differences of the y-values using a nested loop
    deltas = [y] # initialize a list of lists with y as the first element
    for i in range(1, n):
        delta_i = []
        for j in range(n-i):
            delta_j = deltas[i-1][j+1] - deltas[i-1][j]
            delta_i.append(delta_j)
        deltas.append(delta_i)

    # Compute the coefficients of the backward difference interpolating polynomial using the backward differences
    b = [deltas[0][0] / math.factorial(i) for i in range(n)]
    for i in range(1, n):
        b[i] = deltas[i-1][0] / (math.factorial(i) * h**i)

    # Evaluate the interpolating polynomial at the desired point x_new using a nested loop
    Pn = b[-1] # start with the highest order coefficient
    for i in range(n-2, -1, -1):
        Pn = Pn*(x_new - x[i]) + b[i]
    
    # Return the estimated value of the function at x_new
    return Pn

# Example usage
# Define the data points
x = [0.0, 0.2, 0.4, 0.6, 0.8, 1.0]
y = [1.0000, 1.2214, 1.4918, 1.8221, 2.2255, 2.7183]

# Define the point where we want to estimate the function
x_new = 0.5

# Use the newton_backward_interpolation function to estimate the value of the function at x_new
Pn = newton_backward_interpolation(x, y, x_new)

# Print the estimated value of the function at x_new
print(f"Pn({x_new}) = {Pn}")

#Output - Pn(0.5) = 1.6604399999999998
				
			

More Related Stuff