|
|
#pragma once
|
|
|
|
|
|
#ifndef LinearFitting_h__
|
|
|
#define LinearFitting_h__
|
|
|
|
|
|
|
|
|
|
|
|
namespace NChart
|
|
|
{
|
|
|
|
|
|
class AFX_EXT_CLASS CLinearFitting
|
|
|
{
|
|
|
public:
|
|
|
CLinearFitting();
|
|
|
virtual ~CLinearFitting();
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
|
|
//矩阵结构体
|
|
|
struct Matrix
|
|
|
{
|
|
|
int m,n;//m为行数,n为列数
|
|
|
double **pm;//指向矩阵二维数组的指针
|
|
|
};
|
|
|
//初始化矩阵mt,并置矩阵的行为m,列为n
|
|
|
void InitMatrix(struct Matrix *mt,int m,int n);
|
|
|
|
|
|
//用0初始化矩阵mt,并置矩阵的行为m,列为n
|
|
|
void InitMatrix0(struct Matrix *mt,int m,int n);
|
|
|
|
|
|
//销毁矩阵mt
|
|
|
void DestroyMatrix(struct Matrix *mt);
|
|
|
|
|
|
//矩阵相乘mt3=mt1*mt2
|
|
|
//成功返回1,失败返回0
|
|
|
int MatrixMul(Matrix *mt1,Matrix *mt2,Matrix *mt3);
|
|
|
|
|
|
//矩阵转置mt2=T(mt1)
|
|
|
//成功返回1,失败返回0
|
|
|
int MatrixTran(Matrix *mt1,Matrix *mt2);
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
|
|
//Guass列主元素消元法求解方程Ax=b,a=(A,b)
|
|
|
int Guassl(double **a,double *x,int n);
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////
|
|
|
//最小二乘法求解矩阵Ax=b
|
|
|
int MinMul(Matrix A,Matrix b,double *x);
|
|
|
int MinMul(double **A,double *b,int m,int n,double *x);
|
|
|
|
|
|
//控制台显示矩阵mt
|
|
|
void ConsoleShowMatrix(Matrix *mt);
|
|
|
|
|
|
//最小二乘法 x,y为x,y数组,num 为其个数,result储存结果
|
|
|
void LinearFitting(double* x, double* y, int num, double* result); //分别是x,y数组和个数
|
|
|
};
|
|
|
|
|
|
}//namespace
|
|
|
|
|
|
#endif // LinearFitting_h__
|