aslMatrices.h
Go to the documentation of this file.
/*
* Advanced Simulation Library <http://asl.org.il>
*
* Copyright 2015 Avtech Scientific <http://avtechscientific.com>
*
*
* This file is part of Advanced Simulation Library (ASL).
*
* ASL is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, version 3 of the License.
*
* ASL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with ASL. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef ASLMATRICES
#define ASLMATRICES
#include "../aslUtilities.h"
#include "aslVectors.h"
namespace asl
{
template <typename T = double> class AMatr
{
private:
unsigned int nRow;
unsigned int nCol;
AVec<T> internalVec;
public:
inline AMatr();
inline AMatr(unsigned int nR, unsigned int nC);
inline AMatr(const AMatr<T> &a);
inline AMatr(unsigned int nR, unsigned int nC, AVec<T> v);
template <typename T1> AMatr(const AMatr<T1> &a);
const AMatr<T> & operator=(const AMatr & a);
inline T& operator()(int i, int j) {return internalVec[i*nCol+j];}
inline const T& operator()(int i, int j)const {return internalVec[i*nCol+j];}
inline T& operator[](int i) {return internalVec[i];}
inline const T& operator[](int i)const {return internalVec[i];}
inline unsigned int getNRow() const;
inline unsigned int getNCol() const;
inline void resize(unsigned int nR, unsigned int nCol);
inline const AVec<T> & getInternalVec() const;
inline AVec<T> & getInternalVec();
void setRow(unsigned int r, const AVec<T> & a);
void setColumn(unsigned int c, const AVec<T> & a);
};
template <typename T> std::ostream& operator<<(std::ostream &f,const AMatr<T> & a);
template <typename T>
inline const AMatr<T> & operator+=(AMatr<T> & a, const AMatr<T> & b);
template <typename T>
inline const AMatr<T> operator+ (const AMatr<T> & a, const AMatr<T> & b);
template <typename T>
inline const AMatr<T> operator- (const AMatr<T> & a, const AMatr<T> & b);
template <typename T>
const AMatr<T> operator* (const AMatr<T> &a, const AMatr<T> & b);
template <typename T>
const AVec<T> operator* (const AMatr<T> &a, const AVec<T> & b);
template <typename T>
const AVec<T> operator* (const AVec<T> &a, const AMatr<T> & b);
template <typename T>
const AMatr<T> operator* (const AMatr<T> &a, const T & b);
template <typename T>
const AMatr<T> operator* (const T &a, const AMatr<T> & b);
template <typename T> const T trace(const AMatr<T> &a);
template <typename T> const T trace(const AMatr<T> & a, const AMatr<T> & b);
template <typename T>
inline const AMatr<T> operator/ (const AMatr<T> & b, const T & a);
template <typename T>
AMatr<T> elementProduct(const AVec<T> & a, const AVec<T> & b);
template <typename T> AMatr<T> makeAMatr(const AVec<T> & a);
template <typename T> AMatr<T> makeAMatr(const AVec<T> & a, const AVec<T> & b);
template <typename T> AMatr<T> makeAMatr(const AVec<T> & a,
const AVec<T> & b,
const AVec<T> & c);
template <typename T> AMatr<T> makeAMatr(AVec<T> *a, unsigned int n);
template <typename T=int>AMatr<T> makeAMatrUnit(unsigned int n);
template <typename T> AVec<T> getDiagonal(const AMatr<T> & a);
template <typename T> AVec<T> getOffDiagonalUp(const AMatr<T> & a);
template <typename T> T det(const AMatr<T> & m);
template <typename T> AVec<T> solveSystem(const AMatr<T> & a,
const AVec<T> & b);
template <typename T>
AMatr<T> replaceRow(const AMatr<T> & a, const AVec<T> & b, unsigned int r);
template <typename T>
AMatr<T> replaceColumn(const AMatr<T> & a, const AVec<T> & b, unsigned int c);
template <typename T>
AMatr<T> inverseMatrix(const AMatr<T> & a);
// ------------------------------ Implementation -----------------
template <typename T> inline AMatr<T>::AMatr():
nRow(0),
nCol(0)
{
}
template <typename T> inline AMatr<T>::AMatr(unsigned int nR, unsigned int nC):
nRow(nR),
nCol(nC),
internalVec(nR*nC)
{
}
template <typename T> inline AMatr<T>::AMatr(const AMatr<T> &a):
nRow(a.nRow),
nCol(a.nCol),
internalVec(a.internalVec)
{
}
template <typename T> inline AMatr<T>::AMatr(unsigned int nR, unsigned int nC, AVec<T> v):
nRow(nR),
nCol(nC),
internalVec(v)
{
}
template <typename T> inline AVec<T> & AMatr<T>::getInternalVec()
{
return internalVec;
}
template <typename T> inline const AVec<T> & AMatr<T>::getInternalVec() const
{
return internalVec;
}
template <typename T> inline unsigned int AMatr<T>::getNRow() const
{
return nRow;
}
template <typename T> inline unsigned int AMatr<T>::getNCol() const
{
return nCol;
}
template <typename T>
inline void AMatr<T>::resize(unsigned int nr, unsigned int nc)
{
nRow=nr;
nCol=nc;
internalVec.resize(nr*nc);
}
template <typename T>
inline const AMatr<T> & operator+=(AMatr<T> & a, const AMatr<T> & b)
{
a.getInternalVec += b.getInternalVec;
return a;
}
template <typename T>
inline const AMatr<T> operator+ (const AMatr<T> & a, const AMatr<T> & b)
{
return {a.getNRow(),a.getNCol(),a.getInternalVec() + b.getInternalVec()};
}
template <typename T>
inline const AMatr<T> operator- (const AMatr<T> & a,const AMatr<T> & b)
{
return {a.getNRow(),a.getNCol(),a.getInternalVec() - b.getInternalVec()};
}
template <typename T>
inline const AMatr<T> operator/ (const AMatr<T> & b, const T & a)
{
return {b.getNRow(), b.getNCol(), b.getInternalVec() / a};
}
void getEValEVecMatSym2x2(double a, double b, double c, double & l1, double & l2, double & v1x, double & v1y, double & v2x, double & v2y);
void getEValEVecMatSym2x2(double a, double b, double c, double & l1, double & l2, double & v1x, double & v1y, double & v2x, double & v2y);
void getEValEVecMatSym3x3(double a, double b, double c, double e, double f, double g,
double & l1, double & l2, double & l3,
double & v1x, double & v1y, double & v1z,
double & v2x, double & v2y, double & v2z,
double & v3x, double & v3y, double & v3z);
} // asl
#endif //ASLMATRICES
asl::AMatr
Definition: aslMatrices.h:39
asl::AMatr::makeAMatr
AMatr< T > makeAMatr(const AVec< T > &a, const AVec< T > &b)
generates a matrix with two rows
asl::AMatr::trace
const T trace(const AMatr< T > &a, const AMatr< T > &b)
Trace of a matrix product .
asl::AMatr::setColumn
void setColumn(unsigned int c, const AVec< T > &a)
asl::AMatr::elementProduct
AMatr< T > elementProduct(const AVec< T > &a, const AVec< T > &b)
element product of two vectors
asl::AMatr::operator=
const AMatr< T > & operator=(const AMatr &a)
asl::AMatr::getInternalVec
const AVec< T > & getInternalVec() const
Definition: aslMatrices.h:221
asl::AMatr::getOffDiagonalUp
AVec< T > getOffDiagonalUp(const AMatr< T > &a)
returns AVec<T> containing the uper off diagonal elements
asl::AMatr::inverseMatrix
AMatr< T > inverseMatrix(const AMatr< T > &a)
returns inverse matrix for cases 2x2 and 3x3<T>
asl::AMatr::trace
const T trace(const AMatr< T > &a)
Trace of a matrix .
asl::AMatr::AMatr
AMatr()
Definition: aslMatrices.h:191
asl::AMatr::operator<<
std::ostream & operator<<(std::ostream &f, const AMatr< T > &a)
asl::AMatr::replaceColumn
AMatr< T > replaceColumn(const AMatr< T > &a, const AVec< T > &b, unsigned int c)
generate matrix with content of the matrix a but with replaced column c by vector b<T>
asl::AMatr::AMatr
AMatr(const AMatr< T1 > &a)
asl::AMatr::setRow
void setRow(unsigned int r, const AVec< T > &a)
asl::AMatr::det
T det(const AMatr< T > &m)
computes determinant expression fo cases 2x2 and 3x3 only
asl::AMatr::getNCol
unsigned int getNCol() const
Definition: aslMatrices.h:231
asl::AMatr::replaceRow
AMatr< T > replaceRow(const AMatr< T > &a, const AVec< T > &b, unsigned int r)
generate matrix with content of the matrix a but with replaced row r by vector b<T>
asl::AMatr::getNRow
unsigned int getNRow() const
Definition: aslMatrices.h:226
asl::AMatr::resize
void resize(unsigned int nR, unsigned int nCol)
Definition: aslMatrices.h:237
asl::AMatr::operator[]
const T & operator[](int i) const
doesn't chek boundaries
Definition: aslMatrices.h:58
asl::AMatr::makeAMatr
AMatr< T > makeAMatr(const AVec< T > &a)
generates a matrix with a row
asl::AMatr::makeAMatr
AMatr< T > makeAMatr(const AVec< T > &a, const AVec< T > &b, const AVec< T > &c)
generates a matrix with three rows
asl::AMatr::getDiagonal
AVec< T > getDiagonal(const AMatr< T > &a)
returns AVec containing the diagonal elements
asl::AMatr::operator()
const T & operator()(int i, int j) const
doesn't chek boundaries
Definition: aslMatrices.h:54
asl::AMatr::operator[]
T & operator[](int i)
doesn't chek boundaries
Definition: aslMatrices.h:56
asl::AMatr::operator()
T & operator()(int i, int j)
doesn't chek boundaries
Definition: aslMatrices.h:52
asl::AMatr::makeAMatrUnit
AMatr< T > makeAMatrUnit(unsigned int n)
asl::AMatr::makeAMatr
AMatr< T > makeAMatr(AVec< T > *a, unsigned int n)
generates a matrix with n rows
asl::AVec
Definition: aslVectorsDynamicLength.h:40
asl::solveSystem
AVec< T > solveSystem(const AMatr< T > &a, const AVec< T > &b)
returns solution of a system of linear equations
asl::operator-
SPDistanceFunction operator-(SPDistanceFunction a)
asl::operator*
SPPositionFunction operator*(SPPositionFunction a, SPPositionFunction b)
Definition: aslPositionFunction.h:215
asl
Advanced Simulation Library.
Definition: aslDataInc.h:31
asl::operator+
const AMatr< T > operator+(const AMatr< T > &a, const AMatr< T > &b)
Definition: aslMatrices.h:252
asl::operator+=
const AMatr< T > & operator+=(AMatr< T > &a, const AMatr< T > &b)
Definition: aslMatrices.h:245
asl::l2
const T l2(const AVec< T > &a)
Definition: aslVectorsDynamicLengthOperations.h:147
asl::getEValEVecMatSym3x3
void getEValEVecMatSym3x3(double a, double b, double c, double e, double f, double g, double &l1, double &l2, double &l3, double &v1x, double &v1y, double &v1z, double &v2x, double &v2y, double &v2z, double &v3x, double &v3y, double &v3z)
Eigenvalues and eigenvectors calcutaion for symetric matrix 2x2.
asl::operator/
const AMatr< T > operator/(const AMatr< T > &b, const T &a)
Definition: aslMatrices.h:264
asl::getEValEVecMatSym2x2
void getEValEVecMatSym2x2(double a, double b, double c, double &l1, double &l2, double &v1x, double &v1y, double &v2x, double &v2y)
Eigenvalues and eigenvectors calcutaion for symetric matrix 2x2.
aslVectors.h
definition of class АVec<T>