Matrix and Equation System Functions

Function Index

mtxBkSubst mtxChl mtxDiag mtxFwSubst mtxGauss mtxLSC mtxLSW mtxMlt mtxRand mtxRand2 mtxSeries mtxSVD mtxT

Matrix and Equation System Functions


mtxBkSubst(U, B)

Performs backsubstitution for a given upper triangular n × n U matrix and an n × l B matrix containing l vectors of right-hand values.

The mtxBkSubst function returns l column vectors that are—typically—solutions of the equation L·U·x = B.

Example:
=mtxBkSubst({1, 0.5, 0.3333333; 0, 0.28867507685978, 0.2886752500649; 0, 0, 0.07453530110679}, {0.58333; -0.25979035258533; -0.03740870232733}) returns {0.94965127674073; -0.39804764314169; -0.50189241569889}


mtxChl(A, B, [iterations], result)

Performs Cholesky decomposition of a given symmetric, positively determined n × n A matrix (xᵀ·A·x > 0 for each x ≠ 0). The mtxChl function can be used to:

  1. solve a linear equation set A·x = B, where A is an n × n matrix, x is an n-element column vector and B is an n × l matrix,
  2. find the upper triangular U matrix such that Uᵀ·U = A,
  3. find the inverse and determinant of A.

The A and B arguments specify the matrices used in the A·x = B equation. The B argument is used only when result = 1. If B has l columns (l > 1), the procedure will use each column as different right-hand values and it will return l solution (column) vectors.

The iterations argument specifies the number of additional improving iterations that should be performed when finding the x vector(s). The default value is 0.

The result argument specifies what should be returned:

If result = 1, the function returns l solution vectors of the A·x = B equation system.
If result = 2, the function returns an upper triangular n × n U matrix such that Uᵀ·U = A.
If result = 3, the function returns a transposed upper triangular n × n Uᵀ matrix such that Uᵀ·U = A.
If result = 4, the function returns the inverse of A.
If result = 5, the function returns the determinant of A.

Examples:
=mtxChl({1, 0.5, 0.3333333; 0.5, 0.3333333, 0.25; 0.33333333, 0.25, 0.2}, {0.58333; 0.21667; 0.11666}, 3, 1) returns {0.9496504220468; -0.3980425149853; -0.5018975438522}

=mtxChl({1, 0.5, 0.3333333; 0.5, 0.3333333, 0.25; 0.33333333, 0.25, 0.2},,,2) returns {1, 0.5, 0.3333333; 0, 0.28867507685978, 0.2886752500649; 0, 0, 0.07453530110679}


mtxDiag(n, x) / mtxDiag(n, A)

Creates and returns an n × n diagonal matrix.

The first version of the function uses the x value for all diagonal elements. The second version uses the subsequent elements of the A vector/matrix to set the diagonal elements in the returned matrix.

Examples:
=mtxDiag(3, 1) returns {1, 0, 0; 0, 1, 0; 0, 0, 1}

=mtxDiag(3, {1, 2, 3}) returns {1, 0, 0; 0, 2, 0; 0, 0, 3}


mtxFwSubst(L, B)

Performs forward substitution for a given lower triangular n × n L matrix and an n × l B matrix containing l vectors of right-hand values.

The mtxFwSubst function returns l (column) vectors.

Example:
=mtxFwSubst({1, 0, 0; 0.5, 0.28867507685978, 0; 0.3333333, 0.2886752500649, 0.07453530110679}, {0.58333; 0.21667; 0.11666}) returns {0.58333; -0.25979035258533; -0.03740870232733}


mtxGauss(A, B, [iterations], [scaling], result)

Performs Gauss transformation with partial pivoting, optional improving iterations and scaling. The mtxGauss function can be used to:

  1. solve a linear equation set A·x = B, where A is an n × n matrix, x is an n-row column vector and B is an n × l matrix,
  2. find the LU decomposition of A,
  3. find the inverse of A,
  4. obtain the determinant of A.

The A and B arguments specify the matrices used in the A·x = B equation. The B argument is used only when result = 1. If B has l columns (l > 1), the procedure will use each column as different right-hand values and it will return l solution vectors.

The iterations argument specifies the number of improving iterations that should be performed when finding the x vector(s). The default value is 0.

The scaling argument specifies whether the initial coefficients should be scaled (to minimize roundoff problems if the equations are not well balanced). If scaling = 1, mtxGauss will scale the coefficients. If scaling = 0, no scaling will be performed. The default value is 0.

The result argument specifies what should be returned:

If result = 1, the function solves A·x = B and returns l solution vectors, where l is the number of columns in B.
If result = 2, the function returns an n × n lower triangular matrix L such that L·U = A' where A' is a row-wise permutation of A.
If result = 3, the function returns an n × n upper triangular matrix U such that L·U = A' where A' is a row-wise permutation of A.
If result = 4, the function returns an n × n permutation matrix P such that P·A = A' where A' is obtained from A by exchanging rows in the partial pivoting procedure.
If result = 5, the function returns the inverse of A.
If result = 6, the function returns the determinant of A.

Initial equation system:
2·x1 − x2 + 3·x3 = 6
1·x1 + 3·x2 + x3 = 8
4·x1 + x2 + x3 = 2

Examples:
=mtxGauss({2, -1, 3; 1, 3, 1; 4, 1, 1}, {6; 8; 2},,,1) returns {-0.75; 1.875; 3.125}

=mtxGauss({2, -1, 3; 1, 3, 1; 4, 1, 1},,,,6) returns -32

=mtxGauss({2, -1, 3; 1, 3, 1; 4, 1, 1},,,,5) returns {-0.0625, -0.125, 0.3125; -0.09375, 0.3125, -0.03125; 0.34375, 0.1875, -0.21875}


mtxLSC(A, b, E, d, [minMaxRatio], result)

Solves a given over-determined equation set A·x ≈ b with constraints in the form of E·x = d, where E is an l × n matrix and l < n.

The A argument is an m × n matrix and the b argument is a column vector with m rows. The E argument is an l × n matrix and the d argument is a column vector with l rows.

The minMaxRatio argument specifies the minimum allowable ratio between the minimum and maximum singular value below which a given singular value will be treated as 0.

The result argument specifies what should be returned:

If result = 1, the function returns the n-row column vector x.
If result = 2, the function returns the rest value r such that (A·x − b)ᵀ·(A·x − b) = r.

If the SVD decomposition is not convergent, the #NUM! error value is returned.

Examples:
=mtxLSC({1, 2; 2, 3; 7, 1}, {1; 2; 3}, {1, 3}, {2},,1) returns {0.2; 0.6}

=mtxLSC({1, 2; 2, 3; 7, 1}, {1; 2; 3}, {1, 3}, {2},,2) returns 0.319512195121195


mtxLSW(A, b, G, [minMaxRatio], result)

Solves a given over-determined equation set A·x ≈ b with weights specified by the G matrix so that the minimized function has the form:

r = (A·x − b)ᵀ·G·(A·x − b) → min

The A argument is an m × n matrix and the b argument is a column vector with m rows.

The G argument is an n × n matrix with weights. If G = I, the function is an equivalent of mtxSVD.

The minMaxRatio argument specifies the minimum allowable ratio between the minimum and maximum singular value below which a given singular value will be treated as 0.

The result argument specifies what should be returned:

If result = 1, the function returns the n-row column vector x.
If result = 2, the function returns the rest value r such that (A·x − b)ᵀ·G·(A·x − b) = r.

If the SVD decomposition is not convergent, the #NUM! error value is returned.

Examples:
=mtxLSW({1, 2; 2, 3; 7, 1}, {1; 2; 3}, {1,0,0;0,1,0;0,0,1},,1) returns {0.37476459510358; 0.38418079096045}

=mtxLSW({1, 2; 2, 3; 7, 1}, {1; 2; 3}, {1, 0.5 , 0.2; 0.5, 1, 0.7; 0.2, 0.7, 1},,1) returns {0.38927943760984; 0.3585237258348}


mtxMlt(v1, v2, ...)

Multiplies the subsequent specified matrices. The number of rows in each next matrix and the number of columns in the previous result must be the same.

Example:
=mtxMlt({1;2;3}, {1, 2, 3}, {2; 2; 2}) returns {12; 24; 36}


mtxRand(n, [seed1], [seed2])

Generates a column vector (a one-column matrix) of n random floating point numbers from the range (0, 1). The function uses two combined MLCG generators to create a series of about 2.3×10¹⁸ numbers.

The n argument specifies the size of the returned vector.

The seed1 and seed2 arguments determine the starting numbers for the first and the second generator.

If both those values are omitted, the first call to mtxRand will always start from the same hard-coded values of seed1 and seed2 and subsequent calls will use the previously generated values, returning partial series occurring one after another.

If both seed1 and seed2 are specified, mtxRand will always be generating one and the same partial series.

To generate two or more independent partial series that do not occur one after another, specify a fixed seed1 value and skip the seed2 argument.

