?? matrix.h
字號:
#ifndef _MATRIX_H
#define _MATRIX_H
class Matrix
{
private:
int row; // 矩陣的行數(shù)
int col; // 矩陣的列數(shù)
int n; // 矩陣元素個數(shù)
double* mtx; // 動態(tài)分配用來存放數(shù)組的空間
public:
Matrix(int row=1, int col=1); // 帶默認參數(shù)的構(gòu)造函數(shù)
Matrix(int row, int col, double mtx[]); // 用數(shù)組創(chuàng)建一個矩陣
Matrix(const Matrix &obj); // copy構(gòu)造函數(shù)
~Matrix() { delete[] this->mtx; }
void print()const; // 格式化輸出矩陣
int getRow()const { return this->row; } // 訪問矩陣行數(shù)
int getCol()const { return this->col; } // 訪問矩陣列數(shù)
int getN()const { return this->n; } // 訪問矩陣元素個數(shù)
double* getMtx()const { return this->mtx; } // 獲取該矩陣的數(shù)組
// 用下標訪問矩陣元素
double get(const int i, const int j)const;
// 用下標修改矩陣元素值
void set(const int i, const int j, const double e);
// 重載了一些常用操作符,包括 +,-,x,=,負號,正號,
// A = B
Matrix &operator= (const Matrix &obj);
// +A
Matrix operator+ ()const { return *this; }
// -A
Matrix operator- ()const;
// A + B
friend Matrix operator+ (const Matrix &A, const Matrix &B);
// A - B
friend Matrix operator- (const Matrix &A, const Matrix &B);
// A * B 兩矩陣相乘
friend Matrix operator* (const Matrix &A, const Matrix &B);
// a * B 實數(shù)與矩陣相乘
friend Matrix operator* (const double &a, const Matrix &B);
// A 的轉(zhuǎn)置
friend Matrix trv(const Matrix &A);
// A 的行列式值,采用列主元消去法
// 求行列式須將矩陣化為三角陣,此處為了防止修改原矩陣,采用傳值調(diào)用
friend double det(Matrix A);
// A 的逆矩陣,采用高斯-若當列主元消去法
friend Matrix inv(Matrix A);
};
#endif
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -