繁体   English   中英

SymPy 中的矩阵不一致

[英]Inconsistent matrices in SymPy

我正在计算 SymPy 中减少的梯形形式。 我正在尝试获取以下矩阵的枢轴列:

exercise4 = Matrix([[1,3,5,7],[3,5,7,9],[5,7,9,1]])

我用以下方法检查矩阵:

exercise4.rref()[0]

Matrix([
[1, 0, -1, 0],
[0, 1,  2, 0],
[0, 0,  0, 1]])

...顺便说一句,这与我的 NumPy 简化矩阵不同

exercise4 = np.array([[1,3,5,7],[3,5,7,9],[5,7,9,1]])
exercise4[1] = exercise4[1] + -3*exercise4[0]
exercise4[2] = exercise4[2] + -5*exercise4[0]
exercise4[1] = -1/4*exercise4[1]
exercise4[0] = exercise4[0] + -3*exercise4[1]
exercise4[2] = exercise4[2] + 8*exercise4[1]
exercise4

array([[  1,   0,  -1,  -2],
       [  0,   1,   2,   3],
       [  0,   0,   0, -10]])

rref()[1]此处返回(0, 1, 3) ,其中第三个元素显然不正确,因为它是增广矩阵的最后一个元素。 第三行不一致,应该没有第三个枢轴列。

这是sympy.Matrix().rref()的固有缺陷,它会错误地解释不一致的枢轴列吗? 这是我需要注意的事情,还是有办法解决这个问题?

在 [2,3] 上做你的枢轴会产生rref矩阵:

In [269]: M                                                                     
Out[269]: 
array([[  1.,   0.,  -1.,  -2.],
       [ -0.,   1.,   2.,   3.],
       [  0.,   0.,   0., -10.]])
In [271]: M[0]-=M[2]*(-2/-10)                                                                                                             
In [276]: M[1]-=M[2]*(3/-10)                                                    
In [278]: M[2]/= -10                                                                                                                    
In [281]: M                                                                     
Out[281]: 
array([[ 1.,  0., -1.,  0.],
       [ 0.,  1.,  2.,  0.],
       [-0., -0., -0.,  1.]])

当我将您的矩阵插入交互式表单时,我得到了sympy结果

http://www.math.odu.edu/~bogacki/cgi-bin/lat.cgi?c=rref

这里也是: https : //www.emathhelp.net/calculators/linear-algebra/reduced-row-echelon-form-rref-caclulator/

此版本减少了最后一行,因此所有前导项均为 1。但一个来源允许:

https://stattrek.com/statistics/dictionary.aspx?definition=reduced_row_echelon_form

注意:一些参考文献对行梯形图的描述略有不同。 它们不要求每行中的第一个非零条目等于 1。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM