IGLib  1.7.2
The IGLib base library EXTENDED - with other lilbraries and applications.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
Meta.Numerics.Matrices.SquareMatrix Class Reference

Represents a square matrix. More...

+ Inheritance diagram for Meta.Numerics.Matrices.SquareMatrix:
+ Collaboration diagram for Meta.Numerics.Matrices.SquareMatrix:

Public Member Functions

 SquareMatrix (int dimension)
 Initializes a new square matrix. More...
 
 SquareMatrix (double[,] entries)
 Initializes a new square matrix from the given 2D array. More...
 
override double OneNorm ()
 Computes the 1-norm of the matrix.
Returns
||M||1
The 1-norm of a matrix is the largest column sum. More...
 
override double InfinityNorm ()
 Computes the ∞-norm of the matrix.
Returns
||M||∞
The ∞-norm of a matrix is the largest row sum. More...
 
override RowVector Row (int r)
 Returns a vector representing a given row of the matrix. More...
 
override ColumnVector Column (int c)
 Gets a copy of one column of the the matrix. More...
 
SquareMatrix Copy ()
 Copies the matrix. More...
 
SquareMatrix Transpose ()
 Creates a transpose of the matrix. More...
 
SquareMatrix Inverse ()
 Computes the inverse of the matrix. More...
 
LUDecomposition LUDecomposition ()
 Computes the LU decomposition of the matrix. More...
 
Complex[] Eigenvalues ()
 Computes the eigenvalues of the matrix. More...
 
ComplexEigensystem Eigensystem ()
 Computes the eigenvalues and eigenvectors of the matrix. More...
 
SingularValueDecomposition SingularValueDecomposition ()
 Computes the singular value decomposition of the square matrix. More...
 
SquareQRDecomposition QRDecomposition ()
 Computes a QR decomposition of the matrix. More...
 
SquareMatrix Power (int n)
 Computes the matrix raised to the given power. More...
 
- Public Member Functions inherited from Meta.Numerics.Matrices.AnySquareMatrix
virtual double Trace ()
 Computes the trace of the square matrix. More...
 
- Public Member Functions inherited from Meta.Numerics.Matrices.AnyRectangularMatrix
virtual double FrobeniusNorm ()
 Computes the Frobenius-norm of the matrix. More...
 
virtual SymmetricMatrix MultiplySelfByTranspose ()
 Computes the product of the matrix and its transpose. More...
 
virtual SymmetricMatrix MultiplyTransposeBySelf ()
 Computes the product of the matrix's transpose and itself. More...
 
bool Equals (AnyRectangularMatrix other)
 Determines whether the given matrix equals the current matrix. More...
 
override bool Equals (object obj)
 Determines whether the given object is an equal matrix. More...
 
override int GetHashCode ()
 Not a valid operation. More...
 
- Public Member Functions inherited from Meta.Numerics.Matrices.AnyMatrix< T >
virtual void Fill (Func< int, int, T > f)
 Sets all matrix entries according to a supplied fill function. More...
 
virtual T[,] ToArray ()
 Copies the matrix into an array. More...
 

Static Public Member Functions

static SquareMatrix operator+ (SquareMatrix A, SquareMatrix B)
 Adds two real, square matrices. More...
 
static SquareMatrix operator- (SquareMatrix A, SquareMatrix B)
 Computes the difference of two square matrices. More...
 
static SquareMatrix operator* (SquareMatrix A, SquareMatrix B)
 Computes the product of two square matrices. More...
 
static ColumnVector operator* (SquareMatrix A, ColumnVector v)
 Computes the product of a square matrix and a column vector. More...
 
static SquareMatrix operator* (double alpha, SquareMatrix A)
 Multiply a real, square matrix by a real constant. More...
 
static SquareMatrix operator* (SquareMatrix A, double alpha)
 Divides a real, square matrix by a real constant. More...
 
static SquareMatrix operator- (SquareMatrix A)
 Negates a real, square matrix. More...
 
- Static Public Member Functions inherited from Meta.Numerics.Matrices.AnySquareMatrix
static SquareMatrix operator+ (AnySquareMatrix A, AnySquareMatrix B)
 Adds any two real, square matrices. More...
 
static SquareMatrix operator- (AnySquareMatrix A, AnySquareMatrix B)
 Subtracts any two real, square matrices. More...
 
static SquareMatrix operator* (AnySquareMatrix A, AnySquareMatrix B)
 Multiplies any two real, square matrices. More...
 
- Static Public Member Functions inherited from Meta.Numerics.Matrices.AnyRectangularMatrix
static RectangularMatrix operator+ (AnyRectangularMatrix A, AnyRectangularMatrix B)
 Adds any two real, rectangular matrices. More...
 
static RectangularMatrix operator- (AnyRectangularMatrix A, AnyRectangularMatrix B)
 Subtracts any two real, rectangular matrices. More...
 
static RectangularMatrix operator* (AnyRectangularMatrix A, AnyRectangularMatrix B)
 Multiplies any two real, rectangular matrices. More...
 
static RectangularMatrix operator* (double alpha, AnyRectangularMatrix A)
 Multiplies any real, rectangular matrix by a real constant. More...
 
static ColumnVector operator* (AnyRectangularMatrix A, ColumnVector v)
 Multiplies any real, rectangular matrix with a real column vector. More...
 
static bool operator== (AnyRectangularMatrix A, AnyRectangularMatrix B)
 Determines whether two matrices are equal. More...
 
static bool operator!= (AnyRectangularMatrix A, AnyRectangularMatrix B)
 Determines whether two matrices are not equal. More...
 

Properties

override int Dimension [get]
 Gets the dimension of the matrix. More...
 
override double this[int r, int c] [get, set]
 Gets or sets an entry of the matrix. More...
 
- Properties inherited from Meta.Numerics.Matrices.AnySquareMatrix
abstract int Dimension [get]
 Gets or sets the dimension of the square matrix. More...
 
override int RowCount [get]
 
override int ColumnCount [get]
 
- Properties inherited from Meta.Numerics.Matrices.AnyMatrix< T >
abstract int RowCount [get]
 Gets the number of matrix rows. More...
 
abstract int ColumnCount [get]
 Gets the number of matrix columns. More...
 
abstract T this[int r, int c] [get, set]
 Gets or sets the value of a matrix entry. More...
 
bool IsReadOnly [get, set]
 Gets a flag indicating whether the matrix is read-only. More...
 

Private Attributes

readonly int dimension
 
readonly double[] store
 

Additional Inherited Members

- Protected Member Functions inherited from Meta.Numerics.Matrices.AnyRectangularMatrix
 AnyRectangularMatrix ()
 
- Protected Member Functions inherited from Meta.Numerics.Matrices.AnyMatrix< T >
 AnyMatrix ()
 

Detailed Description

Represents a square matrix.

Constructor & Destructor Documentation

Meta.Numerics.Matrices.SquareMatrix.SquareMatrix ( int  dimension)
inline

Initializes a new square matrix.

Parameters
dimensionThe dimension of the matrix, which must be positive.
Exceptions
ArgumentOutOfRangeExceptionThrown when dimension < 1.
Meta.Numerics.Matrices.SquareMatrix.SquareMatrix ( double  entries[,])
inline

Initializes a new square matrix from the given 2D array.

Parameters
entriesThe source 2D array.
Exceptions
ArgumentNullExceptionentries is null.
DimensionMismatchExceptionThe first and second dimensions of entries are not equal.

Member Function Documentation

override double Meta.Numerics.Matrices.SquareMatrix.OneNorm ( )
inlinevirtual

Computes the 1-norm of the matrix.

Returns
||M||1
The 1-norm of a matrix is the largest column sum.

Reimplemented from Meta.Numerics.Matrices.AnyRectangularMatrix.

Referenced by Test.SquareMatrixTest.SquareMatrixNorms().

override double Meta.Numerics.Matrices.SquareMatrix.InfinityNorm ( )
inlinevirtual

Computes the &#x221E;-norm of the matrix.

Returns
||M||&#x221E;
The &#x221E;-norm of a matrix is the largest row sum.

Reimplemented from Meta.Numerics.Matrices.AnyRectangularMatrix.

Referenced by Test.SquareMatrixTest.SquareMatrixNorms().

override RowVector Meta.Numerics.Matrices.SquareMatrix.Row ( int  r)
inlinevirtual

Returns a vector representing a given row of the matrix.

Parameters
rThe (zero-based) row number to return.
Returns
An independent copy of the specified row.

The returned vector is not linked to the matrix. If an entry in the matrix is updated after this method is called, the returned object will continue to represent a row of the original, not the updated, matrix. Similiarly, updates to the elements of the returned vector will not update the original matrix.

Reimplemented from Meta.Numerics.Matrices.AnyRectangularMatrix.

Referenced by Test.SquareMatrixTest.SquareMatrixAccess().

override ColumnVector Meta.Numerics.Matrices.SquareMatrix.Column ( int  c)
inlinevirtual

Gets a copy of one column of the the matrix.

Parameters
cThe (zero-based) column number to return.
Returns
An independent copy of the specificed column.

The returned vector is not linked to the matrix. If an entry in the matrix is updated after this method is called, the returned object will continue to represent a row of the original, not the updated, matrix. Similiarly, updates to the elements of the returned vector will not update the original matrix.

Reimplemented from Meta.Numerics.Matrices.AnyRectangularMatrix.

Referenced by Test.SquareMatrixTest.SquareMatrixAccess().

SquareMatrix Meta.Numerics.Matrices.SquareMatrix.Inverse ( )
inline

Computes the inverse of the matrix.

Returns
The matrix inverse M-1.

The inverse of a matrix M is a matrix M-1 such that M-1M = I, whhere I is the identity matrix.

If the matrix is singular, inversion is not possible. In that case, this method will fail with a DivideByZeroException.

The inversion of a matrix is an O(N3) operation.

Exceptions
DivideByZeroExceptionThe matrix is singular.

References Meta.Numerics.Matrices.SquareMatrix.Copy().

Referenced by Test.BugTests.Bug7208(), Meta.Numerics.Matrices.SymmetricMatrix.Inverse(), Test.SquareMatrixTest.SquareRandomMatrixInverse(), and Test.SquareMatrixTest.SquareVandermondeMatrixInverse().

LUDecomposition Meta.Numerics.Matrices.SquareMatrix.LUDecomposition ( )
inline

Computes the LU decomposition of the matrix.

Returns
The LU decomposition of the matrix.

The LU decomposition of a matrix M is a set of matrices L, U, and P such that LU = PM, where L is lower-left triangular, U is upper-right triangular, and P is a permutation matrix (so that PM is a row-wise permutation of M).

The LU decomposition of a square matrix is an O(N3) operation.

Referenced by Meta.Numerics.Analysis.FunctionMath.FindZero(), Test.SparseSquareMatrixTest.SparseSquareMatrixSolutionAgreement(), Test.SquareMatrixTest.SquareRandomMatrixLUDecomposition(), Test.SquareMatrixTest.SquareUnitMatrixLUDecomposition(), and Test.SquareMatrixTest.SquareVandermondeMatrixLUDecomposition().

Complex [] Meta.Numerics.Matrices.SquareMatrix.Eigenvalues ( )
inline

Computes the eigenvalues of the matrix.

Returns
The eigenvalues of the matrix.
See also
Eigensystem

Referenced by Test.BugTests.Bug5504(), Test.BugTests.DifficultEigenvalue(), Test.SquareMatrixTest.KnownEigenvalues(), and Test.SquareMatrixTest.TimedEigenvalues().

ComplexEigensystem Meta.Numerics.Matrices.SquareMatrix.Eigensystem ( )
inline

Computes the eigenvalues and eigenvectors of the matrix.

Returns
A representation of the eigenvalues and eigenvectors of the matrix.

For a generic vector v and matrix M, Mv = u will point in some direction with no particular relationship to v. The eigenvectors of a matrix M are vectors z that satisfy Mz = &#x3BB;z, i.e. multiplying an eigenvector by a matrix reproduces the same vector, up to a prortionality constant &#x3BB; called the eigenvalue.

For v to be an eigenvector of M with eigenvalue &#x3BB;, (M - &#x3BB;I)z = 0. But for a matrix to anihilate any non-zero vector, that matrix must have determinant, so det(M - &#x3BB;I)=0. For a matrix of order N, this is an equation for the roots of a polynomial of order N. Since an order-N polynomial always has exactly N roots, an order-N matrix always has exactly N eigenvalues.

Since a polynomial with real coefficients can still have complex roots, a real square matrix can nonetheless have complex eigenvalues (and correspondly complex eigenvectors). However, again like the complex roots of a real polynomial, such eigenvalues will always occurs in complex-conjugate pairs.

Although the eigenvalue polynomial ensures that an order-N matrix has N eigenvalues, it can occur that there are not N corresponding independent eigenvectors. A matrix with fewer eigenvectors than eigenvalues is called defective. Like singularity, defectiveness represents a delecate balance between the elements of a matrix that can typically be disturbed by just an infinitesimal perturbation of elements. Because of round-off-error, then, floating-point algorithms cannot reliably identify defective matrices. Instead, this method will return a full set of eigenvectors, but some eigenvectors, corresponding to very nearly equal eigenvalues, will be very nearly parallel.

While a generic square matrix can be defective, many subspecies of square matrices are guaranteed not to be. This includes Markov matrices, orthogonal matrices, and symmetric matrices.

Determining the eigenvalues and eigenvectors of a matrix is an O(N3) operation. If you need only the eigenvalues of a matrix, the Eigenvalues method is more efficient.

References Meta.Numerics.Complex.Re.

Referenced by Test.BugTests.Bug7208(), Test.SquareMatrixTest.CompanionMatrixEigenvalues(), Test.SquareMatrixTest.DegenerateEigenvalues(), FutureTest.FutureTest.ET(), Test.SquareMatrixTest.SquareMatrixDifficultEigensystem(), Test.SquareMatrixTest.SquareMatrixStochasticEigensystem(), Test.SquareMatrixTest.SquareRandomMatrixEigenvalues(), Test.SquareMatrixTest.SquareUnitMatrixEigensystem(), and Test.SquareMatrixTest.SquareVandermondeMatrixEigenvalues().

SingularValueDecomposition Meta.Numerics.Matrices.SquareMatrix.SingularValueDecomposition ( )
inline

Computes the singular value decomposition of the square matrix.

Returns
The singular value decomposition of the matrix.

Singular value decomposition is an advanced matrix decomposition technique that can be applied to all matrices, including non-square and singular square matrices.

References Meta.Numerics.Matrices.RectangularMatrix.SingularValueDecomposition().

Referenced by Test.BugTests.Bug7685(), Test.SquareMatrixTest.HilbertMatrixSVD(), and Test.RectangularMatrixTest.SmallSVD().

SquareQRDecomposition Meta.Numerics.Matrices.SquareMatrix.QRDecomposition ( )
inline

Computes a QR decomposition of the matrix.

Returns
A QR decomposition of the matrix.

Referenced by Test.SquareMatrixTest.SquareRandomMatrixQRDecomposition().

SquareMatrix Meta.Numerics.Matrices.SquareMatrix.Power ( int  n)
inline

Computes the matrix raised to the given power.

Parameters
nThe power to which to raise the matrix, which must be positive.
Returns
The matrix An.

Referenced by Test.SquareMatrixTest.MatrixPeriodTest().

static SquareMatrix Meta.Numerics.Matrices.SquareMatrix.operator+ ( SquareMatrix  A,
SquareMatrix  B 
)
inlinestatic

Adds two real, square matrices.

Parameters
AThe first matrix.
BThe second matrix.
Returns
The sum matrix A + B .
Exceptions
ArgumentNullExceptionA or B is null.
DimensionMismatchExceptionThe dimension of A is not the same as the dimension of B .

References Meta.Numerics.Matrices.SquareMatrix.dimension, and Meta.Numerics.Matrices.SquareMatrix.store.

static SquareMatrix Meta.Numerics.Matrices.SquareMatrix.operator- ( SquareMatrix  A,
SquareMatrix  B 
)
inlinestatic

Computes the difference of two square matrices.

Parameters
AThe first matrix.
BThe second matrix.
Returns
The difference A - B .

Matrix subtraction is an O(N2) process.

Exceptions
ArgumentNullExceptionA or B is null.
DimensionMismatchExceptionThe dimension of A is not the same as the dimension of B .

References Meta.Numerics.Matrices.SquareMatrix.dimension, and Meta.Numerics.Matrices.SquareMatrix.store.

static SquareMatrix Meta.Numerics.Matrices.SquareMatrix.operator* ( SquareMatrix  A,
SquareMatrix  B 
)
inlinestatic

Computes the product of two square matrices.

Parameters
AThe first matrix.
BThe second matrix.
Returns
The product A * B .

Note that matrix multiplication is not commutative, i.e. M1*M2 is generally not the same as M2*M1.

Matrix multiplication is an O(N3) process.

Exceptions
ArgumentNullExceptionA or B is null.
DimensionMismatchExceptionThe dimension of A is not the same as the dimension of B .

References Meta.Numerics.Matrices.SquareMatrix.dimension, and Meta.Numerics.Matrices.SquareMatrix.store.

static ColumnVector Meta.Numerics.Matrices.SquareMatrix.operator* ( SquareMatrix  A,
ColumnVector  v 
)
inlinestatic

Computes the product of a square matrix and a column vector.

Parameters
AThe matrix.
vThe column vector.
Returns
The column vector Av.
Exceptions
ArgumentNullExceptionA or v is null.
DimensionMismatchExceptionThe dimension of A is not the same as the dimension of v .

References Meta.Numerics.Matrices.SquareMatrix.dimension, and Meta.Numerics.Matrices.SquareMatrix.store.

static SquareMatrix Meta.Numerics.Matrices.SquareMatrix.operator* ( double  alpha,
SquareMatrix  A 
)
inlinestatic

Multiply a real, square matrix by a real constant.

Parameters
alphaThe constant.
AThe matrix.
Returns
The product aA.

References Meta.Numerics.Matrices.SquareMatrix.dimension, and Meta.Numerics.Matrices.SquareMatrix.store.

static SquareMatrix Meta.Numerics.Matrices.SquareMatrix.operator* ( SquareMatrix  A,
double  alpha 
)
inlinestatic

Divides a real, square matrix by a real constant.

Parameters
AThe matrix.
alphaThe constant.
Returns
The quotient A/a.

References Meta.Numerics.Matrices.SquareMatrix.dimension, and Meta.Numerics.Matrices.SquareMatrix.store.

static SquareMatrix Meta.Numerics.Matrices.SquareMatrix.operator- ( SquareMatrix  A)
inlinestatic

Negates a real, square matrix.

Parameters
AThe matrix.
Returns
The matrix -A.
Exceptions
ArgumentNullExceptionA is null.

References Meta.Numerics.Matrices.SquareMatrix.dimension, and Meta.Numerics.Matrices.SquareMatrix.store.

Member Data Documentation

readonly double [] Meta.Numerics.Matrices.SquareMatrix.store
private

Property Documentation

override double Meta.Numerics.Matrices.SquareMatrix.this[int r, int c]
getset

Gets or sets an entry of the matrix.

Parameters
rThe (zero-based) row number.
cThe (zero-based) column number.
Returns
The value of the specified matrix entry Mr c.

The documentation for this class was generated from the following file: