![](https://secure.gravatar.com/avatar/ad4ab4eded6bcd5d60bacc446419a4fd.jpg?s=120&d=mm&r=g)
Dear scipy users, I am trying to invert a 12 by 12 complex matrix R using scipy.linalg.inv(), but the round-off errors seem a bit too big. If I do scipy.dot(Ri,R), the first row of the resulting matrix looks like this: array([ 0.953125 +0.j , 0.06542969+0.01171875j, 0.08154297+0.15234375j, -0.078125 -0.09375j , 0.19140625-0.0859375j , 0.08203125+0.140625j , -0.08398438+0.0078125j , -0.02539062-0.03125j , -0.06738281+0.015625j , -0.04736328+0.15820312j, -0.09057617+0.02832031j, 0.109375 -0.0625j ]) Is this normal? Inverting a 2x2 matrix produces the expected result. I've attached a pickle of my matrix. Thanks! ~ Roger
![](https://secure.gravatar.com/avatar/612395b66b3e7959997007b342b3688a.jpg?s=120&d=mm&r=g)
On Sat, 10 Nov 2007 14:16:06 +0800 "Roger Herikstad" <roger.herikstad@gmail.com> wrote:
Dear scipy users, I am trying to invert a 12 by 12 complex matrix R using scipy.linalg.inv(), but the round-off errors seem a bit too big. If I do scipy.dot(Ri,R), the first row of the resulting matrix looks like this:
array([ 0.953125 +0.j , 0.06542969+0.01171875j, 0.08154297+0.15234375j, -0.078125 -0.09375j , 0.19140625-0.0859375j , 0.08203125+0.140625j , -0.08398438+0.0078125j , -0.02539062-0.03125j , -0.06738281+0.015625j , -0.04736328+0.15820312j, -0.09057617+0.02832031j, 0.109375 -0.0625j ])
Is this normal? Inverting a 2x2 matrix produces the expected result. I've attached a pickle of my matrix. Thanks!
~ Roger
It depends on the condition number of your matrix. Did you compute the singular values of the matrix ? Please can you send me your test matrix in matrixmarket format off-list. io.mmwrite Nils
![](https://secure.gravatar.com/avatar/d1189ce0778ab7465ef33b4883250d01.jpg?s=120&d=mm&r=g)
Hi Roger, Your matrix is extremely singular. The singular values are:
U,d,V = linalg.svd(R) d array([1.41944451e+01, 1.23913727e+01, 9.46227279e+00, 2.81247753e-04, 1.11035378e-14, 1.02548448e-14, 8.22627497e-15, 6.74668324e-15, 5.51882714e-15, 4.78886237e-15, 2.82020737e-15, 7.14721524e-16])
Thus, the matrix is really il-conditioned (the ratio of the largest to smallest singular value is of the order of the machine precision. It is essentially singular, and only has 4 linearly independent columns). Thus, it is not surprising that the round-off errors are significant. You can't reasonably expect to invert a matrix when the ratio of the singular values is of order the machine precision. Michael. On 9 Nov 2007, at 10:16 PM, Roger Herikstad wrote:
Dear scipy users, I am trying to invert a 12 by 12 complex matrix R using scipy.linalg.inv(), but the round-off errors seem a bit too big. If I do scipy.dot(Ri,R), the first row of the resulting matrix looks like this:
array([ 0.953125 +0.j , 0.06542969+0.01171875j, 0.08154297+0.15234375j, -0.078125 -0.09375j , 0.19140625-0.0859375j , 0.08203125+0.140625j , -0.08398438+0.0078125j , -0.02539062-0.03125j , -0.06738281+0.015625j , -0.04736328+0.15820312j, -0.09057617+0.02832031j, 0.109375 -0.0625j ])
Is this normal? Inverting a 2x2 matrix produces the expected result. I've attached a pickle of my matrix. Thanks!
~ Roger <matrix.pck>
![](https://secure.gravatar.com/avatar/9820b5956634e5bbad7f4ed91a232822.jpg?s=120&d=mm&r=g)
Roger Herikstad wrote:
Dear scipy users, I am trying to invert a 12 by 12 complex matrix R using scipy.linalg.inv(), but the round-off errors seem a bit too big. If I do scipy.dot(Ri,R), the first row of the resulting matrix looks like this:
array([ 0.953125 +0.j , 0.06542969+0.01171875j, 0.08154297+0.15234375j, -0.078125 -0.09375j , 0.19140625-0.0859375j , 0.08203125+0.140625j , -0.08398438+0.0078125j , -0.02539062-0.03125j , -0.06738281+0.015625j , -0.04736328+0.15820312j, -0.09057617+0.02832031j, 0.109375 -0.0625j ])
Is this normal? Inverting a 2x2 matrix produces the expected result. I've attached a pickle of my matrix. Thanks! As a rule, you should not invert a matrix unless you *really* need it. For example, if you want X in A X = B, with A a matrix, B and X vectors, inverting A should be avoided. Some other methods are better suited (numerically speaking), depending on A and what you are trying to do.
The mathworks have good introduction on this topic, if you look for online help on inv, pinv and so on: http://www.mathworks.com/access/helpdesk/help/techdoc/ref/inv.html cheers, David
![](https://secure.gravatar.com/avatar/ad4ab4eded6bcd5d60bacc446419a4fd.jpg?s=120&d=mm&r=g)
Dear all, Thanks. I can get away with not inverting the matrix, actually, I just wanted to confirm a calculation via a different route, and I was momentarily surprised by my result. I realise my mistake though. Thanks for pointing it out for me! ~ Roger On Nov 10, 2007 4:11 PM, David Cournapeau <david@ar.media.kyoto-u.ac.jp> wrote:
Roger Herikstad wrote:
Dear scipy users, I am trying to invert a 12 by 12 complex matrix R using scipy.linalg.inv(), but the round-off errors seem a bit too big. If I do scipy.dot(Ri,R), the first row of the resulting matrix looks like this:
array([ 0.953125 +0.j , 0.06542969+0.01171875j, 0.08154297+0.15234375j, -0.078125 -0.09375j , 0.19140625-0.0859375j , 0.08203125+0.140625j , -0.08398438+0.0078125j , -0.02539062-0.03125j , -0.06738281+0.015625j , -0.04736328+0.15820312j, -0.09057617+0.02832031j, 0.109375 -0.0625j ])
Is this normal? Inverting a 2x2 matrix produces the expected result. I've attached a pickle of my matrix. Thanks! As a rule, you should not invert a matrix unless you *really* need it. For example, if you want X in A X = B, with A a matrix, B and X vectors, inverting A should be avoided. Some other methods are better suited (numerically speaking), depending on A and what you are trying to do.
The mathworks have good introduction on this topic, if you look for online help on inv, pinv and so on:
http://www.mathworks.com/access/helpdesk/help/techdoc/ref/inv.html
cheers,
David
_______________________________________________ SciPy-user mailing list SciPy-user@scipy.org http://projects.scipy.org/mailman/listinfo/scipy-user
participants (4)
-
David Cournapeau
-
Michael McNeil Forbes
-
Nils Wagner
-
Roger Herikstad