Core 1.0
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Attributes | Friends | List of all members
Matrix2 Class Reference

This class implements 22 matrix. More...

#include <matrix.h>

Public Member Functions

 Matrix2 ()
 Empty.
 
 Matrix2 (const double &)
 Creates a matrix with the same diagonal value. More...
 
 Matrix2 (const Vector2 &)
 Create a diagonal matrix with diagonal terms set to the vector entries. More...
 
 Matrix2 (const Vector2 &, const Vector2 &)
 Creates a column vector matrix. More...
 
 Matrix2 (const double &, const double &, const double &, const double &)
 Creates a matrix with a set of double values.
 
 Matrix2 (const double &, const double &, const double &)
 Create a symmetric matrix. More...
 
constexpr double & operator[] (int)
 Direct access to the array of the matrix.
 
constexpr double operator[] (int) const
 Overloaded.
 
constexpr double & operator() (int, int)
 Get element (i,j) of the matrix. More...
 
constexpr double operator() (int, int) const
 Overloaded.
 
Vector2 C (int) const
 Get the i-th column vector of the matrix. More...
 
Matrix2 operator- () const
 Returns the opposite of a matrix -A.
 
Matrix2operator+= (const Matrix2 &)
 Destructive addition operator.
 
Matrix2operator-= (const Matrix2 &)
 Destructive subtraction operator.
 
Matrix2operator*= (const Matrix2 &)
 Destructive multiplication.
 
Matrix2operator*= (double)
 Destructive multiplication operator.
 
Matrix2operator/= (double)
 Destructive division operator.
 
Vector2 operator* (const Vector2 &) const
 Right multiply by a vector.
 
Matrix2 T () const
 Transpose the matrix. More...
 
double Determinant () const
 Computes the determinant of the matrix.
 
Matrix2 Inverse () const
 Computes the inverse of a matrix A-1. More...
 
double Trace () const
 Compute the trace (sum of diagonal terms) of a matrix.
 
double FrobeniusNorm () const
 Compute the Frobenius norm of the matrix.
 
Quadric Characteristic () const
 Compute the characteristic polynomial.
 
double SpectralNorm () const
 Compute the spectral norm of the matrix.
 
double InfinityNorm () const
 Compute the infinity norm of the matrix.
 
void EigenSolveSymmetric (double[2], Vector2[2]) const
 Find the eigen values of the matrix. More...
 
Vector2 Eigen () const
 Compute the eigen values.
 

Static Public Member Functions

static Matrix2 Rotation (const double &)
 Create a rotation matrix. More...
 
static Matrix2 Rotation (RandomFast &=random239)
 Create a random rotation matrix. More...
 
static Matrix2 Tensor2 (const double &)
 Create an anisotropic tensor matrix. More...
 
static Matrix2 Tensor2 (const double &, const double &)
 Create a tensor matrix. More...
 

Static Public Attributes

static const Matrix2 Null
 This static member defines the null matrix.
 
static const Matrix2 Identity
 This static member defines the identity matrix.
 

Protected Attributes

double r [4] = { 1.0,0.0,0.0,1.0 }
 The array storing the coefficients of the matrix.
 

Friends

Matrix2 operator+ (const Matrix2 &, const Matrix2 &)
 Overloaded.
 
Matrix2 operator- (const Matrix2 &, const Matrix2 &)
 Overloaded.
 
Matrix2 operator* (const Matrix2 &, const Matrix2 &)
 Multiplication. More...
 
Matrix2 operator* (const Matrix2 &, const double &)
 Right multiply by a double.
 
Matrix2 operator* (const double &, const Matrix2 &)
 Left multiply by a double.
 
Matrix2 operator/ (const Matrix2 &, const double &)
 Right divide by a double.
 
Matrix2 operator/ (const double &, const Matrix2 &)
 Computes the inverse matrix and scales it by a double. More...
 
std::ostream & operator<< (std::ostream &, const Matrix2 &)
 Overloaded. More...
 

Detailed Description

This class implements 22 matrix.

Operators have been overloaded to behave as expected. Thus it is possible to write:

Matrix2 a = Matrix2(Vector2(1.0, 2.0)); // Scale
Matrix2 b = Matrix2::Rotation(Math::Pi / 4.0); // Rotation matrix
Vector2 u(2.0, -1.0); // Vector
Vector2 v = (a*b)*u; // Matrix vector product
static const double Pi
π.
Definition: mathematics.h:174
This class implements 22 matrix.
Definition: matrix.h:426
static Matrix2 Rotation(const double &)
Create a rotation matrix.
Definition: matrix2.cpp:87
Matrix2()
Empty.
Definition: matrix.h:431
Vectors in two dimensions.
Definition: evector.h:617

Constructor & Destructor Documentation

◆ Matrix2() [1/4]

Matrix2::Matrix2 ( const double &  a)
inlineexplicit

Creates a matrix with the same diagonal value.

Parameters
aThe diagonal value.

◆ Matrix2() [2/4]

Matrix2::Matrix2 ( const Vector2 a)
inlineexplicit

Create a diagonal matrix with diagonal terms set to the vector entries.

Note that this is a scaling matrix.

Parameters
aVector of diagonal values

◆ Matrix2() [3/4]

Matrix2::Matrix2 ( const Vector2 a,
const Vector2 b 
)
inlineexplicit

Creates a column vector matrix.

Parameters
a,bColumn vectors.

◆ Matrix2() [4/4]

Matrix2::Matrix2 ( const double &  a,
const double &  b,
const double &  c 
)
inlineexplicit

Create a symmetric matrix.

Parameters
a,bDiagonal terms.
cLast term.

Member Function Documentation

◆ C()

Vector2 Matrix2::C ( int  i) const
inline

Get the i-th column vector of the matrix.

Parameters
iIndex.

◆ EigenSolveSymmetric()

void Matrix2::EigenSolveSymmetric ( double  a[2],
Vector2  e[2] 
) const

Find the eigen values of the matrix.

Return eigen vectors as well.

Parameters
aAn array of two eigen values.
eThe array containing the two eigen vectors.

◆ Inverse()

Matrix2 Matrix2::Inverse ( ) const

Computes the inverse of a matrix A-1.

This function returns the null matrix if A cannot be inversed.

The threshold value involved in the singular matrix detection is set to 10-18.

◆ operator()()

constexpr double & Matrix2::operator() ( int  i,
int  j 
)
inlineconstexpr

Get element (i,j) of the matrix.

Parameters
iRow.
jColumn.

◆ Rotation() [1/2]

Matrix2 Matrix2::Rotation ( const double &  a)
static

Create a rotation matrix.

Parameters
aAngle in radian.

◆ Rotation() [2/2]

Matrix2 Matrix2::Rotation ( RandomFast ra = random239)
static

Create a random rotation matrix.

This is a simple function which is equivalent to the following inlined code:

double r[4]
The array storing the coefficients of the matrix.
Definition: matrix.h:428
A fast linear congruential random number generator.
Definition: random.h:41
Parameters
raRandom number generator.

◆ T()

Matrix2 Matrix2::T ( ) const
inline

Transpose the matrix.

Note that if the matrix is a rotation matrix, then the transpose is equal to its inverse.

See also
Matrix::T()

◆ Tensor2() [1/2]

Matrix2 Matrix2::Tensor2 ( const double &  angle)
static

Create an anisotropic tensor matrix.

Parameters
angleThe angle of the tensor.

◆ Tensor2() [2/2]

Matrix2 Matrix2::Tensor2 ( const double &  c,
const double &  s 
)
static

Create a tensor matrix.

Parameters
c,sCosine and sine of the angle of the tensor.

Friends And Related Function Documentation

◆ operator*

Matrix2 operator* ( const Matrix2 u,
const Matrix2 v 
)
friend

Multiplication.

Parameters
u,vInput matrices.

◆ operator/

Matrix2 operator/ ( const double &  x,
const Matrix2 a 
)
friend

Computes the inverse matrix and scales it by a double.

Parameters
xReal.
aMatrix.

◆ operator<<

std::ostream & operator<< ( std::ostream &  s,
const Matrix2 matrix 
)
friend

Overloaded.

Parameters
sStream.
matrixThe matrix.