⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lagrange.c

📁 拉格朗日插值逼近:在离散数据基础上补插除连续函数是计算数学中最基本最常用的手段是函数逼近的重要方法。
💻 C
字号:
#include<stdio.h>
#define N 1000
void main()
{
	int i,j,k,p;
	float x[N],l[N],f[N],m[N];
	float y,L;
	printf("Please put in the number of the sum of the crunodes:");

	scanf("%d",&k);

	printf("Please put in the values of the crunodes and the function values in order:\n");

	for(i=0;i<k;i++)
		scanf("%f%f",&x[i],&f[i]);

	printf("Please put in the value that you want to get:");
	scanf("%f",&y);

	for(i=0;i<k;i++)
	{
		for(j=0,l[i]=1;j<k;j++)
		{
			if(j==i)
				m[j]=1;
			else
				m[j]=(y-x[j])/(x[i]-x[j]);

			l[i]=l[i]*m[j];
		}
	}
	for(i=0,L=0;i<k;i++)
		L=L+l[i]*f[i];

	printf("The function value you want to get is:%f\n",L);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -