linsys.h
来自「斯坦福Energy211/CME211课《c++编程——地球科学科学家和工程师》」· C头文件 代码 · 共 58 行
H
58 行
#ifndef CLASS_LINSYS#define CLASS_LINSYS#include "vector.h"class LinearSystem {public: enum IterMethod { MethodJacobi, MethodGaussSeidel, MethodSOR } ; enum ErrorCode { ERROR_MATRIX_SINGULAR, ERROR_MATRIX_NOT_SQUARE, ERROR_SIZE_MISMATCH } ; LinearSystem( const Matrix& A ) { m_A = A; m_Factored = false; } LinearSystem( const LinearSystem& S ); ~LinearSystem() { } ColVector DirectSolve( const ColVector& b ); ColVector IterativeSolve( const ColVector& b, IterMethod m, double w = 1.0 ); void SetMaxIter( int n ) { m_maxiter = n; } void SetTol( double tol ) { m_tol = tol; }private: Matrix m_A; Matrix m_L; Matrix m_U; bool m_Factored; int m_maxiter; double m_tol; void GaussElim(); ColVector ForwardSub( const Matrix& L, const ColVector& b ); ColVector BackSub( const Matrix& U, const ColVector& y ); ColVector StationarySolve( const Matrix& M, const Matrix& N, const ColVector& b ); ColVector Jacobi( const ColVector& b ); ColVector GaussSeidel( const ColVector& b ); ColVector SOR( const ColVector& b, double w ); // Leave these alone! They are used for error reporting static void ReportError( ErrorCode errorcode ); static char *ErrorMessages[];} ;#endif // CLASS_LINSYS
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?