如何避免 Mathematica 中矩阵本身乘以矩阵转置的奇异性

how to avoid singularity of multiplication of matrix transpose by the matrix itself in Mathematica

我在 Mathematica 中编写了下一个代码来获得矩阵转置乘以矩阵本身的逆:

A = RandomInteger[{1, 20}, {3, 51}];
B = A\[Transpose].A;
F = Inverse[B];
F // MatrixForm

它总是告诉我矩阵 (B) 是奇异的 - 尽管 (A) 是随机的,而矩阵与其转置相乘是可以的!!!!!!!!

A = RandomInteger[{1, 20}, {3, 51}];
O = A.A\[Transpose];
L = Inverse[O];;
L// MatrixForm

谁能向我解释为什么第一种情况给我奇异矩阵而第二种情况还可以?我该怎么做才能使第一个案例成为非单一案例?代码有问题吗?

brenderson 在这里给出了答案:B is positive semidefinite (PSD)

in order for B to be invertible, it must be that A is a narrow matrix (n ≤ m) with full column rank. In the case that A is a strictly wide matrix (m < n), there is no possibility for B to be invertible.

例如

A = RandomInteger[{1, 20}, {3, 4}];
B = Transpose[A].A;
{m, n} = Dimensions[A];
If[n <= m, "A is a narrow matrix", "A is a wide matrix"] <>
 If[Det[B] == 0, " ; B is singular", " ; B is invertible"]

A is a wide matrix ; B is singular

A = RandomInteger[{1, 20}, {4, 3}];
B = Transpose[A].A;
{m, n} = Dimensions[A];
If[n <= m, "A is a narrow matrix", "A is a wide matrix"] <>
 If[Det[B] == 0, " ; B is singular", " ; B is invertible"]

A is a narrow matrix ; B is invertible