   Inversing a matrix
  Im trying to inverse matrices, and am starting off with a simple 2x2m00 m01m10 m11Im using Directx, so am using row majour, and have the followingVector2 v, matrix22 m   [A , B]vOut = v[a, b] * m[C , D]vOut = [aA + bC, aB + bD];and now i want to calculate the inverse of m, so that i can muliply it by vOut to get back to v again.so to inverse it, i was trying to work backwards. vOut.x = aA + bC;vOut.x - bc = aA;vOut.x - bc ----------- = a;AvOut.y = aB + bD;vOut.y - bD = aB;vOut.y - bD ----------- = b;BBut now i dont know how to put these back into the matrix. I believe i have to split the top one into A and C, and the bottom one into B and D.so something like the following, which i know is wrong, becuase there is no subtract in there, and thats where i am stuck.[1, 1    ][bC/A  , bD/B ]
  There are several ways to invert a matrix. For small matrices you can choose to use ad hoc formula like the following for 2x2 matrices (";" divides the row...)A-1 = [a b; c d]-1 = 1/(ad - bc) [d -b; -c a]or to use a more general method like Cramer's rule.For more information: Wikipedia or Wolfram MathWorld;  ah yes, Im aware of Cramers Rule and Gaussian elimination. But i was trying to calculate the inverse for the above matrix specifically. I knwo that Cramers rule and Gaussian elimination can work on all matrices, if they are indeed actually invertible. But was simply looking for the method used to calculate the above inverse specifically.And hopefully for someone to explain how it is done.   ;Quote:Original post by hick18But was simply looking for the method used to calculate the above inverse specifically. [...] And hopefully for someone to explain how it is done.That's what he gave you withA-1 = [a b; c d]-1 = 1/(ad - bc) [d -b; -c a]which is just a way of writing the following on one line:   1[ d   -b]A^(-1) = --------- [  ]    a d - b c [ -c   a];  You can't calculate the inverse matrix using your method. The system of equations you are trying to "solve" doesn't have any variable. You should at least try to rewrite your equation in the form:v * m = vOutv = vOut * m-1but this is a system of two equations and four variables and can't be solved uniquely. The usual way to find the inverse is to solve the systemA * A-1 = I[a b; c d]*[x y; z w] = [1 0; 0 1]ax + bz = 1ay + bw = 0cx + dz = 1cy + dw = 0   ;  Basically, im trying to figure out how the users of http://www.gamedev.net/community/forums/topic.asp?topic_id=478055that thread got their inverse matrix.going from  f = cotangent(fovy/2)  dp = near - far  f/aspect   0   0 00  f   0 00  0  (far+near)/dp   (2*far*near)/dp0  0  -1 0to the inverseaspect/f 0 00   0    1/f00   00 0    -1   00    dp/(2*far*near)   (far+near)/(2*far*near);  Very sparse matrices can often be inverted "by eye". They actually described the easy way to invert that in the thread: they broke it up into a 2x2 diagonal matrix of 2x2 matrices, each of which was trivial to invert.   ;  I understand how they got the top 2x2, but not the lower right 2x2, and was wondering if someone could explain it   ;  They just used the closed form 2x2 inversion. Because the lower right term is zero, half of the determinant drops out, simplifying the inverse further.   ;  I advise against Cramer's Rule, if your matrix is larger than, say, 3x3 or maybe a bit larger on modern processors. It gets prohibitively expensive very, very fast as the matrix size gets larger.Comparison of the Costs for Various MethodsOf course, that table is a bit old and isn't based on the possibility of using modern massively multicore processors, but the point is that there is an upper limit to its usefulness, whether it be number of operations or storage requirements.