rStats.js v1.3.0
    Preparing search index...

    Function solve

    • Inverse of a square matrix. Equivalent to R's solve(a).

      Uses an LU decomposition with partial pivoting. Throws if the matrix is exactly singular or if its estimated reciprocal condition number is below tol (the check is skipped for matrices with NaN or infinite values).

      Parameters

      Returns number[][]

      The inverse of a as an array of rows.

      solve([[2, 1], [1, 3]]); // [[0.6, -0.2], [-0.2, 0.4]]
      
    • Solves the linear system a x = b for a vector b, as R's solve(a, b).

      Throws if a is exactly singular or its estimated reciprocal condition number is below tol.

      Parameters

      • a: MatrixInput

        A square matrix (array of rows).

      • b: readonly number[] | Float64Array<ArrayBufferLike>

        The right-hand side vector, with as many elements as a has rows.

      • Optionaloptions: SolveOptions

      Returns number[]

      The solution x as a vector.

      solve([[2, 1], [1, 3]], [3, 5]); // [0.8, 1.4]
      
    • Solves the linear system a x = b for a matrix b.

      Parameters

      Returns number[][]

      The solution x as an array of rows.

    • Solves the linear system a x = b, or inverts a when b is omitted.

      Parameters

      Returns number[] | number[][]

      A vector if b is a vector, otherwise an array of rows.