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

📄 linearapprox.cpp

📁 C++实现的数值分析源程序
💻 CPP
字号:
//直线拟合
#include"LinearApprox.h"
void LinearApprox::Approx(double x[],double y[],int len)
{
	double A1=0,B1=0,C1=0;
	double A2=0,B2=0,C2=0;
	double a,b;

	A1=len;
	for(int i=0;i<=len-1;i++)
	{
		B1+=x[i];
		C1+=y[i];
		A2=B1;
		B2+=pow(x[i],2);
		C2+=x[i]*y[i];
	}

	a=(B2*C1-B1*C2)/(A1*B2-A2*B1);
	b=(A1*C2-A2*C1)/(A1*B2-A2*B1);

	cout<<"--------Linear Approximation--------"<<endl;
	cout<<"Costant a:"<<a<<endl;
	cout<<"Coefficient b of x:"<<b<<endl;
	cout<<"y="<<a<<"+"<<b<<"x"<<endl;
}

⌨️ 快捷键说明

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