1.1 Interpolation polynomial
Using polynomials as a tool to study interpolation is called algebraic interpolation. The basic problem is: known functionsin the interval
on
differences
function value at
, find at most one
Degree polynomial:
so that at a given point it is equal toThe same value, that is, the interpolation condition is met:
calledinterpolating polynomial,
calledinterpolation node, abbreviationnode,
calledinterpolation interval. Geometrically,
Sub-degree polynomial interpolation is
points, draw a polynomial curve
approximate curve
。
Degree polynomial (1) has
undetermined coefficients, exactly given by the interpolation condition (2)
equation:
Let the coefficient matrix of this system of equations be, then:
is called the Vandermont determinant. whenWhen they are different from each other, the determinant value is not zero. Therefore the system of equations (3) has a unique solution. This shows that as long as
nodes are different from each other and satisfy the interpolation requirement (2)
The interpolation polynomial (1) is unique.
The difference between the interpolating polynomial and the interpolated function:
It is called the truncation error, also known as the interpolation remainder. whenWhen fully smooth,
Among them,
1.2. Lagrangian interpolation polynomial
In fact, the more convenient way is not to solve equation (3) to find the undetermined coefficients, but to first construct a set of basis functions:Yes
Degree polynomial satisfies:
Order:
The above formula is calledtimes
Interpolation polynomial, uniqueness of solution from equation (3),
nodes
times
The interpolation polynomial exists uniquely.
The pseudo code is as follows
LagrangeInterpolationPolynomia(ele, n, x[], y[]) //ele is the element value that needs to be predicted, n is the number of values provided, x[] and y[] store the known x value and the corresponding y value respectively. sum <- 0 k<-0 while k < n do t<-1 j <- 0 while j < n do if j != k t <- ((ele - x[j])/(x[k] - x[j]))*t sum <- t * y[k] + sum end j <- j + 1 end k <- k + 1 end return sum
c++ implementation
#include <iostream>
using namespace std;
float LagrangeInterpolationPolynomia(float x,int n,float a[],float b[]); int main()
{ float x,y,t,a[100],b[100]; int i,j,k,n; cout << "Enter the value of n"<<endl; cin >> n; cout << "Enter the value of x"<<endl; cin >> x; y = 0; for (i=0;i<n;i++) { cout<< "Input the data of x"<<i<<":"; cin >> a[i]; cout<< "Input the data of y"<<i<<":"; cin >> b[i]; } cout << "y="<<LagrangeInterpolationPolynomia(x,n,a,b)<<endl; return 0;
} float LagrangeInterpolationPolynomia(float x,int n,float a[],float b[])
{ int k; float t,y=0; int j; for (k = 0;k < n;k++) { t = 1; for (j = 0;j < n;j++) { if (j != k) t = ((x - a[j])/(a[k]-a[j]))*t; } y = t * b[k]+y; cout << y << endl; } return y;
}