Inverse Matrix

Started by
9 comments, last by masonium 22 years, 6 months ago
Does anyone know how to get the inverse of a 4*4 matrix? If matrix M = | a b c d | | e f g h | | i j k l | | m n o p | what would M^-1 be?
Advertisement
There is no formula because it is found procedurally. If you have a matrix with actual values then you can take the cross product of that matrix with the one you listed. That produces a set of 16 equations with 16 unknowns. The cross product gives the left hand side of the equation and the identity matrix gives the right hand side. You then have to solve that system of equations for the sixteen unknowns. I think the easiest way to do that is to put it in a 17 by 16 matrix and transform it to reduced row echelon form.

Using a simple example say x+y=1 and 2x-3y=-1.

    x  y   rhs  1  1    1  2 -3   -1Subtract 2 times first row from second row  x  y   rhs  1  1    1  0 -5   -3Multiply second row by -1/5  x  y   rhs  1  1    1  0  1   3/5Subtract 1 times second row from first row  x  y   rhs  1  0   2/5  0  1   3/5Answer x=2/5 and y=3/5  


The process is pretty straight forward so hopefully that is enough to get you going. If not then I would suggest a book on linear algebra or trying to find a tutorial on solving systems of linear equations online.
Keys to success: Ability, ambition and opportunity.
The inverse would be:

M -1 = C T /|M |

Where C is the co-factor matrix of M. |M| is the determinant of M.

Edited by - python_regious on October 12, 2001 11:26:53 AM
If at first you don't succeed, redefine success.
The Inverse of a n*n matrix can easily be computed by using the Gauss-algorithm. Transform your matrix to |A and I| I=Identity matrix:

|a11 a12 a13 ..a1j 1 0 0 0 0...n|
|a21 a22 a23 ..a2j 0 1 0 0 0...n|
|a31 a32 a33 ..a3j 0 0 1 0 0...n| and so on

Now apply the Gauss-algorithm on this n*n equation system. It will give you a matrix of the form:

|a11 a12 a13...a1j 1 0 0 0 0...n|
|0 a22 a23...a2j val 1 val val val...n|
|0 0 a33...a3j val val 1 ....

The matrix on the right (former identity) are now used as
right handside vectors (y) of the equationsystem Ax=y1..yn, where
Ax is the matrix on the left. You can now calculate recursivly the solution of this equation system, starting at aij up to a11 and the first column of the right matrix as y, then proceeding, using y2 for the same leftside and so on.

For ex. a 4*4 matrix would give you 4 4-dimensional solutions.
These 4 vectors put in a matrix are the transposed inverted matrix. To get the regular inverse just swap the lines with
the colums. The algorithm also calculates the determinant as a
positive side-effect. detA=product of aii. This algorithm seems complicated at first, but is very effective if bigger matrices are involved.
There exist many variation of the Gauss-algorithm. I won''t explain ít here, but you should find enough information on the net.
good luck cruz
Or if you are using the D3DX stuff, you can simply just call a D3DXMatrixInverse!

--Jeff
Hehe, that''s a bit easier isn''t it. I''m a bit lost on the last part about the transpose.

  Starting Matrix  1    2  3    4Augmented Matrix  1    2    1    0  3    4    0    1Subtract 3 times first row from second  1    2    1    0  0   -2   -3    1Multiply second row by -1/2  1    2    1    0  0    1   3/2 -1/2Subtract 2 times second row from first  1    0   -2   -1  0    1   3/2 -1/2Extract inverse -2   -1 3/2 -1/2  


I don''t see where the transpose comes into play.
Keys to success: Ability, ambition and opportunity.
The problem with LilBudyWizer's algorithm is that it presumes that all pivot-elements aii (the diagonal-elements used to eliminate the lines below) are different from 0. Otherwise a divide by 0 would occur. The algorithm I described uses 1-dimensional pivot-selection. (Sorry I forgot to mention that) This variation of Gauss can deal with the occurance of 0 as a pivot element. (It just selects another one, different from 0). If the algorithm can't find an pivot element different from 0 throughout the whole column, it terminates, which mathematically means the determinant is 0. That means the matrix is singular and cannot be inverted.


LilBudyWizer reduces the matrix at first to an upper triangular matrix and then to its canonical form. You can also do so, but for large matrices, the version with gauss-pivot is far more effective (with large I mean 4 and greater). To reduce the upper triangular matrix to ist canonical form you need to do the Gauss reduction one more time. This take actually more time

greets cruz

Edited by - cruz on October 12, 2001 2:17:48 PM

Edited by - cruz on October 12, 2001 2:22:15 PM
By all means, don''t use Cramer''s rule (which is the cofactor method). Its much more expensive than Gaussian elimination, even for very small matrices such as the 4x4.

Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.
Graham Rhodes Moderator, Math & Physics forum @ gamedev.net
Cruz,

The second post wasn''t proposing a means, but rather my best guess at understanding your post. Perhaps if you gave an example using a 2 by 2 matrix I would better understand what you mean.
Keys to success: Ability, ambition and opportunity.
could someone explain that gauss thing again?

This topic is closed to new replies.

Advertisement