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

📄 新建 文本文档.txt

📁 计算方法之均方差的算法
💻 TXT
字号:
#include <iostream.h>
#include <math.h>
#include <stdlib.h>
int main()
{
	double a,b,a1;
	double x[19]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19};
	double y[19]={0.898,2.38,3.07,1.84,2.02,1.94,2.22,2.77,4.02,4.76,5.46,6.53,10.9,16.5,22.5,35.7,50.6,61.6,81.8};
	int i=19;
	//for (; i<19;i++)
	//{
	//	cout << "please input x" << i+1 << " = " ;
	//	cin >> x[i];
	//	cout << "please input y" << i+1 << " = " ;
	//	cin >> y[i];
	//}
	

	double y1[19];
	int j=i-1;
	i--;
	
	while(j>=0)
	{
		y1[j]= log(y[j]);
		j--;
	}
	double u1,u2=0,u3=0;
	double v1=0,v2=0,v3=0;
	j=i;
	u1=i+1;
	while(j>=0)
	{
		u2=x[j]+u2;
		u3=y1[j]+u3;
		v1=u2;
		v2=x[j]*x[j] + v2;
		v3=x[j]*y1[j] + v3;
		j--;
	}
	b=(v3*u1-v1*u3)/(v2*u1-v1*u2);
	a1=(u3-u2*b)/u1;
	a=exp(a1);
	cout <<"----------a= " << a <<endl;
	cout <<"----------b= " << b <<endl;
	double y_[19],q[19];
	j=i;
	while(j>=0)
	{
		y_[j]=a+b*x[j];
		j--;
	}
	j=i;
	double w=0;
	while(j>=0)
	{
		q[j]=y_[j]-y[j];
		j--;
	}
	j=i;
	while(j>=0)
	{
		w=q[j]*q[j]+w;
		j--;
	}
	cout << "-----------均方差=" << sqrt(w) << endl;
	double d;
	j=i;
	d=q[j];
	while(j>0)
	{ 
		if(fabs(d)<fabs(y_[j-1]-y[j-1]))
		 d=fabs(y_[j-1]-y[j-1]);
		j--;
	}
	cout << "--------最大偏差=" << d <<endl;
	return 0;


		


		






}
		

⌨️ 快捷键说明

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