拉格朗日插值公式 程序
- 格式:doc
- 大小:13.48 KB
- 文档页数:4
- 1 - 拉格朗日插值公式 程序
This article introduces the principle and programming of
Lagrange Interpolation Formula.
一、Lagrange插值函数原理
Lagrange插值函数,又称拉格朗日插值法,是一种基于给定的函数值,以网格点的形式得到函数的近似计算方法。它最早由拉格朗日在18,发现,也称拉格朗日插值方程。
Lagrange interpolation is a method of obtaining
approximate calculation of a function in the form of grid points
based on given function values. It was first discovered by
Lagrange in 18. It is also called the Lagrange interpolation
equation.
它的基本原理是:在给定n+1个数据点(xi,yi),其中xi为给定的点,yi为给定函数yi=f(xi)的值,在它们之间用最低次多项式去近似拟合,用拉格朗日插值法得到的多项式被称为拉格朗日插值多项式.
Its basic principle is: given n + 1 data points (xi, yi),
where xi is the given point and yi is the given function yi =
f (xi) value, approximated with the lowest order polynomial
between them, the polynomial obtained by Lagrange
interpolation is called the Lagrange interpolation polynomial.
二、Lagrange插值函数程序 - 2 - Lagrange插值函数程序基本结构:
The basic structure of the Lagrange interpolation program
is as follows:
1. 定义输入数据
1. Define input data
2. 计算插值函数
2. Calculate interpolation function
3. 根据用户输入的数据求函数值
3. Calculate the function value according to the user input
data
4. 输出结果
4. Output results
以下是一个具体的程序示例:
Here is a specific program example:
#include
#include
// 输入的点的个数
#define N 10
int main()
{ - 3 - double x[N]={-0.8, -0.4, 0.0, 0.4, 0.8, 1.2, 1.6, 2.0, 2.4,
2.8};
double y[N]={1.0, 0.2, -1.3, -1.4, -0.4, 0.3, 0.7, 0.3,
-0.2, -1.0};
double xval;
int i,j;
// 读取要求值的x
printf('请输入要求的值的x:');
scanf('%lf',&xval);
double fval=0;
// 计算插值函数
for(i=0;i { double temp=y[i]; for(j=0;j { if(j!=i) { temp=temp*(xval-x[j])/(x[i]-x[j]); - 4 - } } fval+=temp; } // 输出结果 printf('当x=%.2lf时,插值函数的值为:f(%.2lf)=%.2lf ',xval,xval,fval); return 0; } 三、总结 以上就是拉格朗日插值法的原理和程序的介绍。拉格朗日插值公式是一种常用的插值计算方法,可以实现函数的近似计算,在很多应用场景中都有用。拉格朗日插值法的缺点是,由于给定的数据点过多,构成的拉格朗日插值多项式的次数也较高,计算量增加,计算效率会有所降低。