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.
nmWATI/Include/iAlg/iAlgMath/zxAlgMatrix.h

126 lines
4.0 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
#include "Defines.h"
#include "iAlgMath_global.h"
class zxAlgMatrixCol;
// 矩阵
// 注:本矩阵类有些特殊,包括两个部分,由于时间限制,未做统一整合,后续再进行处理件
// 1.处理解释中用的矩阵操作,以本类为载体,类缓存模式,并且引用 zxAlgMatrixCol对应 zxAlgMatrix.cpp 文件
// 2.拟合回归算法中用到的矩阵相关大都是static函数以VecDouble为载体对应 zxAlgMatrixEx.cpp 文件
class I_ALGMATH_EXPORT zxAlgMatrix
{
public:
zxAlgMatrix();
zxAlgMatrix(int rows, int cols, double val = 0.0);
virtual ~zxAlgMatrix();
/////////////////////////////////////////////////////////
// 1.处理解释中用的矩阵操作,以本类为载体,类缓存模式,并且引用 zxAlgMatrixCol对应 zxAlgMatrix.cpp 文件
public:
static zxAlgMatrix Zero(int nRow, int nCol); //初始化
int rows() const; //获取行数
int cols() const; //获取列数
void set(int row, int col, double value); //设置元素
double get(int row, int col) const; //获取元素
double operator()(int row, int col = 0) const;//访问元素
double& operator()(int row, int col = 0);
zxAlgMatrix operator= (zxAlgMatrix other); //赋值函数
zxAlgMatrix operator+ (zxAlgMatrix other); //矩阵相加
zxAlgMatrix operator- (zxAlgMatrix other); //矩阵相减
zxAlgMatrix operator* (zxAlgMatrix other); //矩阵相乘
zxAlgMatrix operator/ (zxAlgMatrix& other);//矩阵相除
zxAlgMatrixCol operator* (const zxAlgMatrixCol& vec); //矩阵与行列式相乘
zxAlgMatrix operator-() ; //矩阵求负
zxAlgMatrix transpose(); //矩阵转置
zxAlgMatrix inverse(); //矩阵求逆
double determinant(); //行列式
protected:
// 数据体
VVecDouble m_vvecData;
/////////////////////////////////////////////////////////
// 2.拟合回归算法中用到的矩阵相关大都是static函数以VecDouble为载体对应 zxAlgMatrixEx.cpp 文件
public:
// 求矩阵行列式。
static double matrixDet(VecDouble vMatrix, int nRow);
// 矩阵乘法,矩阵*矩阵
static bool plusMatrix(VecDouble& vResult, int &nResultRow, \
VecDouble vLeft, int nLetfRow, \
VecDouble vRight, int nRightRow);
// 矩阵乘法,矩阵*数值
static bool plusMatrix(VecDouble& vResult, double dFactor);
// 将矩阵由一维形式转为二维形式
static bool vec2VecRow2D(VecDouble vec, int nRow, \
VVecDouble& vec2D);
// 行*列
static bool plusRow(double& dResult,VecDouble vRow, \
VecDouble vCol);
// 求矩阵伴随阵
static bool adjoinMatrix(VecDouble& vMatrix, int nRow);
// 求矩阵某一个元素的代数余子式
static bool cofactor(double &dResult, VecDouble vMatrix, \
int nRow, int i, int j);
// 矩阵求逆
static bool inverseMatrix(VecDouble& vMatrix, int nRow);
// 矩阵转置
static bool transposeMatrix(VecDouble& vMatrix, int& nRow);
// 矩阵加法
static bool AddMatrix(VecDouble& vResult, int &nResultRow, \
VecDouble vLeft, int nLetfRow, \
VecDouble vRight, int nRightRow);
// 矩阵减法
static bool subMatrix(VecDouble& vResult, int& nResultRow, \
VecDouble vLeft, int nLetfRow, \
VecDouble vRight, int nRightRow);
};
// 列向量
class I_ALGMATH_EXPORT zxAlgMatrixCol
{
public:
zxAlgMatrixCol();
zxAlgMatrixCol(int nRow, int nCol = 1, double val = 0.0);
static zxAlgMatrixCol Zero(int nRow, int nCol = 1);
int rows();
double operator()(int i, int j = 0) const;
double& operator()(int i, int j = 0);
double& operator[](int i);
const double& operator[](int i) const;
// 赋值函数
zxAlgMatrixCol operator=( zxAlgMatrixCol other);
protected:
// 数据体
VecDouble m_vecData;
};