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

📄 拉格朗日插值.cpp

📁 利用C语言编写的一些常见的差值程序
💻 CPP
字号:
#include<stdio.h>
#define MAX_N 20
typedef struct tagPOINT
{double x;
 double y;
}POINT;
int main()
{int n;
 int i,j;
   POINT points[MAX_N+1];
   double x,temp,larg=0;
   printf("\nInput n value:");
   scanf("%d",&n);
   if(n>MAX_N)
   {
	   printf("ERROR!please input n again!");
	   return 1;
   }
   if(n<=0)
   {
	   printf("Please input a number between 1 and %d.\n",MAX_N);
	   return 1;
   }
   printf("Now input the (x_i,y_i)\n");
   for(i=0;i<=n;i++)
	   scanf("%lf%lf",&points[i].x,&points[i].y);
   printf("Now input the x value:");
   scanf("%lf",&x);
   for(i=0;i<=n;i++)
   { temp=1;
	   for(j=0;j<=n;j++)
	   {
	   if(j==i)
	      continue;
	  else temp=temp*(x-points[j].x)/(points[i].x-points[j].x);
   }
   larg+=temp*points[i].y;
   
   }
   printf("l(%f)=%f\n",x,larg);
   return 0;
}

⌨️ 快捷键说明

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