📄 matrix.h
字号:
#ifndef MATRIX_H_
#define MATRIX_H_
class Matrix
{
private:
float *array;//存放矩阵元素的指针数组
int nrow,ncol;//矩阵的行列数
public:
//默认构造函数
Matrix():nrow(0),ncol(0),array(0){}
//以给定行列数和元素数组构造矩阵
Matrix(int m,int n,float* a);
//构造维数为n的单位矩阵的构造函数
Matrix(size_t n);
//复制构造函数
Matrix(const Matrix&);
//析构函数,释放矩阵元素指针数组的内存空间
~Matrix();
//矩阵的初始化函数
void CreateMatrix();
//矩阵下标引用运算符,暂时没有使用
float* operator [] ( const size_t i );
/*以下为重载的矩阵的各个赋值运算符,计算结果该表本矩阵对象*/
Matrix& operator = ( const Matrix& );
Matrix& operator+= ( const Matrix& );
Matrix& operator-= ( const Matrix& );
Matrix& operator*= ( const Matrix& );
Matrix& operator*= ( const float );
//矩阵行列数的提取函数
size_t getNRow() const;
size_t getNCol() const;
//计算矩阵的对角线元素之和
float trace() const;
//输出矩阵
void print() const;
};
/*以下为重载的矩阵的各个二元运算符*/
Matrix operator+ (const Matrix&,const Matrix&);
Matrix operator- (const Matrix&,const Matrix&);
Matrix operator* (const Matrix&,const Matrix&);
Matrix operator* (const Matrix&,const float);
//求矩阵的n次幂
Matrix pow(const Matrix&, const size_t n);
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -