informatique 1
Dans les projets de
développement informatique, il est intéressant d’utiliser des objets de type matrice.
La classe matrice décrite en
langage C++ à l’aide de template permet
de traiter des opérations impliquant des objets de type vector.
/////////////////////////////////////////////////////////////////////////
//
Template matrix////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
template<class
T> class matrix
{
public:
matrix();
matrix(int lines, int columns, T
value); //constant matrix
matrix(int dim, T value);
//squared matrix
matrix(vector<T>&
inputs, int jump);
explicit
matrix(vector<T>& diag);
matrix(const
matrix<T>& x);
matrix<T> operator= (const
matrix& x);
bool operator||(const
matrix<T>& x);
bool operator|(const matrix<T>& x);
bool operator==(const matrix<T>& x);
matrix<T>
operator*(matrix& x);
matrix<T> operator+(const
matrix& x);
matrix<T> operator-(const
matrix& x);
matrix<T>&
operator+=(const matrix& x);
matrix<T>&
operator-=(const matrix& x);
T operator()(int line, int col)
const;
matrix<T> operator~();
T
operator!();
matrix<T>& permuteLines(int line1, int
line2);
matrix<T>&
permuteCols(int col1, int col2);
matrix<T> InvMatrix();
matrix<T>
CholeskyFactor();
matrix<T>
EigenVectors(matrix& sigma);
matrix<T>
EigenValues(matrix& sigma);
private:
vector<T> itsElem;
int itsJump;
public:
inline int Position(int line, int col, int jump)
const
{
int
value = col - 1 + ( line - 1 ) * jump;
return value;
}
inline T getElement(int i, int j) const
{
int pos = Position(i, j,
getRowSize());
return itsElem[pos];
}
inline void setElement(int i, int j, T value)
{
int pos = Position(i, j,
getRowSize());
itsElem[pos] = value;
}
inline
vector<T> getElem() const
{
return vector<T>(itsElem);
}
inline int getJump() const
{
return itsJump;
}
inline void setJump(int jump)
{
itsJump = jump;
}
inline
void setElem(vector<T>& elem)
{
itsElem = elem;
}
inline int getColumnSize() const
{
int total = itsElem.size();
return total / itsJump;
}
inline int getRowSize() const
{
return itsJump;
}
inline vector<T> getLine(int line) const
{
vector<T> vecLine(itsJump);
for (int i=1; i<=itsJump; i++)
vecLine[i-1] =
itsElem[itsJump*(line-1) + i-1];
return vecLine;
}
inline vector<T> getCol(int col) const
{
int colSize = getColumnSize();
vector<T> vecCol(colSize);
for (size_t j=1; j<=colSize; j++)
vecCol[j-1] =
itsElem[(j-1)*itsJump + col-1];
return vecCol;
}
//Tools for squared matrices.
bool isSymmetric() const;
bool isSquaredDiag() const;
bool isSdp() const;
matrix<T> getSubMatrix(vector&
indices) const;
inline bool isSquared() const
{
if (itsJump == getColumnSize())
return true;
else
return false;
}
};
template<class T>
matrix operator+(T value);
template<class
T> matrix operator+(const matrix& x, T value);
template<class
T> matrix operator+(T value, const matrix& x);
template<class
T> matrix operator-(T value);
template<class
T> matrix operator-(T value, const matrix& x);
template<class
T> matrix operator-(const matrix& x, T value);
template<class
T> matrix operator*(T value, matrix& x);
template<class
T> matrix operator*(matrix& x, T value);
template<class
T> matrix& operator+=(matrix& x, T value);
template<class
T> matrix& operator-=(matrix& x, T value);
template<class
T> matrix& operator*=(matrix& x, T value);
template<class T> bool
operator|(const vector& tv, const matrix& x);
template<class T> bool
operator|(const matrix& x, const vector& v);
template<class T>
vector operator*(vector& tv, matrix& x);
template<class
T> vector operator*(matrix& x, vector&
v);
2/10 sur 1 vote
Sélectionnez une note dans le menu déroulant.
1. hakimov Le 04/20/2008 à 11:50
La partie informatique de ce site a été modifiée par d'autres personnes que moi. Ca rajoute des bugs au code.
Dernière mise à jour de cette page le 03/21/2008