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

📄 sparsemat_main.cpp

📁 斯坦福Energy211/CME211课《c++编程——地球科学科学家和工程师》的课件
💻 CPP
字号:
// ENERGY211/CME211//// main.cpp - Main application file that tests functions from// the SparseMatrix class//#include <iostream>#include <cmath>#include "sparsemat.h"using namespace std;int main() {		try	{		// This creates a 3x3 zero matrix		SparseMatrix A(3,3);			A(1,1) = 1.0;		cout << "(2,2) element:" << endl;		double x = A(2,2);		cout << "x = " << x << endl;		// By trying to access the (2,2) element,		// entries in the map are created even though		// the element is zero		cout << "A(2,2) = " << A(2,2) << endl;		// So this will report nnz = 2 even though		// it should be 1		cout << "nnz = " << A.nnz() << endl;		// This will correct the problem		A.Squeeze();		cout << "nnz = " << A.nnz() << endl;		cout << endl;		// Confirm that the matrix hasn't changed		cout << "A:" << endl;		cout << A;	}	catch(runtime_error e)	{		cout << e.what() << endl;	}	try	{		// Test basic matrix operations		SparseMatrix A;		A.Identity( 4 );		A(0,1) = 2.0;		A(1,2) = 3.0;		A(2,3) = 4.0;		cout << "A = \n";		cout << A;			SparseMatrix B = A * A;		cout << "B = \n";		cout << B;		SparseMatrix T = B.Transpose();		cout << "B^T = \n";		cout << T;		SparseMatrix C = B + T;		cout << "C = \n";		cout << C;	}	catch(runtime_error e)	{		cout << e.what() << endl;	}	return 0;}

⌨️ 快捷键说明

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