// =======================< SYMM.HPP >======================== // * Class MatrixSymm * // * Description: Chapter 12 * // * Scientific C++ Building Numerical Libraries * // * the Object-Oriented Way * // * by G. Buzzi-Ferraris * // * Addison-Wesley (1993) * // =========================================================== // ****** Constructions for MatrixSymm: * // * MatrixSymm S; // default * // * MatrixSymm S = symm; // copy-initializer * // * MatrixSymm S(3,3); // sized and placed at 0 * // * MatrixSymm S(3,3, * // * 1., * // * 2.,3., * // * 4.,5.,6.);// sizes and initialises * // * float x[]= * // * { * // * 1., * // * 2.,3., * // * 4.,5.,6. * // * }; * // * MatrixSymm S(3,3,x); // from array * // * MatrixSymm S("MAT.DAT"); // Formatted File * // * MatrixSymm S('*',MAT.BIN"); // Binary File * // *********************************************************** // ***** Access functions : * // * i = S.Rows(); // numRows * // * i = S.Columns(); // numColumns * // * xf = S.GetValue(i); * // * xf = S(i,j); * // * S(i,j) = xf; * // * xf = S[i][j]; // NOT implemented * // * S[i][j] = xf; // NOT implemented * // * S.SetValue(i,j,xf); * // *********************************************************** // ***** Assignments: * // * S = symm; // symm MatrixSymm * // *********************************************************** // ***** Operators for tests: * // * if(S1 == S2) * // * if(S1 != S2) * // *********************************************************** // ***** Implemented operations : * // * S3 = S1 + S2; // S3 = S1 + S2; * // * S3 = S1 - S2; // S3 = S1 - S2; * // * TProduct(L,&S); // S = LTL * // * ProductT(L,&S); // S = LLT * // * TProduct(R,&S); // S = RTR * // * ProductT(R,&S); // S = RRT * // *********************************************************** // * Other functions: * // * S.Print("comments"); * // * S.Save("MAT.DAT"); * // * S.Save('*',"MAT.BIN"); * // * Delete(&S); // eliminates MatrixSymm * // * ChangeDimensions(rows,columns,&S); * // * Recover(&S,"MAT.DAT"); * // * Recover(&S,'*',"MAT.BIB"); * // *********************************************************** #ifndef SYMM_HPP #define SYMM_HPP // preventive declarations class Vector; class Matrix; class MatrixLeft; class MatrixRight; class MatrixSymm; class FactoredSymm; // =========================================================== // ================= class MatrixSymm ==================== // =========================================================== class MatrixSymm { friend class Vector; friend class Matrix; friend class MatrixRight; friend class MatrixLeft; friend class FactoredSymm; private: static const char *const ERROR; static int count; // for whoAmI float **matrix; int numRows,numColumns; int size; int whoAmI; void Initialize(int rows,int columns); // private constructor R('*',3,3) // deinitialisation void Deinitialize(void); MatrixSymm(char,int rows,int columns); //OK public: // =========================================================== // ****************** constructors *********************** // =========================================================== // default // MatrixLeft S MatrixSymm(void); // copy-initializer // MatrixSymm S = symm; MatrixSymm(MatrixSymm &rval); // sized and initialised to 0 // MatrixSymm S(3,3) MatrixSymm(int rows,int columns); // sized and initialised // MatrixSymm S(2,2,1.,2.,3.); MatrixSymm(int rows,int columnsn,double a11,...); // from array // MatrixSymm S(3,3,w) MatrixSymm(int rows,int columns,float *initvalues); // from formatted File // MatrixSymm S("SYMM.DAT"); MatrixSymm(char *filematrix); // from binary File // MatrixSymm L('*',"SYMM.BIN"); MatrixSymm(char,char *filematrix); // =========================================================== // ******************** destructor *********************** // =========================================================== ~MatrixSymm(void); // =========================================================== // *********** Non-modifying access functions ************ // =========================================================== // number of rows int Rows(void) const {return numRows;} // number of columns int Columns(void) const {return numColumns;} int WhoAmI(void) const {return whoAmI;} // receives the values with control float GetValue(int row,int col) const; // =========================================================== // ************** Modifying access functions ************* // =========================================================== // assigns values with control void SetValue(int row,int col,float val); // assigns and receives vector values with control float &operator () (int row,int col); // =========================================================== // *************** assignment operators ********************* // =========================================================== MatrixSymm &operator = (const MatrixSymm &rval); // =========================================================== // *************** operators for tests ******************* // =========================================================== friend char operator == (const MatrixSymm &lval,const MatrixSymm &rval); friend char operator != (const MatrixSymm &lval,const MatrixSymm &rval); // =========================================================== // ==================== OPERATIONS ======================= // =========================================================== // =========================================================== // *********************** Sum *************************** // =========================================================== friend MatrixSymm operator + (const MatrixSymm &lval,const MatrixSymm &rval); // =========================================================== // ******************** Difference *********************** // =========================================================== friend MatrixSymm operator - (const MatrixSymm &lval,const MatrixSymm &rval); // =========================================================== // ********************* TProduct ************************ // =========================================================== friend void TProduct(const MatrixRight &lvalAndRval, MatrixSymm *result); friend void TProduct(const MatrixLeft &lvalAndRval, MatrixSymm *result); // =========================================================== // ********************* ProductT ************************ // =========================================================== friend void ProductT(const MatrixRight &lvalAndRval, MatrixSymm *result); friend void ProductT(const MatrixLeft &lvalAndRval, MatrixSymm *result); // =========================================================== // =========== Non-modifying functions =================== // =========================================================== // ***********************< Print >*************************** void Print(char *msg=""); // ************************< Save >*************************** void Save(char *filematrix); // formatted void Save(char,char *filematrix);// binary // =========================================================== // ============= Modifying Functions ======================= // =========================================================== friend void Delete(MatrixSymm *S); // eliminates MatrixSymm friend void ChangeDimensions(int rows,int columns, MatrixSymm *result,char zero = 0); // from formatted file friend void Recover(MatrixSymm *A,char *filematrix); // from binary file friend void Recover(MatrixSymm *A,char,char *filematrix); friend void Swap(MatrixSymm *lval,MatrixSymm *rval); // transforms a MatrixSymm in FactoredSymm // MatrixSymm gets destroyed friend void CommuteMatrixToFactored (MatrixSymm *lval,FactoredSymm *rval); }; #endif SYMM_HPP