?? matrix.h
字號(hào):
//////////////////////////////////////////////////////////////////////
// Matrix.h
//
// 操作矩陣的類 CMatrix 的聲明接口
//
// 周長發(fā)編制, 2002/8
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_MATRIX_H__ACEC32EA_5254_4C23_A8BD_12F9220EF43A__INCLUDED_)
#define AFX_MATRIX_H__ACEC32EA_5254_4C23_A8BD_12F9220EF43A__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <math.h>
#if !defined(_BITSET_)
# include <bitset>
#endif // !defined(_BITSET_)
//////////////////////////////////////////////////////////////////////////////////////
//
//(-- class CTokenizer
//
class CTokenizer
{
public:
CTokenizer(const CString& cs, const CString& csDelim) : m_cs(cs), m_nCurPos(0)
{
SetDelimiters(csDelim);
}
void SetDelimiters(const CString& csDelim)
{
for(int i = 0; i < csDelim.GetLength(); ++i)
m_sDelimiter.set(static_cast<BYTE>(csDelim[i]));
}
BOOL Next(CString& cs)
{
cs.Empty();
while(m_nCurPos < m_cs.GetLength() && m_sDelimiter[static_cast<BYTE>(m_cs[m_nCurPos])])
++m_nCurPos;
if(m_nCurPos >= m_cs.GetLength())
return FALSE;
int nStartPos = m_nCurPos;
while(m_nCurPos < m_cs.GetLength() && !m_sDelimiter[static_cast<BYTE>(m_cs[m_nCurPos])])
++m_nCurPos;
cs = m_cs.Mid(nStartPos, m_nCurPos - nStartPos);
return TRUE;
}
CString Tail() const
{
int nCurPos = m_nCurPos;
while(nCurPos < m_cs.GetLength() && m_sDelimiter[static_cast<BYTE>(m_cs[nCurPos])])
++nCurPos;
CString csResult;
if(nCurPos < m_cs.GetLength())
csResult = m_cs.Mid(nCurPos);
return csResult;
}
private:
CString m_cs;
std::bitset<256> m_sDelimiter;
int m_nCurPos;
};
//
//--) // class CTokenizer
//
//////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
//
//(-- class CMatrix
//
class CMatrix
{
//
// 公有接口函數(shù)
//
public:
//
// 構(gòu)造與析構(gòu)
//
CMatrix(); // 基礎(chǔ)構(gòu)造函數(shù)
CMatrix(int nRows, int nCols); // 指定行列構(gòu)造函數(shù)
CMatrix(int nRows, int nCols, double value[]); // 指定數(shù)據(jù)構(gòu)造函數(shù)
CMatrix(int nSize); // 方陣構(gòu)造函數(shù)
CMatrix(int nSize, double value[]); // 指定數(shù)據(jù)方陣構(gòu)造函數(shù)
CMatrix(const CMatrix& other); // 拷貝構(gòu)造函數(shù)
BOOL Init(int nRows, int nCols); // 初始化矩陣
BOOL MakeUnitMatrix(int nSize); // 將方陣初始化為單位矩陣
virtual ~CMatrix(); // 析構(gòu)函數(shù)
//
// 輸入與顯示
//
// 將字符串轉(zhuǎn)換為矩陣數(shù)據(jù)
BOOL FromString(CString s, const CString& sDelim = " ", BOOL bLineBreak = TRUE);
// 將矩陣轉(zhuǎn)換為字符串
CString ToString(const CString& sDelim = " ", BOOL bLineBreak = TRUE) const;
// 將矩陣的指定行轉(zhuǎn)換為字符串
CString RowToString(int nRow, const CString& sDelim = " ") const;
// 將矩陣的指定列轉(zhuǎn)換為字符串
CString ColToString(int nCol, const CString& sDelim = " ") const;
//
// 元素與值操作
//
BOOL SetElement(int nRow, int nCol, double value); // 設(shè)置指定元素的值
double GetElement(int nRow, int nCol) const; // 獲取指定元素的值
void SetData(double value[]); // 設(shè)置矩陣的值
int GetNumColumns() const; // 獲取矩陣的列數(shù)
int GetNumRows() const; // 獲取矩陣的行數(shù)
int GetRowVector(int nRow, double* pVector) const; // 獲取矩陣的指定行矩陣
int GetColVector(int nCol, double* pVector) const; // 獲取矩陣的指定列矩陣
double* GetData() const; // 獲取矩陣的值
//
// 數(shù)學(xué)操作
//
CMatrix& operator=(const CMatrix& other);
BOOL operator==(const CMatrix& other) const;
BOOL operator!=(const CMatrix& other) const;
CMatrix operator+(const CMatrix& other) const;
CMatrix operator-(const CMatrix& other) const;
CMatrix operator*(double value) const;
CMatrix operator*(const CMatrix& other) const;
// 復(fù)矩陣乘法
BOOL CMul(const CMatrix& AR, const CMatrix& AI, const CMatrix& BR, const CMatrix& BI, CMatrix& CR, CMatrix& CI) const;
// 矩陣的轉(zhuǎn)置
CMatrix Transpose() const;
//
// 算法
//
// 實(shí)矩陣求逆的全選主元高斯-約當(dāng)法
BOOL InvertGaussJordan();
// 復(fù)矩陣求逆的全選主元高斯-約當(dāng)法
BOOL InvertGaussJordan(CMatrix& mtxImag);
// 對稱正定矩陣的求逆
BOOL InvertSsgj();
// 托伯利茲矩陣求逆的埃蘭特方法
BOOL InvertTrench();
// 求行列式值的全選主元高斯消去法
double DetGauss();
// 求矩陣秩的全選主元高斯消去法
int RankGauss();
// 對稱正定矩陣的喬里斯基分解與行列式的求值
BOOL DetCholesky(double* dblDet);
// 矩陣的三角分解
BOOL SplitLU(CMatrix& mtxL, CMatrix& mtxU);
// 一般實(shí)矩陣的QR分解
BOOL SplitQR(CMatrix& mtxQ);
// 一般實(shí)矩陣的奇異值分解
BOOL SplitUV(CMatrix& mtxU, CMatrix& mtxV, double eps = 0.000001);
// 求廣義逆的奇異值分解法
BOOL GInvertUV(CMatrix& mtxAP, CMatrix& mtxU, CMatrix& mtxV, double eps = 0.000001);
// 約化對稱矩陣為對稱三對角陣的豪斯荷爾德變換法
BOOL MakeSymTri(CMatrix& mtxQ, CMatrix& mtxT, double dblB[], double dblC[]);
// 實(shí)對稱三對角陣的全部特征值與特征向量的計(jì)算
BOOL SymTriEigenv(double dblB[], double dblC[], CMatrix& mtxQ, int nMaxIt = 60, double eps = 0.000001);
// 約化一般實(shí)矩陣為赫申伯格矩陣的初等相似變換法
void MakeHberg();
// 求赫申伯格矩陣全部特征值的QR方法
BOOL HBergEigenv(double dblU[], double dblV[], int nMaxIt = 60, double eps = 0.000001);
// 求實(shí)對稱矩陣特征值與特征向量的雅可比法
BOOL JacobiEigenv(double dblEigenValue[], CMatrix& mtxEigenVector, int nMaxIt = 60, double eps = 0.000001);
// 求實(shí)對稱矩陣特征值與特征向量的雅可比過關(guān)法
BOOL JacobiEigenv2(double dblEigenValue[], CMatrix& mtxEigenVector, double eps = 0.000001);
//
// 保護(hù)性數(shù)據(jù)成員
//
protected:
int m_nNumColumns; // 矩陣列數(shù)
int m_nNumRows; // 矩陣行數(shù)
double* m_pData; // 矩陣數(shù)據(jù)緩沖區(qū)
//
// 內(nèi)部函數(shù)
//
private:
void ppp(double a[], double e[], double s[], double v[], int m, int n);
void sss(double fg[2], double cs[2]);
};
//
//--) // class CMatrix
//
//////////////////////////////////////////////////////////////////////////////////////
#endif // !defined(AFX_MATRIX_H__ACEC32EA_5254_4C23_A8BD_12F9220EF43A__INCLUDED_)
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -