docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class MatrixExtensions

    Utility methods for double-precision jagged-array matrix arithmetic, including LUP decomposition and inversion.

    Inheritance
    object
    MatrixExtensions
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    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 x.

    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 rows × cols jagged array initialized to zero.

    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: +1 for an even number of swaps, -1 for odd.

    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 matrix.

    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 matrix.

    Exceptions
    Type Condition
    Exception

    Thrown if the matrix is singular or the decomposition fails.

    In This Article
    Back to top
    Copyright © 2026 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)