Example:
=mtxRand(4, 10000, 25000) returns {0.71261246808435; 0.28457538373252; 0.42105025462307; 0.93072516522912}


mtxRand2(n, [seed1], [seed2], [type], [v1], [v2])

Generates a column vector (a one-column matrix) of random floating point numbers for the specified distribution type.

The n argument specifies the size of the returned vector.

The seed1 and seed2 arguments determine the starting numbers for the first and the second MLCG generator.

If both those values are omitted, the first call to mtxRand2 will always start from the same hard-coded values of seed1 and seed2 and subsequent calls will use the previously generated values, returning partial series occurring one after another.

If both seed1 and seed2 are specified, mtxRand2 will always be generating one and the same partial series.

To generate two or more independent partial series that do not occur one after another, specify a fixed seed1 value and skip the seed2 argument.

The type argument specifies the distribution type:

0 – uniform (0, 1)
1 – normal with the v1 mean and the v2 standard deviation
2 – exponential with the v1 mean
3 – Poisson with the v1 mean
4 – Bernoulli with the v1 probability
5 – geometric with the v1 probability

If type is omitted, it's assumed to be 0.

If a given distribution type doesn't require the v1 and/or v2 arguments, they should be omitted.

Example:
=mtxRand2(4, 10000, 25000,,,) returns {0.71261246808435; 0.28457538373252; 0.42105025462307; 0.93072516522912}


mtxSeries(n, x, [step])

Generates a column vector (a one-column matrix) of n subsequent numbers or generic date/time strings.

The x argument specifies the first element of the series. This can be a number or date/time string.

The step argument specifies the value by which the subsequent numbers/dates are incremented. If it's omitted, it's assumed to be 1 for numeric series and "P1D" (one day) for date series.

The general form of the date/time period is:
[+|-]PnYnMnDTnHnMnS.nnn

Examples:
P1Y2M10DT11H5M4S.355 represents a period of 1 year, 2 months, 10 days, 11 hours, 5 minutes, 4 seconds, 355 thousandths.
PT12H7M represents a period of twelve hours and seven minutes.

Examples:
=mtxSeries(5, 1, 0.1) returns {1; 1.1; 1.2; 1.3; 1.4}

=mtxSeries(5, "2005-12-01", "P1D") returns {"2005-12-01"; "2005-12-02"; "2005-12-03"; "2005-12-04"; "2005-12-05"}

=mtxSeries(5, "12:50:00", "PT2M") returns {"12:50:00"; "12:50:02"; "12:50:04"; "12:50:06"; "12:50:08"}


mtxSVD(A, B, [minMaxRatio], result)

Performs SVD decomposition of a given matrix A[m,n]. The mtxSVD function can be used to:

  1. solve an over-determined equation system A·x ≈ B where B is an m × l matrix containing l right-hand values vectors,
  2. find the number of non-zero singular values,
  3. find l rest values r[i] such that (A·x − Bᵢ)ᵀ·(A·x − Bᵢ) = r[i] where Bᵢ is the i-th column of B,
  4. find the (pseudo-)inverse A⁺ of A,
  5. find the U[m,n] matrix, S[m,n] matrix and V[n,n] matrix such that U·S·Vᵀ = A.

The A and B arguments are matrices used in the equation system A·x ≈ B. The B argument is ignored for result values other than 1 or 3.

The minMaxRatio argument specifies the minimum allowable ratio between the minimum and maximum singular value below which a given singular value will be treated as 0. The default value (and the smallest possible value) is 1.0e−15.

The result argument specifies what should be returned:

If result = 1, the function returns l n-row column vectors that are solutions of A·x ≈ B.
If result = 2, the function returns a column vector of l rest values.
If result = 3, the function returns the number of non-zero singular values.
If result = 4, the function returns the inverse A⁺ of A.
If result = 5, 6 or 7, the function returns respectively the U, S and V matrices described above.

If the SVD decomposition is not convergent, the #NUM! error value is returned.

Examples:
=mtxSVD({1, 2; 2, 3; 7, 1}, {1; 2; 3},,1) returns {0.37476459510358; 0.38418079096045}

=mtxSVD({1, 2; 2, 3; 7, 1}, {1; 2; 3},,3) returns 0.030131826742

=mtxSVD({1, 2; 2, 3; 7, 1},,,6) returns {7.68114574786861, 0; 0, 3; 0, 0}


mtxT(A)

Transposes a given matrix and returns the result.

Example:
=mtxT({1, 2, 3; 4, 5, 6}) returns {1, 4; 2, 5; 3, 6}