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

📄 example_3.cpp

📁 lagrange算法的小实践
💻 CPP
字号:
// Example_3.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "iostream.h"

int main(int argc, char* argv[])
{
	float pointX;
	float pointY;	
	int count=0;
	float inputX;
	double f=0;
	printf("Input the number of the points!\n");
	cin>>count;
	double **points=new double*[count];
	double *L=new double[count];

	for(int k=0;k<count;k++)
	{
	 points[k]=new double[2];
	}  
    printf("Input the each points!\n");
	for(int j=0;j<count;j++)
	{
	  scanf("(%f,%f)",&pointX,&pointY);
	  points[j][0]=pointX;
	  points[j][1]=pointY;	  
	}
    cout<<"Input the value of the X:\nX=";
	cin>>inputX;
	for(int i=0;i<count;i++)
	{
		L[i]=1;
	   for(int t=0;t<count;t++)
	   {
		   if(t!=i)
		   {
	         L[i]=L[i]*(inputX-points[t][0])/(points[i][0]-points[t][0]);
		   }
	   }
	   f=f+L[i]*(points[i][1]);
	}
    printf("f(%.2f)=%f \n",inputX,f);
	return 0;
}

⌨️ 快捷键说明

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