#include <math.h> #include <iostream.h> #include <conio.h> /*#ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; #define new DEBUG_NEW #endif */ //-------------------------------------------------------------------- PMatrix::PMatrix() : element(NULL){ ***** (12,1):Qualifier PMatrix is not a class or namespace************ ***** declaration terminated incorrectly************** } //Default constructor //-------------------------------------------------------------------- PMatrix::~PMatrix(){ delete [] element; element = NULL; } //Destructor //-------------------------------------------------------------------- void PMatrix::GetCopyOfElements(double * copy)const{ ASSERT(copy != NULL); for(int i = 0; i < m_nElements; ++i){ copy[i] = element[i]; } } //GetCopyOfElements //-------------------------------------------------------------------- void PMatrix::MeEqualsOther(const PMatrix & other){ ASSERT(m_nRows == other.GetNumberRows() && m_nCols == other.GetNumberCols()); const double * pe = other.GetElements(); for(int i = 0; i < m_nElements; ++i){ element[i] = pe[i]; }
class PMatrix{ //A general matrix. protected: int m_nRows; int m_nCols; int m_nElements; double * element; public: PMatrix(); //Default constructor. virtual ~PMatrix(); inline virtual int GetNumberRows()const = 0; inline virtual int GetNumberCols()const = 0; inline virtual int GetNumberElements()const = 0; inline const double * GetElements()const{return element;} inline double * GetNonconstantElements(){return element;} inline const double * GetRow(int row)const{ASSERT(row >= 0 && row < m_nRows); return element + row * m_nCols;} inline double * GetNonconstantRow(int row)const{ASSERT(row >= 0 && row < m_nRows); return element + row * m_nCols;} inline virtual double GetElement(int row, int col)const = 0; void GetCopyOfElements(double * copy)const; bool IsZero()const; bool HasLargeElements(double max)const; void MeEqualsMeTransposed(); void MeEqualsOther(const PMatrix & other); void MeEqualsMinusOther(const PMatrix & other); virtual void MeEqualsMinusMe()const; void InsertDiagonalSubmatrix(int order, int startRow, int startCol, double diag)const; void MakeMeZero()const{for(int i = 0; i < m_nElements; ++i)element[i] = 0.0;} virtual void MeTimesColumnVector(const double * givenVector, double * resultingVector)const = 0; virtual void RowVectorTimesMe(const double * givenVector, double * resultingVector)const = 0; virtual void MeTimesMatrix(const PMatrix & Given, PMatrix & Result)const = 0; virtual void MeTransposedTimesMatrix(const PMatrix & Given, PMatrix & Result)const = 0; virtual void MeTimesMatrixTransposed(const PMatrix & Given, PMatrix & Result)const = 0; double MeInnerProductMatrix(const PMatrix & M)const; virtual void MeEqualsSumOf(const PMatrix & A, const PMatrix & B)const; virtual void MeEqualsNegativeSumOf(const PMatrix & A, const PMatrix & B)const; virtual void MeEqualsDifferenceBetween(const PMatrix & A, const PMatrix & B)const; virtual void MeEqualsMePlus(const PMatrix & other)const; virtual void MeEqualsMeMinus(const PMatrix & other)const; virtual void MeEqualsMinusMePlus(const PMatrix & other)const; virtual void MeEqualsMinusMeMinus(const PMatrix & other)const; //The following virtual operators are inherited by all derived classes. They are //implemented in PMatrix.cpp, and can be used as-is, or overriden for efficiency. virtual void operator+=(const PMatrix & C); virtual void operator-=(const PMatrix & C); virtual void operator*=(double dd); virtual void operator/=(double dd); //Utility. virtual ArrayOfStr ReportMatrix(const char * title = NULL, const char * format = NULL)const; virtual bool CompareMatrix(const PMatrix & m)const; }; //Class PMatrix //-------------------------------------------------------------------- #endif // !defined(AFX_PMATRX_H__F4499B64_A4E5_4610_AFF0_3C0E2E369429__INCLUDED_)
PMatrix
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)