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

📄 newton.txt

📁 实现牛顿插值多项式的程序源码
💻 TXT
字号:
#include<stdio.h>
#define MAX_N 20
typedef struct tagPOINT
{
 double x;
 double y;
}POINT;
int main()
{
 int n;
 int i,j;
 double points[];
  POINT point[MAX_N+1];double diff[MAX_N];
  double x,tmp,newton=0;
  printf("\nInput n value:");
  scanf("%d",&n);
  if(n>MAX_N)
  {
   printf("The input n is larger than MAX_N,please redefine the MAX_N.\n");
   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),i=0,...,%d:\n",n);
  for(i=0;i<=n;i++)
   scanf("%1f&1f",&points[i].x,points[i].y);
  printf("Now input the x value:");
  scanf("%1f",&x);
  for(i=0;i<=n;i++)
   diff[i]=prints[i].y;
  for(i=0;i<n;i++)
  {
   for(j=n;j>i;j--)
   {
    diff[j]=(diff[j]-diff[j-1])/(prints[j].x-prints[j-1-i].x);
   }
  }
  tmp=1;newton=diff[0];
  for(i=0;i<n;i++)
  {
   tmp=tmp*(x-points[i].x);
   newton=newton+tmp*diff[i+1];
  }
  printf("newton(%f)=%f\n",x,newton);
  return 0;
}

⌨️ 快捷键说明

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