diff --git a/types/index.d.ts b/types/index.d.ts index afc5c128b..150571729 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -1898,6 +1898,13 @@ declare namespace math { // eslint-disable-next-line @typescript-eslint/no-explicit-any ): any + /** + * Calculate the Moore–Penrose inverse of a matrix. + * @param x Matrix to be inversed + * @return The inverse of `x`. + */ + pinv(x: T): T + /** * Create an array from a range. By default, the range end is excluded. * This can be customized by providing an extra parameter includeEnd. diff --git a/types/index.ts b/types/index.ts index 541588147..451e35a2c 100644 --- a/types/index.ts +++ b/types/index.ts @@ -1293,6 +1293,37 @@ Matrices examples ) ) } + + // Moore–Penrose inverse + { + assert.ok( + math.deepEqual( + math.pinv([ + [1, 2], + [3, 4], + ]), + [ + [-2, 1], + [1.5, -0.5], + ] + ) + ) + assert.ok( + math.deepEqual( + math.pinv( + math.matrix([ + [1, 2], + [3, 4], + ]) + ), + math.matrix([ + [-2, 1], + [1.5, -0.5], + ]) + ) + ) + assert.ok(math.deepEqual(math.pinv(4), 0.25)) + } } /*