# Bug? : "invert" doesn't work in this case

I’m not sure that this categoly is proper to post, but the function “invert” doesn’t work in this case. I need your help!

I executed the following code. It calculates inverse of a matrix A and multiple it by A to confirm if it’s correct.

``````
import Blender as B
import Blender.Mathutils as BM
BVec = BM.Vector
BMat = BM.Matrix

lcAMat = BMat([1,1], [-1,0])
lcBVec = BVec([1,1])

print lcAMat, "AMat"
lcAInv = lcAMat.invert()
print lcAInv, "AInv"

lcACopy = BMat([1,1], [-1,0])
print lcAInv*lcACopy, "1?"

``````

I got the following result in which A^-1 * A is not equal to unit matrix. That’s the problem.

I have confirmed what A^-1 is by calculating with kind of software of computer algebra system (CAS) as follows.

According to CAS, the correct answer of A^-1 is [[0,-1],[1,1]] while it’s [[0,1],[-1,1]] in Blender. Please let me know what my mistake is in the code.

hi Hans,
seems to be a bug in invert() for 2x2 matrices. It works well with 3x3 matrices.
temp workaround: convert your 2x2matrix to 3x3matrix before invert()

found the bug in “matrix.c” line 249:

if(self->rowSize == 2) {
mat[0] = self->matrix[1][1];
mat[1] = -self->matrix[1][0];
mat[2] = -self->matrix[0][1];
mat[3] = self->matrix[0][0];

but should be:

``````        mat[1] = -self-&gt;matrix[0][1];
mat[2] = -self-&gt;matrix[1][0];
``````

i will write a bug report and a patch for svn.

possible workaround for blender<2.49: your2x2matrix.transpose().invert()

Thanks, migius!
Thanks a lot for early reply, writing a bug report, and giving an alternative.
I think, I should have taken a look at the .c source code.

I’d like to ask one more thing…
Could I also ask whether it is a bug or even write a bug report? If it’s possible, where should I go?
…apparently, it is not in this forum.

Thank you so much, Kai Kostack.
So, I should get an account to take a look at the source code in SVN or to report a bug, right?