Introduction
This Matrix class is a templated class that can be initialized as any kind of numeric types(int, double,float,& etc). it includes Inverse & determinant functions (which are not so easy to write the code) & also all the operators needed for a Matrix class like Multiplying 2 matrix or multiplying a digit to the matrix. it is able to be any size & also it is easy to use.
Instruction
the uploaded file check.zip contains a file which shows how the Matrix can get initialized & how the operators or functions work. Note that parentheses is maybe the most important operator.it allows you to get access to the array elements ,as :
matrix1
(2,0)=5;
Member functions of class Matrix
These are all the member functions & operators of the class :
template<class T>
class Matrix
{
public:
- Matrix(int Row_Size,int Column_Size)
- Matrix() >
- Matrix(const Matrix<T> &)
- ~Matrix(void)
- void Set_Element(int Row_,int Column,const T& Value)
- T Get_Element(int Row ,int Column) const
- bool operator!() const;
- const Matrix<T> & operator=(const Matrix<T> &)
- const Matrix<T> & operator=(const T&)
- bool operator==(const Matrix<T> &) const
- bool operator==(const T & ) const
- bool operator!=(const Matrix<T> & second) const
- bool operator!=(const T & number)
- T &operator() (int Row,int Column)
- Matrix<T> operator+(const T &)
- Matrix<T> operator+(const Matrix<T> &)
- const Matrix<T> &operator+=(const T&)
- const Matrix<T> & operator+=(const Matrix<T> &)
- Matrix<T> operator-(const T&)
- Matrix<T> operator - (const Matrix<T> &)
- const Matrix<T> & operator -=(const T & )
- const Matrix<T> & operator -=(Matrix<T> & )
- Matrix<T> operator*(const T&)
- Matrix<T> operator* (const Matrix<T> &)
- const Matrix<T> & operator*=(const T&)
- const Matrix<T> & operator*=(const Matrix<T> &)
- void Transposed();>
- Matrix<T> GetTransposed() const
- bool Inverse();>
- Matrix<T> GetInversed() const
- double Det() const
- void Set_Size(int RowSize,int ColumnSize)
- const int& Get_ColumnSize() const
- const int & Get_RowSize() const
private:
- int m_RowSize
- int m_ColumnSize
- T**m_Data
};
Notes
note:The returned argument of Inverse (a boolean ) Shows weather the matrix is Invertible & if it is ,inverts the Matrix
note:I have written this code in vc 2005 but it is not a managed code.if you compile it in vc6 you will see some errors that as an instance i is redeclared .thats because vc6 is alittle differant as when you declare i this way :for (int i=0;i<5;i++){ /*statements*/}
i is destroyed after for statement but in vc6 it is a declared variable even after for statement.but it is easy to change it to vc6 by debugging such errors in vc.you can do it yourself.
note:the only code i have not written my self is determinant because i have found a great one being written by
Paul Bourke .to find the original code go to
http://local.wasp.uwa.edu.au/~pbourke/other/determinant/Some Technics that are used in Class
to announce one,I have to point to the way the element array (m_Data) is declared using new command:
consider the m_RowSize & m_ColumnSize are given
m_Data=new T* [m_RowSize];
for(int i=0;i<m_RowSize;i++)
m_ColumnSize=new T [m_ColumnSize];
HOPE YOU USE & ENJOY IT