• 牛顿插值


    #include<iostream>
    #include<fstream>
    using namespace std;
    double *f;        //系数
    double **xy;       //节点数组
    int n;           //节点个数
    double ff(double **xx,int m)
    {
    	//m=sizeof(xx)/sizeof(xx[0]);    求xx数组的行数
    	if(m==2)
    	{
    		return (xx[m-1][1]-xx[m-2][1])/(xx[m-1][0]-xx[m-2][0]);
    	}
    	else
    	{
    		double **xxfore;        //xx数组的前m-1个元素组成的数组
    		double **xxlast;        //xx数组的后m-1个元素组成的数组
    		xxfore=(double **)new double*[m-1];
    		xxlast=(double **)new double*[m-1];
    		for(int i=0;i<m-1;i++)
    		{
    			 xxfore[i]=new double[2];
    		}
    		for(int i=0;i<m-1;i++)
    		{
    			xxlast[i]=new double[2];
    		}
    		for(int i=0;i<m-1;i++)
    		{
    			xxfore[i][0]=xx[i][0];
    			xxfore[i][1]=xx[i][1];
    			xxlast[i][0]=xx[i+1][0];
    			xxlast[i][1]=xx[i+1][1];
    		}
    		return (ff(xxlast,m-1)-ff(xxfore,m-1))/(xxlast[m-2][0]-xxlast[0][0]);
    	}
    }
    void main()
    {
    	cout<<"请输入节点的个数"<<endl;
    	cin>>n;
    	xy=(double **)new double*[n];
    	for(int i=0;i<n;i++)
    	{
    		xy[i]=new double[2];
    	}
    	ifstream data("data.dat");        //读取数据文件
    	int k=0;
    	while(!data.eof())
    	{
    		data>>xy[k][0]>>xy[k][1];     //将文件中的数据读入数组
    	}
        data.close();                   //关闭数据文件
    	for(int j=n;j!=0;j--)
    	{
    		cout<<ff(xy,j)<<endl;
    	}
    }
    

  • 相关阅读:
    Office加载项安装
    Office加载项
    centos部署vue项目
    centos系统下安装Nginx
    MongoDB 安装笔记
    CDN基本工作过程
    前端常见跨域解决方案(全)
    JS 扁平化(flatten) 数组
    console.log 打印的值不准确
    arr.flat(Infinity)数组扁平化
  • 原文地址:https://www.cnblogs.com/zztong/p/6695286.html
Copyright © 2020-2023  润新知