Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/355.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 带Numpy的矩阵解:没有解?_Python_Numpy - Fatal编程技术网

Python 带Numpy的矩阵解:没有解?

Python 带Numpy的矩阵解:没有解?,python,numpy,Python,Numpy,在Numpy中运行一个简单脚本,以解3个方程组: from numpy import * a = matrix('1 4 1; 4 13 7; 7 22 13') b = matrix('0;0;1') print linalg.solve(a,b) 但当我通过命令提示符运行它时,我不知怎么得到了: [[ 3.46430741e+15] [ -6.92861481e+14] [ -6.92861481e+14]] 虽然Wolfram Alpha说没有解决办法 有人知道为什么Numpy/

在Numpy中运行一个简单脚本,以解3个方程组:

from numpy import *
a = matrix('1 4 1; 4 13 7; 7 22 13')
b = matrix('0;0;1')
print linalg.solve(a,b)
但当我通过命令提示符运行它时,我不知怎么得到了:

[[  3.46430741e+15]
 [ -6.92861481e+14]
 [ -6.92861481e+14]]
虽然Wolfram Alpha说没有解决办法

有人知道为什么Numpy/WRA答案之间会有这样的差异吗?

如果你用笔和纸(或使用
Numpy.linalg.matrix\u rank
)计算系数和增广矩阵的秩,你会发现,根据,没有解决方案。所以Wolfram是对的

NumPy使用LU分解搜索方程的数值解。如果不深入讨论涉及除法的细节,FP算法中的除法可能会导致重大错误

如果您选择:

a = np.matrix('1 4 1; 4 13 7; 7 22 13')
b = np.matrix('0;0;1')

c = np.linalg.solve(a,b)
np.linalg.norm(a * c - b)
## 2.0039024427351748

你会发现NumPy的解决方案远非正确。

WRA到底是什么?@Josh
WRA==Wolfram Alpha
@KDawG-ah-gotcha。我想我从来没见过这个缩写词。最好将计算系统称为Mathematica(“WRA”背后的大脑)
第一个是Mathematica系统,它实现了Wolfram | Alpha的所有功能。