📄 lagrange.c
字号:
/* HELLO.C -- Hello, world */
#include "stdio.h"
#include "conio.h"
#include "math.h"
#include "stdlib.h"
#ifndef EPSILON
#define EPSILON 0.0000000001
#endif
#define N 3
double lagrange(double x,double xi[N],double yi[N])
{
int i,j;
double y,lix;
y=0.0;
for(i=0;i<N;i++)
{lix=1.0;
for(j=0;j<N;j++)
{
if(j!=i)
{
if(fabs(xi[i]-xi[j])<EPSILON)
{printf("the interpolation base poits overlaping!\n");
getch();
printf("strike any key to exit!\n");
getch();
exit(1);
}
else lix=lix*(x-xi[j])/(xi[i]-xi[j]);
}
}
y=y+yi[i]*lix;
}
return(y);
}
main()
{
double x,y;
static double xi[N]={4.00,6.25,9.00}; /* 一个固定的例子进行说明 */
static double yi[N]={2.00,2.50,3.00};
printf("lagrange interpolation :\n");
getch();
scanf("%lf",&x);
y=lagrange(x,xi,yi);
printf("x=%12.6f p(x)=%15.8f\n",x,y);
getch(); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -