BaseMatrix.h
1#ifndef MATRIX_H
2#define MATRIX_H
3
4template<class T>
5class Matrix
6{
7public:
8 //Resizes the matrix to the specifications
9 //(SHOULD IT ONLY RESIZE SMALLER OR CAN IT RESIZE TO A LARGER SIZE?, IF IT CAN DOES IT FILL IT WITH ZEROES?) AM I ASSUMING ALL MATRICES WILL BE SQUARE?
10 virtual void resize( int nRow, int nCol) = 0;
11 virtual T getElement(int i, int j)const = 0;
12 virtual void setElement(int i, int j, T value) = 0;
13
14 virtual int getSize()const = 0; //Assumes Matrix is Square
15
16 virtual void setZero() = 0; //Sets all elements in the matrix to zero
17 virtual void setIdentity(); //Sets the matrix to the identity matrix
18 virtual void invert() = 0; //Inverts the matrix
19
20 virtual Matrix<T>* operator*(const Matrix<T>* RHS) = 0; //Matrix Multiplication
21 virtual Matrix<T>* operator+(const Matrix<T>* RHS) = 0; //Matrix Addition
22 virtual Matrix<T>* operator-(const Matrix<T>* RHS) = 0; //Matrix Subtraction
23 virtual void operator=(const Matrix<T>* RHS); //Makes the elements in the matrix the same as the one passed, probably really slow performance
24
25 virtual ~Matrix(){}; //ERROR ????
26
27};
28
29
30template<typename T>
31void Matrix<T>::setIdentity()
32{
33 setZero();
34
35 for(int i = 0; i < this->getSize(); i++)
36 {
37 setElement(i, i, 1);
38 }
39}
40
41template<typename T>
42void Matrix<T>::operator=(const Matrix<T>* RHS)
43{
44 //Resize if neccessary
45 if(this->getSize() != RHS->getSize() )
46 this->resize(RHS->getSize(), RHS->getSize() );
47
48 //Set the elements
49 for(int i = 0; i < RHS->getSize(); i++)
50 {
51 for(int j = 0; j < RHS->getSize(); j++)
52 {
53 this->setElement(i, j, RHS->getElement(i, j));
54 }
55 }
56}
57
58
59
60
61#endif

Generated using doxygen 1.14.0