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

📄 main.cpp

📁 原创C++的matrix类,有许多运算符重载,很简单,但是好用,好看
💻 CPP
字号:
#include "matrix.h"
#include <fstream>

void main()
{
	CMatrix A=rand(5,4);
	cout<<"matrix  A="<<endl<<A;
	CMatrix B=rand(4,6);
	cout<<"matrix  B="<<endl<<B;
	CMatrix C=rand(6,3);
	cout<<"matrix  C="<<endl<<C;
	cout<<" the first algorithm calculating the transpose of ABC:   "<<endl<<~(A*B*C);	
	cout<<" the second algorithm calculating the transpose of ABC:   "<<endl<<~C*~B*~A;
	cout<<" test two algorithms  ~(A*B*C)-~C*~B*~A :    "<<endl<<~(A*B*C)-~C*~B*~A;
	if(~(A*B*C)==~C*~B*~A) 
	{
		cout<<"~(A*B*C)  is equal to  ~C*~B*~A"<<endl;
	}
	else
	{
		cout<<"~(A*B*C)  is not equal to  ~C*~B*~A"<<endl;
	}
	cout<<endl;


	const n=4;
	CMatrix a=rand(n,n)+n*identity(n);
	cout<<"matrix a"<<endl<<a;
	CMatrix b=rand(n,n)+n*identity(n);
	cout<<"matrix b"<<endl<<b;
	CMatrix c=rand(n,n)+n*identity(n);
	cout<<"matrix c"<<endl<<c;
	CMatrix d=rand(n,n)+n*identity(n);
	cout<<"matrix d"<<endl<<d;
	cout<<" the first algorithm calculating the inverse matrix of abcd:  "<<endl<<!(a*b*c*d);
	cout<<" the second algorithm calculating the inverse matrix of abcd:  "<<endl<<!d*!c*!b*!a;
	cout<<" test tow algorithms !(a*b*c*d)-!d*!c*!b*!a  :  "<<endl<<!(a*b*c*d)-!d*!c*!b*!a;
	if(!(a*b*c*d)==!d*!c*!b*!a) 
	{
		cout<<"!(a*b*c*d) is equal to !d*!c*!b*!a"<<endl;
	}
	else
	{
		cout<<"!(a*b*c*d) is not equal to !d*!c*!b*!a"<<endl;
	}
	cout<<endl;

	cout<<" the first algorithm calculating the determinant matrix of abcd:  "\
		<<endl<<determinant(a*b*c*d)<<endl;

	cout<<" the second algorithm calculating the determinant matrix of abcd:  "\
		<<endl<<determinant(a)*determinant(b)*determinant(c)*determinant(d)<<endl;
	

	CMatrix H=a*~a;
	cout<<"matrix H"<<endl<<H;
	CMatrix E;
	CMatrix V=symmeig(H,E);
	cout<<"the eigenvalue matrix of matrix H is E="<<endl<<E;
	cout<<"the eigenvector matrix of matrix H is V="<<endl<<V;
	cout<<"test eigenequation H*V-V*E="<<endl<<H*V-V*E;


	char filename[100];
	cout<<"please input the file name of linear simultaneous equations: ";
	cin>>filename;
	ifstream fin(filename);
	fin>>A;
	fin>>B;
	fin.close();

	CMatrix x=linequ2(A,B);
	cout<<"please input the file name you will write the solution to: ";
	cin>>filename;
	ofstream fout(filename);
	fout<<x;
	fout.close();

	cout<<"test the solution: A*x-B="<<endl<<A*x-B;
}

⌨️ 快捷键说明

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