⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 realmatrix.h

📁 这是一个实数矩阵计算的源代码
💻 H
字号:
// ComplexMatrix.h: interface for the CRealMatrix class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(__REALMATRIX_H__)
#define __REALMATRIX_H__

class CRealMatrix 
{
protected:
	struct CNode	//链表的节点信息
	{
		CNode *pRight;	//向同一行的下一节点
		CNode *pDown;	//相同列的下一节点
		CNode *pPrev;	//向上一头节点 
		CNode *pNext;	//向下一头节点

		int nRow;		//行值
		int nCol;		//列值
		double data;	//数据
	};

	//表的节点操作指针

	CNode *pHead;
	CNode *pTail;
	CNode *pCurrent;
	CNode *pData;

private:
	void Copy(const CRealMatrix &src);	//矩阵复制
	void DeleteNode(int row,int col);	//删除节点
	void DeleteNode(int row,int col,CNode* pTemp);
	void AddNode(int row,int col,double value,CNode* pTemp);
	CRealMatrix PoseBlock(int& number,int* Ip,CRealMatrix& MatrixP);//矩阵分块

	//{节点指针的移动

		void GoToHead();
		void GoToTail();
		void GoNext();
		void GoPrev();
		void GoRight();
		void GoDown();

	//}

//special operation
private:
	BOOL Unit();
	BOOL Remove(int row1,int row2);
private:
	//用于三角分解的内部函数
	double GetDiaEle(INT row,INT col);
	double GetDownEle(INT row,INT col);
	double GetUpEle(INT row,INT col);

	double GetDiaEle(INT n,CNode* pTemp);
	double GetUpEle(INT k,CNode* pCol);

	double GetDiaEle0(INT row,INT col);
	double GetDownEle0(INT row,INT col);
	double GetUpEle0(INT row,INT col);

	double GetDia0(INT row,INT col);
	double GetDia1(INT row,INT col);

	double GetDown(INT row,INT col);
	double GetDia(INT row,INT col);
	double GetUp(INT row,INT col);
private:
	//解方程
	void BackPush0(CRealMatrix& src);//消去,用于LDU
	BOOL Standardize0(CRealMatrix& src); //规格化
	void FrontPush0(CRealMatrix& src);//回代,用于LDU

	void BackPush1(CRealMatrix& src);//消去,用于DL
	void FrontPush1(CRealMatrix& src);//回代,用于LD

	void BackPush(CRealMatrix& src);//消去,用于LL
	void FrontPush(CRealMatrix& src);//回代,用于LL

	void BackStep2(INT col,CRealMatrix& src);//消去,用于LL
	void FrontStep2(INT col,CRealMatrix& src);//回代,用于LL

	void BackStep1(INT col,CRealMatrix& src);//消去,用于DL
	void FrontStep1(INT col,CRealMatrix& src);//回代,用于LD

	void BackStep(INT col,CRealMatrix& src);
	BOOL Standard(INT col,CRealMatrix& src);
	void FrontStep(INT col,CRealMatrix& src);


public:
	CRealMatrix  Discerption();//对原存储LD/DL的矩阵进行分离,
								//返回对角阵的逆 
public:
	CRealMatrix Inverse();	//一般矩阵求逆
	CRealMatrix Transpose();//矩阵转置

	CRealMatrix CreateG0(CRealMatrix &srcR,CRealMatrix &srcHR);
						//形成信息阵G=[H(T)RH],仅保留上三角部分,
						//并返回srcHR=[H(T)R]
						//输入矩阵为雅可比矩阵H,对角阵R
	CRealMatrix CreateG1(CRealMatrix &srcR,CRealMatrix &srcHR);
						//形成信息阵G=[H(T)RH],仅保留下三角部分,
						//并返回srcHR=[H(T)R]
	void Normalize0(); //对进存储了上、下三角元素的对称阵进行标准化
	void Normalize1(); //对对称阵进行上三角化
	void Normalize2(); //对对称阵进行下三角化

