Gauss’s Forward Interpolation


Gauss's Forward Interpolation is a numerical method that enables us to ascertain the value of a function at a certain point within a specific range using a sequence of equally spaced data points. This method of polynomial interpolation uses Newton's Divided Difference Formula to calculate the coefficients of the polynomial. This method is particularly useful for estimating values for several equally spaced locations inside a given range. We'll examine the Python implementation method in this article.

Installation

To use Gauss' Forward Interpolation method, the numpy library can be installed via this command since we will be performing complex mathematical calculations.

pip install numpy

Algorithm

  • Let's start by inputting the function f(x), the range of x values [a,b], the number of equally spaced data points n, and the point at which we want to approximate the function value x0. We need to determine the spacing h between data points first, which we can do by using the formula h = (b-a)/(n-1).

  • Next, we need to create an array D that will store the divided differences of f(x) at equally spaced points. To do this, we can assign D[i,0] with f(a + (i-1)h) for I ranging from 1 to n, which will help us compute the major section of D. For the excess sections of D, we can use the formula D[i,j] = (D[i,j-1] - D[i-1,j-1])/(jh), where i runs from j+1 to n and j ranges from 1 to n-1.

  • The interpolating polynomial's coefficients can be determined once the divided differences of f(x) at equally spaced points fill our array D.

  • Finally, we can use the formula P(x0) = c[1] + (x0 - a)c[2] + (x0 - a)(x0 - a - h)c[3]/2 +... to evaluate the interpolating polynomial at x0 (x0). This can be accomplished by setting c[j] equal to D[j,j] for j ranging from 1 to n.

Example

Approximating the function sin(x) at x = 0.2 using 5 equally spaced data points in the range [0,1] −

import numpy as np

# Define the function
def f(x):
   return np.sin(x)

# Set up the inputs
a = 0
b = 1
n = 5
x0 = 0.2

# Calculate the spacing
h = (b - a)/(n - 1)

# Calculate the divided differences
D = np.zeros((n,n))
for i in range(n):
   D[i,0] = f(a + i*h)
for j in range(1,n):
   for i in range(j,n):
      D[i,j] = (D[i,j-1] - D[i-1,j-1])/(j*h)

# Calculate the coefficients
c = np.zeros(n)
for j in range(n):
   c[j] = D[j,j]

# Evaluate the interpolating polynomial
P = c[0]
for j in range(1,n):
   prod = 1
   for k in range(j):
      prod = (x0 - a - k*h)
   P += prod*c[j]/np.math.factorial(j)

print("Approximation of sin(0.2): ", P)

Output

Approximation of sin(0.2):  0.20824045983077355 
  • The function f(x) is defined to calculate sin(x).

  • a, b, n, and x0 are initialized as input values.

  • The spacing h is calculated as (b - a)/(n - 1).

  • The divided differences D are calculated by filling the first column with the function values at evenly spaced points, and then the rest of the columns using the formula (D[i,j-1] - D[i-1,j-1])/(j*h).

  • The coefficients c are calculated by taking the diagonal of the divided differences matrix.

  • The interpolating polynomial is evaluated using the coefficients c and the input value x0. The prod variable is used to calculate the product of (x0 - a - k*h) for the required values of k. Finally, the P variable is updated using this product and the coefficients.

  • The output of this code is the approximation of sin(0.2). The implementation can be modified for different input values and functions.

2. Approximating the function e^(x/2) at x = 1.5 using 4 equally spaced data points in the range [1,2] −

import numpy as np

# Define the function
def f(x):
   return np.exp(x/2)

# Set up the inputs
a = 1   # Lower limit
b = 2   # Upper limit
n = 4   # data pts count
x0 = 1.5   # Interpolation point

# Calculate the spacing
h = (b - a)/(n - 1)

# Calculate the divided differences
D = np.zeros((n,n))   # Initialize divided differences matrix
for i in range(n):
   D[i,0] = f(a + i*h)
for j in range(1,n):
   for i in range(j,n):
      D[i,j] = (D[i,j-1] - D[i-1,j-1])/(j*h)

# Calculate the coefficients
c = np.zeros(n)
for j in range(n):
   c[j] = D[j,j]

# Evaluate the interpolating polynomial
P = c[0]
for j in range(1,n):
   prod = 1
   for k in range(j):
      prod = prod * (x0 - a - k*h)
   P += prod*c[j]/np.math.factorial(j)

# Print the result
print("Approximation of e^(1.5/2): ", P)

Output

Approximation of e^(1.5/2):  2.1073059306325783

Applications

Gauss' Forward Addition technique can be utilized in various fields like money, material science, designing, and PC illustrations. For instance, it very well may be utilized to introduce monetary information, like stock costs, to gauge future qualities. It can be used to estimate a physical quantity's value at a specific time or location in physics. It can be used in engineering to estimate the behavior of a complicated system, like an aircraft, based on a small amount of data. In visualizations, it very well may be utilized to add the variety or power of pixels in a picture to make a smooth progress between neighboring pixels.

Conclusion

The numerical Gauss's Forward Interpolation method, which interpolates a function using a series of evenly spaced data points, was covered in this article. We thoroughly discussed the technique and included several Python implementation examples. The use of Gauss' Forward Interpolation technique in many domains was also covered. Overall, Gauss' Forward Interpolation approach may be applied in a number of real-world scenarios and is a valuable tool for approximating functions.

Updated on: 22-Aug-2023

830 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements