📄 matrix.h
字号:
// Matrix.h: interface for the CMatrix class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_MATRIX_H__F5A742DF_E053_4D49_AF7A_0895F11574B5__INCLUDED_)
#define AFX_MATRIX_H__F5A742DF_E053_4D49_AF7A_0895F11574B5__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class CMatrix
{
class base_mat
{
public:
double **Val;
size_t Row, Col, RowSiz, ColSiz;
int Refcnt;
base_mat (size_t row, size_t col, double** v)
{
Row = row; RowSiz = row;
Col = col; ColSiz = col;
Refcnt = 1; //被引用的次数
Val = new double* [row];
size_t rowlen = col * sizeof(double);
for (size_t i=0; i<row; i++)
{
Val[i] = new double [col];
if (v) memcpy( Val[i], v[i], rowlen);
}
}
~base_mat ()
{
for (size_t i=0; i < RowSiz; i++)
delete [] Val[i];
delete [] Val;
}
};
private:
base_mat *_m;
private:
void clone ();
void realloc (size_t row, size_t col);
int pivot (size_t row);
public:
CMatrix(const CMatrix& m);
CMatrix(size_t row=4, size_t col=4);
virtual ~CMatrix();
// Assignment operators
CMatrix& operator = (const CMatrix& m) ;
// Value extraction method
size_t RowNo () const { return _m->Row; }
size_t ColNo () const { return _m->Col; }
// Subscript operator 下标操作
double& operator () (size_t row, size_t col) ;
double operator () (size_t row, size_t col) const ;
// Unary operators 一元操作
CMatrix operator + () {return *this; }
CMatrix operator - () {return *this; };
// Combined assignment - calculation operators
//结合操作
CMatrix& operator += (const CMatrix& m); //两个矩阵相加
CMatrix& operator -= (const CMatrix& m); //两个矩阵相减
CMatrix& operator *= (const CMatrix& m); //两个矩阵相乘
CMatrix& operator *= (const double& c); //乘上一个常数
CMatrix& operator /= (const double& c); //除以一个常数
CMatrix& operator ^= (const size_t& pow); //矩阵的乘方
bool operator == (const CMatrix &m) const;
bool operator != (const CMatrix &m) const;
CMatrix operator ! ();
CMatrix operator + (CMatrix &m);
CMatrix operator - (CMatrix &m);
CMatrix operator ~ ();
// Miscellaneous -methods
void Null (const size_t& row, const size_t& col) ;
void Null ();
void Unit (const size_t& row) ;
void Unit () ;
void Zero ();
void SetSize (size_t row, size_t col);
// Utility methods
CMatrix Solve (const CMatrix& v) const ;
CMatrix Adj () ;
CMatrix Reverse () ;
CMatrix Inversion ();
double Det () const;
double Norm ();
double Cofact (size_t row, size_t col);
double Cond () ;
// Type of matrices
bool IsSquare () { return (_m->Row == _m->Col); } // 判断是方阵吗
bool IsSingular () ; //是奇异阵
bool IsDiagonal () ; //对角阵
bool IsScalar () ;
bool IsUnit () ;
bool IsNull () ;
bool IsSymmetric () ;
bool IsSkewSymmetric ();
bool IsUpperTriangular () ;
bool IsLowerTriangular () ;
static void USVtDecompose_ppp(CMatrix &S, double *e, double *s, CMatrix &V, int m, int n);
static void USVtDecompose_sss(double *fg, double *cs);
BOOL USVtDecompose(const CMatrix &A, CMatrix &U, CMatrix &S, CMatrix &V, double dbEps, int nIt=60);
};
#endif // !defined(AFX_MATRIX_H__F5A742DF_E053_4D49_AF7A_0895F11574B5__INCLUDED_)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -