English 中文(简体)
一种线性方程式系统,如肉类复力和 n。
原标题:A system of linear equations such that matlab backslash and numpy.linalg.solve produce different solutions

I have the following problem using numpy 1.3.0 and MATLAB 7.9.0: the python code

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

产出

[  1.87241716e-13   1.89545264e-13   1.89545264e-13   1.87241716e-13
   7.56433496e-11   7.63890449e-11   7.63890449e-11   7.56433496e-11
   3.04833369e-08   3.07089522e-08   3.07089522e-08   3.04833369e-08
   1.22844835e-05   1.23451480e-05   1.23451480e-05   1.22844835e-05
   4.95055571e-03   4.96277946e-03   4.96277946e-03   4.95055571e-03]

whereas using backslash in 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

我没有发现任何其他线性薄膜等系统,这种系统产生不同的解决办法。 目前,我已经离开城镇,因此无法检查,不同版本的 n(不同计算机)是否会产生正确的结果。 否。 是否解决利用这一系统的正确职能(系统矩阵L正在稀少)? 难道这是我版本的 n吗? 我的法典中是否有问题?

感谢!

最佳回答

Actually, those are likely the same solution. MATLAB is rounding to 0.0000 (when printing at least), while python is giving you much more detailed numbers (some problems might be from floating point rounding errors). The only numbers that are showing up as 0.0050 are the ones that are e-03. All of the other numbers are smaller than 0.0005, so it might get rounded to 0.0000.

问题回答

暂无回答




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签