PtokaX forum

Development Section => HOW-TO's => Topic started by: chill on 25 December, 2004, 13:54:36

Title: Invert Matrix
Post by: chill on 25 December, 2004, 13:54:36
there are 2 ways of inverting a matrix one
is
using  sub determinats
other is the Gau?-Jordan method

and the better one is defently
the Gau?-Jordan, it can easily calculate the
inverse Matrix of a 100 x 100 matrix
whereas the sub determinats method will take hours maybe, I borke it off, maybe someone want's to try...

and to prof the calculations of the following script are right.
we do this

the inverse Matrix =  matrix^-1

now when you multiply the orginal matrix with
the inveres you get the identity matrix

e.g. for a 3 x 3
1 0 0
0 1 0
0 0 1

so what we do is something like

m1 = Matrix:Create( 10, 10 )
m1:fillrandom( -5, 5 )

m1:draw()

m2 = m1^-1

m2: draw()

m3 = m2 * m1

m3:draw()

if m3 is a Identymatrix then the calcualtion was correct

now when we do
m1 = Matrix:Create( 100, 100 )
we get a 100 x 100 matrix to try the same

here (http://lua.uknnet.com/attachment.php?attachmentid=79&sid=c1082ca1b647efc375f415db70622c45)  the code
using Gau?-Jordan

here (http://lua.uknnet.com/attachment.php?attachmentid=80&sid=c1082ca1b647efc375f415db70622c45)  the code using sub detreminats