IGLib
1.7.2
The IGLib base library EXTENDED - with other lilbraries and applications.
|
Represents a square matrix. More...
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.
| |
override double | InfinityNorm () |
Computes the ∞-norm of the matrix.
| |
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... | |
![]() | |
virtual double | Trace () |
Computes the trace of the square matrix. More... | |
![]() | |
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... | |
![]() | |
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 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 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... | |
![]() | |
abstract int | Dimension [get] |
Gets or sets the dimension of the square matrix. More... | |
override int | RowCount [get] |
override int | ColumnCount [get] |
![]() | |
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 | |
![]() | |
AnyRectangularMatrix () | |
![]() | |
AnyMatrix () | |
Represents a square matrix.
|
inline |
Initializes a new square matrix.
dimension | The dimension of the matrix, which must be positive. |
ArgumentOutOfRangeException | Thrown when dimension < 1. |
|
inline |
Initializes a new square matrix from the given 2D array.
entries | The source 2D array. |
ArgumentNullException | entries is null. |
DimensionMismatchException | The first and second dimensions of entries are not equal. |
|
inlinevirtual |
Computes the 1-norm of the matrix.
Reimplemented from Meta.Numerics.Matrices.AnyRectangularMatrix.
Referenced by Test.SquareMatrixTest.SquareMatrixNorms().
|
inlinevirtual |
Computes the ∞-norm of the matrix.
Reimplemented from Meta.Numerics.Matrices.AnyRectangularMatrix.
Referenced by Test.SquareMatrixTest.SquareMatrixNorms().
|
inlinevirtual |
Returns a vector representing a given row of the matrix.
r | The (zero-based) row number to return. |
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().
|
inlinevirtual |
Gets a copy of one column of the the matrix.
c | The (zero-based) column number to return. |
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().
|
inline |
Copies the matrix.
References Meta.Numerics.Matrices.SquareMatrix.Copy().
Referenced by Meta.Numerics.Matrices.SquareMatrix.Copy(), Meta.Numerics.Matrices.SquareQRDecomposition.Inverse(), Meta.Numerics.Matrices.SquareMatrix.Inverse(), and Test.SquareMatrixTest.SquareMatrixAccess().
|
inline |
Creates a transpose of the matrix.
References Meta.Numerics.Matrices.SquareMatrix.Transpose().
Referenced by FutureTest.FutureTest.EigenTest(), Test.SquareMatrixTest.HilbertMatrixSVD(), Meta.Numerics.Matrices.SingularValueDecomposition.LeftTransformMatrix(), Meta.Numerics.Matrices.SquareQRDecomposition.QMatrix(), Test.RectangularMatrixTest.RandomRectangularSVD(), Test.RectangularMatrixTest.RectangularQRDecomposition(), Test.RectangularMatrixTest.SmallSVD(), Test.SquareMatrixTest.SquareMatrixArithmetic(), Test.SymmetricMatrixTest.SymmetricRandomMatrixEigenvectors(), and Meta.Numerics.Matrices.SquareMatrix.Transpose().
|
inline |
Computes the inverse of the matrix.
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.
DivideByZeroException | The 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().
|
inline |
Computes 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().
|
inline |
Computes the eigenvalues of the matrix.
Referenced by Test.BugTests.Bug5504(), Test.BugTests.DifficultEigenvalue(), Test.SquareMatrixTest.KnownEigenvalues(), and Test.SquareMatrixTest.TimedEigenvalues().
|
inline |
Computes 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 = λz, i.e. multiplying an eigenvector by a matrix reproduces the same vector, up to a prortionality constant λ called the eigenvalue.
For v to be an eigenvector of M with eigenvalue λ, (M - λI)z = 0. But for a matrix to anihilate any non-zero vector, that matrix must have determinant, so det(M - λ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().
|
inline |
Computes the singular value decomposition of the square 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().
|
inline |
Computes a QR decomposition of the matrix.
Referenced by Test.SquareMatrixTest.SquareRandomMatrixQRDecomposition().
|
inline |
Computes the matrix raised to the given power.
n | The power to which to raise the matrix, which must be positive. |
Referenced by Test.SquareMatrixTest.MatrixPeriodTest().
|
inlinestatic |
Adds two real, square matrices.
A | The first matrix. |
B | The second matrix. |
ArgumentNullException | A or B is null. |
DimensionMismatchException | The dimension of A is not the same as the dimension of B . |
References Meta.Numerics.Matrices.SquareMatrix.dimension, and Meta.Numerics.Matrices.SquareMatrix.store.
|
inlinestatic |
Computes the difference of two square matrices.
A | The first matrix. |
B | The second matrix. |
Matrix subtraction is an O(N2) process.
ArgumentNullException | A or B is null. |
DimensionMismatchException | The dimension of A is not the same as the dimension of B . |
References Meta.Numerics.Matrices.SquareMatrix.dimension, and Meta.Numerics.Matrices.SquareMatrix.store.
|
inlinestatic |
Computes the product of two square matrices.
A | The first matrix. |
B | The second matrix. |
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.
ArgumentNullException | A or B is null. |
DimensionMismatchException | The dimension of A is not the same as the dimension of B . |
References Meta.Numerics.Matrices.SquareMatrix.dimension, and Meta.Numerics.Matrices.SquareMatrix.store.
|
inlinestatic |
Computes the product of a square matrix and a column vector.
A | The matrix. |
v | The column vector. |
ArgumentNullException | A or v is null. |
DimensionMismatchException | The dimension of A is not the same as the dimension of v . |
References Meta.Numerics.Matrices.SquareMatrix.dimension, and Meta.Numerics.Matrices.SquareMatrix.store.
|
inlinestatic |
Multiply a real, square matrix by a real constant.
alpha | The constant. |
A | The matrix. |
References Meta.Numerics.Matrices.SquareMatrix.dimension, and Meta.Numerics.Matrices.SquareMatrix.store.
|
inlinestatic |
Divides a real, square matrix by a real constant.
A | The matrix. |
alpha | The constant. |
References Meta.Numerics.Matrices.SquareMatrix.dimension, and Meta.Numerics.Matrices.SquareMatrix.store.
|
inlinestatic |
Negates a real, square matrix.
A | The matrix. |
ArgumentNullException | A is null. |
References Meta.Numerics.Matrices.SquareMatrix.dimension, and Meta.Numerics.Matrices.SquareMatrix.store.
|
private |
|
private |
|
get |
Gets the dimension of the matrix.
Referenced by Meta.Numerics.Matrices.AnySquareMatrix.operator*(), Meta.Numerics.Matrices.AnySquareMatrix.operator+(), Meta.Numerics.Matrices.AnySquareMatrix.operator-(), Test.RectangularMatrixTest.RandomRectangularSVD(), Test.RectangularMatrixTest.RectangularQRDecomposition(), Test.SquareMatrixTest.SquareMatrixAccess(), and Test.SquareMatrixTest.SquareRandomMatrixQRDecomposition().
|
getset |
Gets or sets an entry of the matrix.
r | The (zero-based) row number. |
c | The (zero-based) column number. |