Jump to content

  • Log In with Google      Sign In   
  • Create Account


Inverse Matrix


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
10 replies to this topic

#1 masonium   Members   -  Reputation: 118

Like
Likes
Like

Posted 11 October 2001 - 11:51 AM

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?

Sponsor:

#2 LilBudyWizer   Members   -  Reputation: 491

Like
Likes
Like

Posted 11 October 2001 - 02:50 PM

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 -1

Subtract 2 times first row from second row

x y rhs
1 1 1
0 -5 -3

Multiply second row by -1/5

x y rhs
1 1 1
0 1 3/5

Subtract 1 times second row from first row

x y rhs
1 0 2/5
0 1 3/5

Answer 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.

#3 python_regious   Members   -  Reputation: 929

Like
Likes
Like

Posted 12 October 2001 - 04:21 AM

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

#4 cruZ   Members   -  Reputation: 133

Like
Likes
Like

Posted 12 October 2001 - 05:13 AM

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

#5 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 12 October 2001 - 05:51 AM

Or if you are using the D3DX stuff, you can simply just call a D3DXMatrixInverse!

--Jeff

#6 LilBudyWizer   Members   -  Reputation: 491

Like
Likes
Like

Posted 12 October 2001 - 06:08 AM

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 4

Augmented Matrix
1 2 1 0
3 4 0 1

Subtract 3 times first row from second
1 2 1 0
0 -2 -3 1

Multiply second row by -1/2
1 2 1 0
0 1 3/2 -1/2

Subtract 2 times second row from first
1 0 -2 -1
0 1 3/2 -1/2

Extract inverse
-2 -1
3/2 -1/2



I don''t see where the transpose comes into play.

#7 cruZ   Members   -  Reputation: 133

Like
Likes
Like

Posted 12 October 2001 - 07:06 AM

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

#8 grhodes_at_work   Moderators   -  Reputation: 1361

Like
Likes
Like

Posted 12 October 2001 - 07:24 AM

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.

#9 LilBudyWizer   Members   -  Reputation: 491

Like
Likes
Like

Posted 12 October 2001 - 11:42 AM

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.

#10 masonium   Members   -  Reputation: 118

Like
Likes
Like

Posted 12 October 2001 - 04:59 PM

could someone explain that gauss thing again?

#11 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 14 October 2001 - 10:08 AM

Try this for general matrix/quaternion questions and answers:

[link]
http://skal.planet-d.net/demo/matrixfaq.htm
[/link]

You can find a very optimal way of performing a 4x4 inverse here:

[link]
http://developer.intel.com/design/pentiumiii/sml/24504301.pdf
[/link]

According to Intel, performing a matrix inverse yields faster results for Cramer''s rule than Gaussian elimination with dimensions <= 6. All the information and source code is available at the above link.

Bear in mind also that if your 4x4 matrices are *only* a combination of any of the following: translation, rotation, or scale, you can perform an "affine matrix" inverse much quicker than the above methods. Information available here:

[link]
http://www.cs.unc.edu/~gotz/code/affinverse.html
[/link]

HTH




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS