求解具有不同根集的 python 中的线性系统

Solve linear system in python with different set of roots

我在使用这个线性系统时遇到问题

| a b c |   | x1 |   | 0 |
| d e f | x | x2 | = | 0 |
| g h i |   | x3 |   | 0 |

我需要解决 x1x2x3 但我使用的每个库都只给我 x1=x2=x3=0 作为解决方案它是正确的但系统接受其他解决方案。 我正在寻找避免零作为答案的解决方案。 感谢您的帮助。

如果我没记错的话我的矩阵代数:

M x N = 0

蕴含(如果 M 不是单数):

inv(M) x M x N = inv(M) x 0

所以 :

N = 0

正如我在评论中所说,如果 M 是单数,则有无穷多个解。没有算法可以给你全部。

这更像是一道数学题,而不是 python 题。

我的意思是你的通用公式是:

A(matrix) * x(vector) = b(vector)

所以你要做的是计算矩阵的逆并将它从左边相乘到两边:

Inv(A) * A *x = Inv(A) *b

现在 Inv(A)*A 为 1(对角线元素为 1 的矩阵)和 1(矩阵)*x = x,您就有了解决方案:

x = Inv(A)*b

现在有了 numpy.linalg.inv that let you compute the inverse if one exists (check the conditions for that) and numpy.dot which lets you multiply a matrix and a vector. And there are function that let you solve it in one step like: numpy.linalg.solve 这样的功能。但是,这是否有效取决于您要处理的值以及是否在数学上允许这些操作。同样出于明显的原因,如果将逆矩阵与 0,0,0 相乘,则结果向量将为零:

|a' b' c'|     |0|    |a'*0+b'*0+c'*0|    |0 + 0 + 0|   |0|
|d' e' f'|  *  |0| =  |d'*0+e'*0+f'*0| =  |0 + 0 + 0| = |0| 
|g' h' i'|     |0|    |g'*0+h'*0+i'*0|    |0 + 0 + 0|   |0|

其中 a' 等是逆矩阵的元素,无论它们最终会是什么。