mirror of
https://github.com/josdejong/mathjs.git
synced 2026-01-25 15:07:57 +00:00
fix(pinv): write a typescript definition and test (#2804)
* fix(pinv): write a typescript definition * fix(pinv): write a typescript test * fix(pinv): format types/index.ts * fix(pinv): format types/index.ts * fix(pinv): format types/index.d.ts * fix(pinv): format types/index.ts Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
This commit is contained in:
parent
5754478f16
commit
822ea2a1c7
7
types/index.d.ts
vendored
7
types/index.d.ts
vendored
@ -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<T extends MathType>(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.
|
||||
|
||||
@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user