📄 matrix.h
字号:
//---------------------------------------------------------------------------
// 16.jul.2002 13:24 GMT
// Matrix module implementation of TVector and TMatrix classes for
// transparent vector and matrix operation.
// Find more information at:
// http://www.fuzzy.ru/source/matrix.phtml
// Contact authors:
// Boris Izyumov bobbisson@fuzzy.ru
// Olivier Riff olivier.riff@inrialpes.fr
//
//---------------------------------------------------------------------------
#ifndef _Matrix_UNIT_
#define _Matrix_UNIT_
#include <math.h>
#include <string.h>
#include <stdio.h>
//---------------------------------------------------------------------------
class TMatrix;
class TVector
{
friend class TMatrix;
public:
TVector ();
TVector (const TVector& m);
TVector (int rows, double* val = NULL);
virtual ~TVector ();
protected:
int m_nBufCount;
char* m_pcBuf;
int m_nRows;
bool m_bVertical;
double* m_dVals;
public:
operator double* () const { return m_dVals; };
TVector operator- (); // -(*this)
TVector& operator= (const TVector& m);
TVector& operator= (const double* v);
TMatrix operator* (TMatrix& m); // (*this)*m
TVector operator+ (TVector& m); // (*this) + m
TVector operator- (TVector& m); // (*this) - m
void SetSize (int i);
void Reset ();
void Transpose ();
void MakeIdentity ();
void MakeZero ();
bool Multiply (TMatrix* R, TMatrix* Dest);
bool Add (TVector* R, TVector* Dest);
bool Vertical ();
int Rows ();
void GrowBy(int inc);
void Add(double val);
void Insert(int idx, double val);
void Delete(int idx);
void Swap(int idx1, int idx2);
double& Val (int i);
double& operator[] (int idx);
double Max();
double Min();
const char* Packed();
};
class TMatrix
{
friend class TVector;
public:
TMatrix ();
TMatrix (const TMatrix& m);
TMatrix (int rows);
TMatrix (int rows, int cols);
~TMatrix ();
protected:
int m_nRows, m_nCols;
double** m_dVals;
double Minor (char* rowsused, char* colsused);
bool LU_decomp(TMatrix& m,int* indx,double& d);
void LU_backsub(TMatrix& m,int* indx,double* b);
void GetMem();
void FreeMem();
public:
TMatrix& operator= (const TMatrix& m);
TMatrix operator* (TMatrix& m); // (*this)*m
TMatrix operator* (TVector& v); // (*this)*v
TMatrix operator+ (TMatrix& m); // (*this) + m
void SetSize (int i, int j);
void Reset ();
void Transpose ();
void MakeIdentity ();
void MakeZero ();
bool Invert();
bool Multiply (TMatrix* R, TMatrix* Dest);
bool Multiply (TVector* R, TMatrix* Dest);
bool Add (TMatrix* R, TMatrix* Dest);
bool Square ();
int Rows ();
int Cols ();
double Determinant();
double AlgAdd(int row, int col);
double& Val(int i, int j);
int AddLine(TVector& vctr);
void GrowBy(int rows, int cols);
double* operator[] (int idx);
};
//---------------------------------------------------------------------------
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -