This library provides functions for linear algebra transformations
This is very much still a work in progress, the functionality here has only been tested with a few sample cases.
Status | Name |
---|---|
Filter.SavitzkyGolayParameters
(
Vector ↑v,
Number ↓fm,
Matrix ↓dim,
Number ↓dn,
Vector ↓w,
Vector ↑v
)
Computes the coefficients for a Savitzky Golay filter given the parameters |
|
Matrix Matrix.copyMatrix
(
Matrix ↓A,
Number ↓m,
Number ↓n,
Matrix ↑B
)
Copies the contents of a m x n matrix A into another matrix B. |
|
Number Matrix.determinant
(
Matrix ↓A,
Number ↓am
)
Computes the determinant of square matrix A, using LU decomposition |
|
Matrix Matrix.fillMatrix
(
Matrix ⇅A,
Number ↓m,
Number ↓n,
Number ↓val
)
Given a m x n matrix A, fills all elements of the matrix with the specified value. This is a convenience method to initialise a matrix (e.g. fill with 0). |
|
Matrix Matrix.identityMatrix
(
Number ↓m,
Matrix ↑mat
)
Generates an identity matrix of size m x m. |
|
Boolean Matrix.inverse
(
Matrix ↓A,
Number ↓am,
Matrix ↑inverse
)
Computes the inverse of square matrix A. |
|
Boolean Matrix.isSymmetric
(
Matrix ↓A,
Number ↓m
)
Given a m x m square matrix A, returns whether it is symmetrical, within tolerance |
|
Matrix Matrix.multiplyMatrix
(
Matrix ↓A,
Number ↓am,
Number ↓an,
Matrix ↓B,
Number ↓bm,
Number ↓bn,
Matrix ↑C
)
Multiplies matrices A and B to output C. |
|
Matrix Matrix.transposeMatrix
(
Matrix ↓A,
Number ↓m,
Number ↓n,
Matrix ↑AT
)
Given a m x n matrix A, returns the transpose, n x m matrix A T. |
|
Solver.cholSolve
(
Matrix ↓A,
Number ↓am,
Matrix ↓B,
Number ↓bm,
Number ↓bn,
Matrix ↑X
)
For the symmetric positive definite matrix A, and matrices X and B, where AX = B, solve for X given A and B, using Cholesky Decomposition. |
|
Boolean Solver.luSolve
(
Matrix ↓A,
Number ↓am,
Matrix ↓B,
Number ↓bm,
Number ↓bn,
Matrix ↑X
)
For the square matrix A, and matrices X and B, where AX = B, solve for X given A and B, using LU Decomposition |
|
Boolean Solver.qrSolve
(
Matrix ↓A,
Number ↓am,
Number ↓an,
Matrix ↓B,
Number ↓bm,
Number ↓bn,
Matrix ↑X,
Number ↓threshold
)
For the matrices A, X and B, where AX = B, solve for X given A and B, using QR Decomposition |
|
Solver.svdSolve
(
Matrix ↓A,
Number ↓am,
Number ↓an,
Matrix ↓B,
Number ↓bm,
Number ↓bn,
Matrix ↑X
)
For the matrix A, X and B, where AX = B, solve for X given A and B, using Singular Value Decomposition |
|
Matrix Transformation.ATA
(
Matrix ↓A,
Number ↓m,
Number ↓n,
Matrix ↑ATA
)
Given a m × n matrix A, computes and returns the n × n matrix, A T × A. |
|
Transformation.chol
(
Matrix ↓A,
Number ↓m,
Matrix ↑L,
Matrix ↑LT,
Number ↓relativeSymmetryThreshold,
Number ↓absolutePositivityThreshold,
Object ↑details
)
Calculates the Cholesky decomposition of a matrix.
|
|
Transformation.eigen
(
Matrix ↓A,
Number ↓m,
Array ↑realEigenValues,
Array ↑imagEigenValues,
Matrix ↑eigenVectors
)
Transforms the matrix A of size m × m to derive its eigenvalues and eigenvectors. |
|
Transformation.hessenberg
(
Matrix ↓A,
Number ↓m,
Matrix ↑P,
Matrix ↑H
)
Transforms the matrix A of size m × m to its Hessenberg form.
|
|
Boolean Transformation.lu
(
Matrix ↓A,
Number ↓m,
Matrix ↑L,
Matrix ↑U,
Matrix ↑P,
Array ↑pivot,
Matrix ↑LU,
Object ↑details
)
Calculates the LUP-decomposition of a square matrix.
|
|
Boolean Transformation.qr
(
Matrix ↓A,
Number ↓m,
Number ↓n,
Matrix ↑Q,
Matrix ↑R,
Matrix ↑H,
Matrix ↑QT,
Number ↓threshold
)
Calculates the QR-decomposition of a matrix.
|
|
Transformation.schur
(
Matrix ↓A,
Number ↓m,
Matrix ↑P,
Matrix ↑T
)
Transforms the matrix A of size m × m to its Schur form.
|
|
Transformation.svd
(
Matrix ↓A,
Number ↓m,
Number ↓n,
Matrix ↑U,
Matrix ↑V,
Array ↑singularValues,
Array ↑S,
Object ↑details
)
Calculates the compact Singular Value Decomposition of a matrix.
|
|
Matrix Transformation.svdPseudoInverse
(
Number ↓m,
Number ↓n,
Array ↓singularValues,
Matrix ↓U,
Matrix ↓V,
Number ↓tol,
Matrix ↑inv
)
Calculates the pseudoinverse of a m × n matrix A based on the output of its SVD transformation. |
|
Transformation.symmetricEigen
(
Matrix ↓A,
Number ↓m,
Array ↑realEigenValues,
Array ↑imagEigenValues,
Matrix ↑eigenVectors
)
Transforms the symmetric matrix A of size m × m to derive its eigenvalues and eigenvectors. |
|
Transformation.tridiagonal
(
Matrix ↓A,
Number ↓m,
Matrix ↑P,
Matrix ↑T,
Array ↑main,
Array ↑secondary
)
Transforms the symmetric matrix A of size m × m to a tridiagonal form.
|
Methods for matrix filters
Computes the coefficients for a Savitzky Golay filter given the parameters
Parameters:Vector
↑v - - output vector v, which is a vector sized frame size.Number
↓fm - - frame size - must be a positive odd integer.Matrix
↓dim - - order of polynomial for filter. Must be less than frame size - 1.Number
↓dn - - derivative to compute. 0 = smoothing only. Must be less than or equal to order of polynomial.Vector
↓w - - optional, weighting vector. If provided, must be sized frame size.Vector
↑v - - output vector v, which is a vector sized frame size.Methods for working with matrices The matrices in this library are represented by an array, with the elements of the matrix within the array in row-major format, e.g.:
[ 1 2 3 4 5 6 7 8 9 ]
Copies the contents of a m x n matrix A into another matrix B.
Parameters:Matrix
↓A - - input matrix A to transposeNumber
↓m - - row dimension of input matrix A.Number
↓n - - col dimension of input matrix A.Matrix
↑B - - output matrix B. Optional - if not provided a new array will be created and returned.Matrix
↑B - - output matrixGiven a m x n matrix A, fills all elements of the matrix with the specified value. This is a convenience method to initialise a matrix (e.g. fill with 0).
Parameters:Matrix
⇅A - - input matrix A to fillNumber
↓m - - row dimension of input matrix A.Number
↓n - - col dimension of input matrix A.Number
↓val - - value to fill input matrix A.Matrix
⇅A - - filled matrix AGenerates an identity matrix of size m x m.
Parameters:Number
↓m - - row/col dimension of identity matrix to generate.Matrix
↑mat - - identity matrix to generate. Optional - if not specified, a new array will be created and returned.Matrix
↑mat - - identity matrix to generate.Computes the inverse of square matrix A.
Parameters:Matrix
↓A - - input matrix A to compute inverseNumber
↓am - - row/col dimension of input matrix A.Matrix
↑inverse - - output matrix inverse of A.Boolean
↑solved - - true if solution is valid. false if solution not valid (i.e. A is singular).Multiplies matrices A and B to output C.
Parameters:Matrix
↓A - - input matrix A to multiplyNumber
↓am - - row dimension of input matrix A.Number
↓an - - col dimension of input matrix A.Matrix
↓B - - input matrix B to multiplyNumber
↓bm - - row dimension of input matrix B.Number
↓bn - - col dimension of input matrix B.Matrix
↑C - - output matrix C. Optional - if not provided a new array will be created and returned. This is a am x bn matrix.Matrix
↑C - - output matrixGiven a m x n matrix A, returns the transpose, n x m matrix A T.
Parameters:Matrix
↓A - - input matrix A to transposeNumber
↓m - - row dimension of input matrix A.Number
↓n - - col dimension of input matrix A.Matrix
↑AT - - output matrix AT. Optional - if not provided a new array will be created and returned.Matrix
↑AT - - output matrixMethods for solving linear systems
For the symmetric positive definite matrix A, and matrices X and B, where AX = B, solve for X given A and B, using Cholesky Decomposition.
Parameters:For the square matrix A, and matrices X and B, where AX = B, solve for X given A and B, using LU Decomposition
Parameters:Matrix
↓A - - input matrix ANumber
↓am - - row/col dimension of input matrix A.Matrix
↓B - - input matrix BNumber
↓bm - - row dimension of input matrix B.Number
↓bn - - col dimension of input matrix B.Matrix
↑X - - output matrix X (same size as B).Boolean
↑solved - - returns true if solution is valid. Returns false if solution is not valid (i.e. A is singular).For the matrices A, X and B, where AX = B, solve for X given A and B, using QR Decomposition
Parameters:Matrix
↓A - - input matrix ANumber
↓am - - row dimension of input matrix A.Number
↓an - - col dimension of input matrix A.Matrix
↓B - - input matrix BNumber
↓bm - - row dimension of input matrix B.Number
↓bn - - col dimension of input matrix B.Matrix
↑X - - output matrix X (same size as B).Number
↓threshold - - singularity threshold. Optional - defaults to zero if not specified.Boolean
↑solved - - returns true if solution is valid. Returns false if solution is not valid (i.e. A is singular).For the matrix A, X and B, where AX = B, solve for X given A and B, using Singular Value Decomposition
Parameters:Methods for working with transformations
Given a m × n matrix A, computes and returns the n × n matrix, A T × A.
Parameters:Matrix
↓A - - input matrix A.Number
↓m - - row dimension of input matrix A.Number
↓n - - col dimension of input matrix A.Matrix
↑ATA - - output matrix. This is a n × n matrix. Specifying an output array is optional but recommended. If no output array is given, an array will be created and returned.Matrix
↑ATA - - the output array.Calculates the Cholesky decomposition of a matrix.
The Cholesky decomposition of a real symmetric positive-definite matrix A consists of a lower triangular matrix L with same size such that: A = LL
T. In a sense, this is the square root of A.
Matrix
↓A - - input matrix A.Number
↓m - - row/col dimension of input matrix A.Matrix
↑L - - output matrix L. L is a lower triangular, m × m matrix. Optional - this matrix is only computed if an output array is specified.Matrix
↑LT - - output matrix LT. LT is the transpose of L. Optional - this matrix is only computed if an output array is specified.Number
↓relativeSymmetryThreshold - - relative symmetry threshold. Optional - defaults to 1.0e-15 if not specified.Number
↓absolutePositivityThreshold - - positive definite threshold. Optional - defaults to 1.0e-10 if not specified.Object
↑details - - an output details object with the following element: determinant. Optional - this object is populated if it exists.Transforms the matrix A of size m × m to derive its eigenvalues and eigenvectors.
Parameters:Matrix
↓A - - input square matrixNumber
↓m - - row/col dimension of input square matrix A.Array
↑realEigenValues - - output array of size m, containing the real components of the eigenvalues of AArray
↑imagEigenValues - - output array of size m, containing the imaginary components of the eigenvalues of AMatrix
↑eigenVectors - - output matrix, where the eigenvectors of A are the rows of this matrix. This is an matrix of size m x m.Transforms the matrix A of size m × m to its Hessenberg form.
The m × m matrix A can be written as the product of three matrices: A = P × H × P
T with P an orthogonal matrix and H a Hessenberg matrix. Both P and H are m × m matrices.
P is an orthogonal matrix, i.e. its inverse is also its transpose.
Matrix
↓A - - input square matrixNumber
↓m - - row/col dimension of input square matrix A.Matrix
↑P - - output matrixMatrix
↑H - - output matrixCalculates the LUP-decomposition of a square matrix.
The LUP-decomposition of a matrix A consists of three matrices L, U and P that satisfy: P×A = L×U. L is lower triangular (with unit diagonal terms), U is upper triangular and P is a permutation matrix. All matrices are m×m.
As shown by the presence of the P matrix, this decomposition is implemented using partial pivoting.
This function uses 1e-11 as the singularity threshold.
Matrix
↓A - - input matrix A.Number
↓m - - row/col dimension of input matrix A.Matrix
↑L - - output matrix L. L is a lower-triangular, m × m matrix. Optional - this matrix is only computed if an output array is specified.Matrix
↑U - - output matrix U. U is an upper-triangular matrix, m × m matrix. Optional - this matrix is only computed if an output array is specified.Matrix
↑P - - output matrix P - rows permutation matrix. This is a m × m matrix. P is a sparse matrix with exactly one element set to 1.0 in each row and each column, all other elements being set to 0.0. The positions of the 1 elements are given by the pivot permutation vector. Optional - this matrix is only computed if an output array is specified.Array
↑pivot - - output pivot permutation vector of size m. Optional - this vector is only returned if an output array is specified.Matrix
↑LU - - output matrix LU. This is a m × m matrix combining aspects of L and U. Optional - this matrix is only computed if an output array is specified.Object
↑details - - an output details object with the following elements: singular, even, determinant. Optional - this object is populated if it exists.Boolean
↑singular - - whether the specified matrix is singular or not.Calculates the QR-decomposition of a matrix.
The QR-decomposition of a matrix A consists of two matrices Q and R that satisfy: A = QR, Q is orthogonal (Q
TQ = I), and R is upper triangular. If A is m×n, Q is m×m and R m×n.
This function compute the decomposition using Householder reflectors.
Matrix
↓A - - input matrix A.Number
↓m - - row dimension of input matrix A.Number
↓n - - col dimension of input matrix A.Matrix
↑Q - - output matrix Q. Q is an orthogonal, m × m matrix. Optional - this matrix is only computed if an output array is specified.Matrix
↑R - - output matrix R. R is an upper-triangular matrix, m × n matrix. Optional - this matrix is only computed if an output array is specified.Matrix
↑H - - output matrix H - Householder reflector vectors. H is a lower trapezoidal matrix, m × n whose columns represent each successive Householder reflector vector. This matrix is used to compute Q. Optional - this matrix is only computed if an output array is specified.Matrix
↑QT - - output matrix QT. This is the transpose of Q. Optional - this matrix is only computed if an output array is specified.Number
↓threshold - - singularity threshold. Optional - defaults to zero if not specified.Boolean
↑singular - - whether the specified matrix is singular or not.Transforms the matrix A of size m × m to its Schur form.
The m × m matrix A can be written as the product of three matrices: A = P × T × P
T with P an orthogonal matrix and T an quasi-triangular matrix. Both P and T are m × m matrices.
P is an orthogonal matrix, i.e. its inverse is also its transpose.
Matrix
↓A - - input square matrixNumber
↓m - - row/col dimension of input square matrix A.Matrix
↑P - - output matrixMatrix
↑T - - output matrixCalculates the compact Singular Value Decomposition of a matrix.
The Singular Value Decomposition of matrix A is a set of three matrices: U, Σ and V such that A = U × Σ × V
T. Let A be a m × n matrix, then U is a m × p orthogonal matrix, Σ is a p × p diagonal matrix with positive or null elements, V is a p × n orthogonal matrix (hence V
T is also orthogonal) where p=min(m,n).
This implementation requires m > n. If that is not the case, instead pass in the transpose of A. The V and U matrices are swapped in this case.
Matrix
↓A - - input matrixNumber
↓m - - row dimension of input matrix A.Number
↓n - - col dimension of input matrix A. This implementation requires that m > n.Matrix
↑U - - output array UMatrix
↑V - - output array VArray
↑singularValues - - output singular values. They are ranked in descending order.Array
↑S - - optional. If supplied, the Σ matrix is returned (a matrix with the singular values as its main diagonal).Object
↑details - - optional. If supplied as a hash or array, the method populates two properties: 'rank' denoting rank of the matrix, and 'tol' denoting the tolerance of the output matrices.Calculates the pseudoinverse of a m × n matrix A based on the output of its SVD transformation.
Parameters:Number
↓m - - row dimension of input matrix A.Number
↓n - - col dimension of input matrix A.Array
↓singularValues - - singular values of A as returned by svd()Matrix
↓U - - matrix U as returned by svd()Matrix
↓V - - matrix V as returned by svd()Number
↓tol - - tolerance as returned by svd(). Set to 0 if the input does not come from svd().Matrix
↑inv - - output pseudo inverse of A. This is a n × m matrix. Specifying an output array is optional but recommended. If no output array is given, an array will be created and returned.Matrix
↑inv - - the output array.Transforms the symmetric matrix A of size m × m to derive its eigenvalues and eigenvectors.
Parameters:Matrix
↓A - - input square matrixNumber
↓m - - row/col dimension of input square matrix A.Array
↑realEigenValues - - output array of size m, containing the real components of the eigenvalues of AArray
↑imagEigenValues - - output array of size m, containing the imaginary components of the eigenvalues of A. A symmetric matrix A yields only real eigen values, so this should be an all-zero output.Matrix
↑eigenVectors - - output matrix, where the eigenvectors of A are the rows of this matrix. This is an matrix of size m x m.Transforms the symmetric matrix A of size m × m to a tridiagonal form.
The m × m matrix A can be written as the product of three matrices: A = Q × T × Q
T with Q an orthogonal matrix and T a symmetrical tridiagonal matrix. Both Q and T are m × m matrices.
Q is an orthogonal matrix, i.e. its inverse is also its transpose. The function assumes that A is symmetric, only the upper part of the matrix is accessed.
Matrix
↓A - - input square matrixNumber
↓m - - row/col dimension of input square matrix A.Matrix
↑P - - output matrixMatrix
↑T - - output matrixArray
↑main - - optional. output main diagonal of matrix T. This is an array of size m.Array
↑secondary - - optional. output secondary diagonal of matrix T. This is an array of size m - 1.