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

    Function qrSolve

    • Solves a x = b in the least-squares sense using a QR decomposition. Equivalent to R's qr.solve().

      Throws if the rank is less than min(nrow, ncol). When b is omitted, returns the inverse of a (square matrices only). For a wide matrix, coefficients of unused columns are set to 0 (as in R).

      A LAPACK decomposition (qr(a, { lapack: true })) has no rank, so it throws instead if some |R[k][k]| is at most tol * |R[0][0]| (tol from options, default 1e-7), which R's qr.solve() does not detect.

      Parameters

      • a: MatrixInput | QR

        A matrix (array of rows) or a QR decomposition from qr.

      • Optionalb: VectorOrMatrix

        The right-hand side, a vector or a matrix. Default: the identity matrix.

      • options: { tol?: number } = {}

        tol: the tolerance passed to qr when a is a matrix. Default: 1e-7.

      Returns number[] | number[][]

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

      qrSolve([[2, 1], [1, 3]], [3, 5]); // [0.8, 1.4]
      qrSolve([[1, 1], [1, 2], [1, 3]], [1, 2, 4]); // [-0.6667, 1.5]