You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
const mat = /* same as above */;
//right-inverse recipe, works for matrices with linearly-independent rows:
const pinv = math.multiply(
math.transpose( mat ),
math.inv(
math.multiply(
mat,
math.transpose( mat )
)
)
);
console.table(math.multiply(mat, pinv));
Here, the output is very close to the identity matrix.
Results in an Error: Cannot calculate inverse, determinant is zero exception being thrown. (The right inverse recipe above still works on this matrix.)
My suspicion is that the pinv implementation here was only tested on matrices with linearly-independent columns (the rank-surplus case), not linearly-independent rows (the rank-deficient case). It's a useful tool in both situations so it would make sense to patch to deal with both.
The text was updated successfully, but these errors were encountered:
Thanks! This is a good addition to #3012. Having specific examples is very helpful. You don't happen to have an intuition as how we might find even smaller examples, do you?
Applies to mathjs 14.1.0, installed via npm.
May be related to #3012, but that bug does not provide a test case.
According to wikipedia's summary, the pseudo-inverse of a column-rank-deficient matrix
mat
exists, and acts as a right inversemat * pinv(mat) = I
.This does not appear to be the case when using
mathjs.pinv
on matricies with columns that are not linearly independent.In some cases, the returned matrix is not a right inverse:
The output here has its first column as all zeros -- quite far from the identity matrix (expected result).
In comparison, computing with wikipedia's summary of how to compute the pseudoinverse works just fine:
Here, the output is very close to the identity matrix.
Further,
pinv
just fails on some matrices:Results in an
Error: Cannot calculate inverse, determinant is zero
exception being thrown. (The right inverse recipe above still works on this matrix.)My suspicion is that the
pinv
implementation here was only tested on matrices with linearly-independent columns (the rank-surplus case), not linearly-independent rows (the rank-deficient case). It's a useful tool in both situations so it would make sense to patch to deal with both.The text was updated successfully, but these errors were encountered: