Class MatrixExtensions
Utility methods for double-precision jagged-array matrix arithmetic, including LUP decomposition and inversion.
Inherited Members
Namespace: Unity.SimulationPro.Foundation
Assembly: Unity.SimulationPro.Foundation.dll
Syntax
public static class MatrixExtensions
Methods
HelperSolve(double[][], double[])
Solves the system LU·x = b using forward and backward substitution, given a pre-permuted right-hand side.
Declaration
public static double[] HelperSolve(double[][] luMatrix, double[] b)
Parameters
| Type | Name | Description |
|---|---|---|
| double[][] | luMatrix | The combined LU matrix produced by MatrixDecompose(double[][], out int[], out int). |
| double[] | b | The right-hand side vector, already permuted by the pivot ordering. |
Returns
| Type | Description |
|---|---|
| double[] | The solution vector |
Remarks
The caller is responsible for permuting b according to the perm array
produced by MatrixDecompose(double[][], out int[], out int) before calling this method.
MatrixCreate(int, int)
Allocates a new zero-initialized jagged matrix with the specified dimensions.
Declaration
public static double[][] MatrixCreate(int rows, int cols)
Parameters
| Type | Name | Description |
|---|---|---|
| int | rows | Number of rows. |
| int | cols | Number of columns. |
Returns
| Type | Description |
|---|---|
| double[][] | A new |
MatrixDecompose(double[][], out int[], out int)
Performs Doolittle LUP decomposition with partial pivoting on a square matrix.
Declaration
public static double[][] MatrixDecompose(double[][] matrix, out int[] perm, out int toggle)
Parameters
| Type | Name | Description |
|---|---|---|
| double[][] | matrix | The square matrix to decompose. |
| int[] | perm | Output row permutation array recording the pivot swaps applied. |
| int | toggle | Output parity of the permutation: |
Returns
| Type | Description |
|---|---|
| double[][] | The combined L (lower, with implicit 1s on the diagonal) and U (upper) matrix. |
Exceptions
| Type | Condition |
|---|---|
| Exception | Thrown if the matrix is not square or if Doolittle's method cannot be applied. |
MatrixDuplicate(double[][])
Creates a deep copy of a jagged matrix.
Declaration
public static double[][] MatrixDuplicate(double[][] matrix)
Parameters
| Type | Name | Description |
|---|---|---|
| double[][] | matrix | The source matrix to duplicate. |
Returns
| Type | Description |
|---|---|
| double[][] | A new jagged array with the same dimensions and values as |
MatrixInverse(double[][])
Computes the inverse of a square matrix using LUP decomposition.
Declaration
public static double[][] MatrixInverse(double[][] matrix)
Parameters
| Type | Name | Description |
|---|---|---|
| double[][] | matrix | The square matrix to invert. |
Returns
| Type | Description |
|---|---|
| double[][] | The inverse of |
Exceptions
| Type | Condition |
|---|---|
| Exception | Thrown if the matrix is singular or the decomposition fails. |