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

📄 niudun ok.cpp

📁 数值分析中一般的插值算法 牛顿和龙悲歌算法
💻 CPP
字号:
#include<iostream>
using namespace std;
float x[100],y[100];
float f(int s,int t)
{
 if(t==s+1)
  return (y[t]-y[s])/(x[t]-x[s]);
 else
  return (f(s+1,t)-f(s,t-1))/(x[t]-x[s]);  
}
float Newton(float m,int count)
{
 float t=1.0;
 float p=y[0];
 float yt=0.0;
 for(int j=1;j<=6;j++)
 {
  t=(m-x[j-1])*t;
  yt=f(0,j)*t;
  p=p+yt;
 }
 return p;
}
void main()
{
 float m,n;
 int count=6;
 cout<<"请输入6组数据"<<"\n";
 for(int i=0;i<count;i++)
 {
  cout<<"X"<<i+1<<"=";
  cin>>x[i];
  cout<<"Y"<<i+1<<"=";
  cin>>y[i];
 }
 cout<<"请输入x的值:";
 cin>>m;
 n=Newton(m,count);
 cout<<"x="<<m<<";"<<"y="<<n<<endl;
}


⌨️ 快捷键说明

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