You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
kev/Drawer/SSBase/PlatBase/LinearFitting.h

59 lines
1.4 KiB
C++

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#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__