概述
我在使用numpy 1.3.0和MATLAB 7.9.0时遇到以下问题:
python代码import numpy as np
Lu = [[1.01250000000000,-0.00250000000000000,0,0,-0.00250000000000000,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[-0.00250000000000000,1.01250000000000,-0.00250000000000000,0,0,-0.00250000000000000,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,-0.00250000000000000,1.01250000000000,-0.00250000000000000,0,0,-0.00250000000000000,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,-0.00250000000000000,1.01250000000000,0,0,0,-0.00250000000000000,0,0,0,0,0,0,0,0,0,0,0,0],[-0.00250000000000000,0,0,0,1.01000000000000,-0.00250000000000000,0,0,-0.00250000000000000,0,0,0,0,0,0,0,0,0,0,0],[0,-0.00250000000000000,0,0,-0.00250000000000000,1.01000000000000,-0.00250000000000000,0,0,-0.00250000000000000,0,0,0,0,0,0,0,0,0,0],[0,0,-0.00250000000000000,0,0,-0.00250000000000000,1.01000000000000,-0.00250000000000000,0,0,-0.00250000000000000,0,0,0,0,0,0,0,0,0],[0,0,0,-0.00250000000000000,0,0,-0.00250000000000000,1.01000000000000,0,0,0,-0.00250000000000000,0,0,0,0,0,0,0,0],[0,0,0,0,-0.00250000000000000,0,0,0,1.01000000000000,-0.00250000000000000,0,0,-0.00250000000000000,0,0,0,0,0,0,0],[0,0,0,0,0,-0.00250000000000000,0,0,-0.00250000000000000,1.01000000000000,-0.00250000000000000,0,0,-0.00250000000000000,0,0,0,0,0,0],[0,0,0,0,0,0,-0.00250000000000000,0,0,-0.00250000000000000,1.01000000000000,-0.00250000000000000,0,0,-0.00250000000000000,0,0,0,0,0],[0,0,0,0,0,0,0,-0.00250000000000000,0,0,-0.00250000000000000,1.01000000000000,0,0,0,-0.00250000000000000,0,0,0,0],[0,0,0,0,0,0,0,0,-0.00250000000000000,0,0,0,1.01000000000000,-0.00250000000000000,0,0,-0.00250000000000000,0,0,0],[0,0,0,0,0,0,0,0,0,-0.00250000000000000,0,0,-0.00250000000000000,1.01000000000000,-0.00250000000000000,0,0,-0.00250000000000000,0,0],[0,0,0,0,0,0,0,0,0,0,-0.00250000000000000,0,0,-0.00250000000000000,1.01000000000000,-0.00250000000000000,0,0,-0.00250000000000000,0],[0,0,0,0,0,0,0,0,0,0,0,-0.00250000000000000,0,0,-0.00250000000000000,1.01000000000000,0,0,0,-0.00250000000000000],[0,0,0,0,0,0,0,0,0,0,0,0,-0.00250000000000000,0,0,0,1.01250000000000,-0.00250000000000000,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,-0.00250000000000000,0,0,-0.00250000000000000,1.01250000000000,-0.00250000000000000,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,-0.00250000000000000,0,0,-0.00250000000000000,1.01250000000000,-0.00250000000000000],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-0.00250000000000000,0,0,-0.00250000000000000,1.01250000000000]]
rhs = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0.0050, 0.0050, 0.0050, 0.0050]
Lu = np.array(Lu)
rhs = np.array(rhs)
ans = np.linalg.solve(Lu,rhs)
print ans
产生输出
^{pr2}$
而在MATLAB中使用反斜杠会产生输出0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0050 0.0050 0.0050 0.0050
我没有发现任何其他的线性代数方程组,纽比和matlab产生不同的解。我目前在外地,因此无法检查不同版本的numpy(在另一台计算机上)是否会给出正确的结果。是np.linalg.求解用不正确的函数来解决这个系统(系统矩阵Lu稀疏)?这是我版本的numpy中的一个bug吗?我的代码有问题吗?在
谢谢!在
最后
以上就是高高音响为你收集整理的matlab打反斜杠,一个线性方程组,如matlab反斜杠和numpy.linalg.求解提出不同的解决方案...的全部内容,希望文章能够帮你解决matlab打反斜杠,一个线性方程组,如matlab反斜杠和numpy.linalg.求解提出不同的解决方案...所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复