斯坦福Energy211/CME211课《c++编程——地球科学科学家和工程师》的课件

源代码在线查看: sparsemat_main.cpp

软件大小: 228 K
上传用户: liu4052032
关键词: 211 Energy CME 斯坦福
下载地址: 免注册下载 普通下载 VIP

相关代码

				// ENERGY211/CME211				//				// main.cpp - Main application file that tests functions from				// the SparseMatrix class				//								#include 				#include 								#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 						double x = A(2,2);						cout 						// By trying to access the (2,2) element,						// entries in the map are created even though						// the element is zero						cout 						// So this will report nnz = 2 even though						// it should be 1						cout 						// This will correct the problem						A.Squeeze();						cout 						cout 						// Confirm that the matrix hasn't changed						cout 						cout 					}					catch(runtime_error e)					{						cout 					}									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 						cout 											SparseMatrix B = A * A;						cout 						cout 						SparseMatrix T = B.Transpose();						cout 						cout 						SparseMatrix C = B + T;						cout 						cout 					}					catch(runtime_error e)					{						cout 					}									return 0;				}							

相关资源