MathMath

Help › Functions

Linear algebra

rank det norm1 norm2 norme normi cond1 cond2 conde condi eigenvals eigenvec eigenvecs cholesky lu qr svd svds geninv lsolve rref

rank(A) As in Mathcad

The rank of a matrix: how many of its rows are independent.

It is found by row reduction (see rref), counting the nonzero rows. Values near zero count as zero.

A≔(12​24​)
rank(A)=1

det(A) As in Mathcad

The determinant of a square matrix.

A determinant of 0 means the matrix has no inverse.

Units

The result has the matrix's units raised to the number of rows.

Refused

  • A matrix that is not square.
A≔(13​24​)
det(A)=−2

norm1(A) As in Mathcad

The L1 norm of a matrix: its largest column sum of absolute values.

See normi for the largest row sum, norm2 for the spectral norm and norme for the Euclidean norm.

A≔(13​24​)
norm1(A)=6

norm2(A) As in Mathcad

The L2 (spectral) norm of a matrix: its largest singular value.

See svds for all the singular values.

A≔(30​04​)
norm2(A)=4

norme(A) As in Mathcad

The Euclidean (Frobenius) norm of a matrix or vector: the square root of the sum of the squares of all its elements.

norme((34​))=5
norme((12​24​))=5

normi(A) As in Mathcad

The infinity norm of a matrix: its largest row sum of absolute values.

See norm1 for the largest column sum.

A≔(13​24​)
normi(A)=7

cond1(A) As in Mathcad

The condition number of a square matrix in the L1 norm: norm1(A)·norm1(A⁻¹).

A large number means that solving with the matrix magnifies errors. The smallest possible value is 1.

Refused

  • A matrix that is not square, or has no inverse.
A≔(20​01​)
cond1(A)=2

cond2(A) As in Mathcad

The condition number of a matrix in the L2 norm: the largest singular value over the smallest.

See cond1 for what the number means.

A≔(60​02​)
cond2(A)=3

conde(A) As in Mathcad

The condition number of a square matrix in the Euclidean norm: norme(A)·norme(A⁻¹).

See cond1 for what the number means.

Refused

  • A matrix that is not square, or has no inverse.
A≔(20​02​)
conde(A)=2

condi(A) As in Mathcad

The condition number of a square matrix in the infinity norm: normi(A)·normi(A⁻¹).

See cond1 for what the number means.

Refused

  • A matrix that is not square, or has no inverse.
A≔(20​01​)
condi(A)=2

eigenvals(A) As in Mathcad

A column vector of the eigenvalues of a square matrix.

The values can be complex, as for a rotation. eigenvecs gives the matching eigenvectors.

Refused

  • A matrix that is not square, or whose values fail to converge.
A≔(20​03​)
eigenvals(A)=(23​)

eigenvec(A, z) As in Mathcad

The unit-length eigenvector of A for the eigenvalue z.

z must be an eigenvalue of A, as eigenvals gives. A real vector comes back with its first nonzero element positive.

Refused

  • A value z that is not an eigenvalue of the matrix.
A≔(20​03​)
eigenvec(A,3)=(01​)

eigenvecs(A) As in Mathcad

A matrix whose columns are the unit-length eigenvectors of A, in the order eigenvals lists the values.

Each real vector is signed so its first nonzero element is negative, so a column can differ in sign from eigenvec. A repeated eigenvalue gets independent vectors.

Refused

  • A matrix that is not square, or whose vectors fail to converge.
A≔(20​03​)
eigenvecs(A)=(−10​0−1​)

cholesky(A) As in Mathcad

The lower-triangular matrix L with L·Lᵀ = A, for a symmetric positive definite A.

Only the lower triangle of A is read.

Refused

  • A matrix with units.
  • A matrix that is not square, or not positive definite.
A≔(42​25​)
L≔cholesky(A)
L=(21​02​)

lu(A) As in Mathcad

The LU decomposition of a square matrix: the matrices P, L and U side by side, with P·A = L·U.

P is a permutation matrix (rows swapped for stability), L is lower triangular with ones on its diagonal and U is upper triangular. They come back as one matrix three times as wide as A. Pick each out with submatrix.

Refused

  • A matrix with units.
  • A matrix that is not square.
A≔(42​25​)
lu(A)=(10​01​10.5​01​40​24​)

qr(A) As in Mathcad

The QR decomposition: the orthogonal Q and the upper-triangular R side by side, with A = Q·R.

For an m by n matrix, Q is m by m and R is m by n, joined into one m by (m+n) matrix. The diagonal of R is not negative. Pick each out with submatrix.

Refused

  • A matrix with units.
A≔(34​05​)
qr(A)=(0.60.8​−0.80.6​50​43​)

svd(A) As in Mathcad

The singular value decomposition of A: the matrices U and V stacked one above the other, with A = U·diag(s)·Vᵀ.

For an m by n matrix, U is m by n and V is n by n, so the result has m+n rows. The values s are in descending order and come from svds. Each column of U has a positive first nonzero element.

Refused

  • A matrix with fewer rows than columns.
A≔(30​02​)
svd(A)=⎝⎜⎜⎛​1010​0101​⎠⎟⎟⎞​

svds(A) As in Mathcad

A column vector of the singular values of A, largest first.

The largest is norm2 and the ratio of largest to smallest is cond2. svd gives the vectors too.

A≔(30​02​)
svds(A)=(32​)

geninv(A) As in Mathcad

The generalized (pseudo) inverse of A: the matrix that, multiplied on the left, gives the identity for a tall matrix of full column rank.

Useful for a least-squares fit, where geninv(A)·b is the best solution of A·x = b.

Units

The result has the matrix's units to the power −1.

Refused

  • A matrix with fewer rows than columns.
A≔⎝⎜⎜⎛​1111​⎠⎟⎟⎞​
b≔⎝⎜⎜⎛​1236​⎠⎟⎟⎞​
geninv(A)⋅b=3

lsolve(A, b) As in Mathcad

The vector x that solves the linear system A·x = b.

A must be square and b a column vector with as many rows. For an over-determined fit use geninv.

Units

The result has b's units divided by A's.

Refused

  • A matrix that is not square.
  • A b that is not a vector as long as the matrix.
  • A singular matrix.
A≔(21​13​)
b≔(510​)
lsolve(A,b)=(13​)

rref(A) As in Mathcad

The reduced row echelon form of A, found by Gauss-Jordan elimination.

Append the right-hand side with augment to solve a system by hand. rank counts the nonzero rows.

A≔(13​24​511​)
rref(A)=(10​01​12​)