Unit 2 Interpolation P2
Unit 2 Interpolation P2
Problem 2:- Given a dataset (x, y) corresponding to a physics problem, use Lagrange and
Newton’s forms of interpolating polynomials and compare. Determine the value of y at an
intermediate value of x not included in the data set. This may be done with equally spaced and
Theory:-
basis polynomials that pass through each data point individually. The polynomial has the general
form:
P(x) = ∑ yi . Li(x) ; i = 0 to n.
where:
Each Li(x) polynomial equals 1 at x=xi and 0 at every other xj in the dataset. The entire
polynomial, P(x) is a sum of these basis polynomials, each scaled by the corresponding yi value.
This construction ensures that P(x) passes through all data points (xi,yi).
easier to update if additional points are added. It uses divided differences, which capture the
relationships between the data points more flexibly than the Lagrange basis.
The polynomial can be expressed as:
where:
Divided Differences:
Algorithm:
1. Import necessary libraries.
2. Define the Lagrange Interpolation Function.
3. Put the (x_values, y_values, x) in it.
4. Now Call Newton Interpolation Function.
5. Put the (x_values, y_values) in it.
6. Lastly print the output.