Lab 9 NC GG
Lab 9 NC GG
Lab 9 NC GG
Numerical Computation
Section: BEE-7A
Advantages:
Ease of Computation: The method is relatively straightforward to implement, and the
forward differences can be computed systematically.
Efficiency: Once the divided differences are calculated, evaluating the interpolating
polynomial at different points is computationally efficient.
Suitability for Equally Spaced Data: Newton's Forward Differences work well when the
data points are equally spaced, making it a practical choice for certain types of data sets.
Disadvantages:
Sensitivity to Data Perturbations: Newton's Forward Differences can be sensitive to small
changes in the input data, which might lead to significant variations in the interpolated
values.
Limited Applicability: The method is specifically designed for equally spaced data points,
and its accuracy may decrease if the data is not uniformly distributed.
In summary, Newton's Forward Differences is a useful interpolation method for equally spaced
data, offering simplicity and efficiency. However, its sensitivity to data perturbations and
limitations in handling unevenly spaced data are important considerations. It's essential to
choose interpolation methods based on the specific characteristics of the given data.
Advantages:
Ease of Computation: Similar to Newton's Forward Differences, the backward differences
method is relatively easy to compute, and the differences can be calculated systematically.
Efficiency: Once the divided differences are calculated, evaluating the interpolating
polynomial at different points is computationally efficient.
Suitability for Equally Spaced Data: Newton's Backward Differences work well when the
data points are equally spaced, making it a practical choice for certain types of data sets.
Disadvantages:
Sensitivity to Data Perturbations: Similar to Newton's Forward Differences, the backward
differences method can be sensitive to small changes in the input data, leading to variations
in the interpolated values.
Limited Applicability: The method is specifically designed for equally spaced data points,
and its accuracy may decrease if the data is not uniformly distributed.
In summary, Newton's Backward Differences is a useful interpolation method for equally spaced
data, offering simplicity and efficiency. However, its sensitivity to data perturbations and
limitations in handling unevenly spaced data are important considerations. It's crucial to choose
interpolation methods based on the specific characteristics of the given data.
Code:
In [7]:
import numpy as np
import matplotlib.pyplot as plt
return F
return B
F = forward_differences(x, y)
result = y[0]
term = 1
equations = [f"{y[0]:.2f}"]
for i in range(1, n):
term *= (t - i + 1) / i
result += term * F[0, i]
equations.append(f"{term * F[0, i]:.2f}")
B = backward_differences(x, y)
result = y[-1]
term = 1
equations = [f"{y[-1]:.2f}"]
for i in range(1, n):
term *= (t + i - 1) / i
result += term * B[n - i - 1, i]
equations.append(f"{term * B[n - i - 1, i]:.2f}")
# Sample data
print("\nBackward Interpolation:")
print(f"Interpolation value at x = {x_interp_backward}: {result_backward}")
print("Equations used:")
for i, eq in enumerate(equations_backward):
print(f"Term {i}: {eq}")
plt.figure(figsize=(8, 6))
plt.scatter(x_values, y_values, label='Original Data Points')
plt.plot(x_plot, y_plot_forward, label='Newton Forward Interpolation', linestyle='--
plt.plot(x_plot, y_plot_backward, label='Newton Backward Interpolation', linestyle='
plt.scatter([x_interp_forward], [result_forward], color='red')
plt.scatter([x_interp_backward], [result_backward], color='blue')
plt.xlabel('x')
plt.ylabel('Pn(x)')
plt.title('Newton Interpolation')
plt.legend()
plt.grid(True)
plt.show()
Forward Interpolation:
Interpolation value at x = 3.0: -5.0
Equations used:
Term 0: 11.00
Term 1: -39.00
Term 2: 84.00
Term 3: -61.00
Term 4: 0.00
Backward Interpolation:
Interpolation value at x = 3.0: -5.0
Equations used:
Term 0: -18.00
Term 1: 13.00
Term 2: -0.00
Term 3: -0.00
Term 4: -0.00