	BOOL Inverse0();	//矩阵求逆(对角占优)
	CRealMatrix Inverse1();	//对称正定矩阵求逆

	BOOL Decompose0();//普通矩阵LDU分解,分解后的L、D、U
	                  //存在原矩阵中,返回0——矩阵为空或非方阵;
					  //1——矩阵奇异
					  //2——矩阵分解
	BOOL Decompose1();//普通矩阵LDL(T)分解,分解后的L、D存在上三角(原对称阵保留上三角)
	BOOL Decompose2();//普通矩阵LL(T)分解,分解后的L、存在上三角(原对称阵保留上三角)

	BOOL DecomposeEx1();//普通矩阵LDL(T)分解,分解后的L、D存在下三角(原对称阵保留下三角)
	BOOL DecomposeEx2();//普通矩阵LL(T)分解,分解后的L、存在下三角(原对称阵保留下三角)

	BOOL GetResult0(CRealMatrix& srcB);//求解,输入信息:A阵LDU的组合阵
											//srcB为m*n阶的矩阵	
	BOOL GetResult1(CRealMatrix& srcB);//求解,输入信息:A阵为分解后的
											//LD组合阵(存与上三角)
											//srcB为m*n阶的矩阵	
	BOOL GetResult2(CRealMatrix& srcB);//求解,输入信息:A阵为分解后的
											 //L阵(存与上三角)
											//srcB为m*n阶的矩阵	
	BOOL GetResultEx1(CRealMatrix& srcB);//求解,输入信息:A阵为分解后的
											//LD组合阵(存与下三角)
											//srcB为m*n阶的矩阵	
	BOOL GetResultEx2(CRealMatrix& srcB);//求解,输入信息:A阵为分解后的
											 //L阵(存与下三角)
											//srcB为m*n阶的矩阵
	BOOL GetResult3(CRealMatrix& srcB);//求解,输入信息:A阵为
										//上三角,srcB为m*n阶的矩阵
	BOOL GetResultEx3(CRealMatrix& srcB);//求解,输入信息:A阵为
										//下三角,srcB为m*n阶的矩阵
public:
	bool IsEmpty();			//矩阵为空判断
	void Empty();			//矩阵清空

	int RowCount();			//矩阵行数

	CRealMatrix GetRow(int row);	//取某一行元素
	CRealMatrix GetCol(int col);	//取某一列元素

	void DeleteRow(int row);	//删除某行元素
	void DeleteCol(int col);	//删除某列元素

	CRealMatrix RowExchange(int row1,int row2);//交换两行
	CRealMatrix ColExchange(int col1,int col2);//交换两列

	void Input(char filename[21]);//矩阵输入
	void Output(char filename[21]);//矩阵输出

	double Get_det();//求矩阵的行列式
	int rank();//矩阵求秩

	CRealMatrix AddRow(int row,CRealMatrix& src);//增加一行
	CRealMatrix AddCol(int col,CRealMatrix& src);//增加一列

	//{矩阵构造函数
		CRealMatrix();
		CRealMatrix(int row,int col);
		CRealMatrix(const CRealMatrix &src);
	//}
		virtual ~CRealMatrix();			//析构函数

	void Create(int row,int col);
	void SetSize(int row,int col);	//保证矩阵能扩展
	void Store(int row,int col,const double newElement);//矩阵元素赋值
	void Add(int row,int col,const double newElement);
	void GetData(int row,int col,double &data);			//获取矩阵元素值


	//{矩阵的加、减、乘,输入,输出操作
		CRealMatrix operator +(const CRealMatrix &src);
		CRealMatrix operator -(const CRealMatrix &src);
		CRealMatrix operator *(const CRealMatrix &src);
		CRealMatrix operator -();			//矩阵求负
		CRealMatrix operator *(const double value);
		void operator =(const CRealMatrix &src);
		void operator +=(const CRealMatrix &src);
		void operator -=(const CRealMatrix &src);
		void operator *=(const CRealMatrix &src);
		void operator *=(const double value);

	//}
};

#endif // !defined(__REALMATRIX_H__)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -