Results 1 to 9 of 9

Thread: matrices help again (inverse) please

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Posts
    12

    matrices help again (inverse) please

    hi there would anyone be able to give me a link or guidence as how i would go about finding the inverse of A? I have a book that tells me add subtract and multiply.

    the question is this: find the inverse of A

    A =

    (19 81)
    (2 10)

    sorry for the crude matrices. any help would be great

    lakitu

  2. #2
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: matrices help again (inverse) please

    Quote Originally Posted by lakitu
    hi there would anyone be able to give me a link or guidence as how i would go about finding the inverse of A? I have a book that tells me add subtract and multiply.

    the question is this: find the inverse of A

    A =

    (19 81)
    (2 10)

    sorry for the crude matrices. any help would be great

    lakitu
    Hello.

    Matrices can be inverted by various algorithms. It's not easy to explain in a few words so I suggest you Google around. Yot can search for "matrix inversion", "Gauss-Jordan", "LU decomposition", etc.

    Or you can go to http://mathworld.wolfram.com/topics/Matrices.html or http://mathworld.wolfram.com/topics/...perations.html or http://mathworld.wolfram.com/MatrixInverse.html
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Posts
    12

    Re: matrices help again (inverse) please

    thank you i will try those links now

  4. #4
    Frenzied Member yrwyddfa's Avatar
    Join Date
    Aug 2001
    Location
    England
    Posts
    1,253

    Re: matrices help again (inverse) please

    A more general solution

    VB Code:
    1. Public Function MxInverse(Matrix() As Double) As Double()
    2.    
    3.     Dim i As Long
    4.     Dim j As Long
    5.     Dim Rows As Long
    6.     Dim Cols As Long
    7.     Dim Tmp() As Double
    8.     Dim Ret() As Double
    9.     Dim Degree As Long
    10.    
    11.     Tmp = Matrix
    12.    
    13.     Rows = UBound(Tmp, 1)
    14.     Cols = UBound(Tmp, 2)
    15.     Degree = Cols + 1
    16.    
    17.     'Augment Identity matrix onto matrix M to get [M|I]
    18.     ReDim Preserve Tmp(Rows, (Degree * 2) - 1)
    19.     For i = Degree To (Degree * 2) - 1
    20.         Tmp(i Mod Degree, i) = 1
    21.     Next
    22.    
    23.     ' Now find the inverse using Gauss-Jordan Elimination which should get us [I|A-1]
    24.     MxGaussJordan Tmp
    25.    
    26.     ' Copy the inverse (A-1) part to array to return
    27.     ReDim Ret(Rows, Cols)
    28.     For i = 0 To Rows
    29.         For j = Degree To (Degree * 2) - 1
    30.             Ret(i, j - Degree) = Tmp(i, j)
    31.         Next
    32.     Next
    33.    
    34.     MxInverse = Ret
    35.    
    36. End Function
    37.  
    38. Public Sub MxGaussJordan(Matrix() As Double)
    39.    
    40.     Dim Rows As Long
    41.     Dim Cols As Long
    42.     Dim P As Long
    43.     Dim i As Long
    44.     Dim j As Long
    45.     Dim m As Double
    46.     Dim d As Double
    47.     Dim Pivot As Double
    48.    
    49.     Rows = UBound(Matrix, 1)
    50.     Cols = UBound(Matrix, 2)
    51.  
    52.     ' Reduce so we get the leading diagonal
    53.     For P = 0 To Rows
    54.         Pivot = Matrix(P, P)
    55.         For i = 0 To Rows
    56.             If Not P = i Then
    57.                 m = Matrix(i, P) / Pivot
    58.                 For j = 0 To Cols
    59.                     Matrix(i, j) = Matrix(i, j) + (Matrix(P, j) * -m)
    60.                 Next
    61.             End If
    62.         Next
    63.     Next
    64.    
    65.     'Divide through to get the identity matrix
    66.     'Note: the identity matrix may have very small values (close to zero)
    67.     'because of the way floating points are stored.
    68.     For i = 0 To Rows
    69.         d = Matrix(i, i)
    70.         For j = 0 To Cols
    71.             Matrix(i, j) = Matrix(i, j) / d
    72.         Next
    73.     Next
    74.    
    75. End Sub

    It is not optimised. You should use LU Decomposition for better algorithmic performance, and make of CopyMemory to increase the code performance. Nevertheless; it works
    "As far as the laws of mathematics refer to reality, they are not certain; and as far as they are certain, they do not refer to reality." - Albert Einstein

    It's turtles! And it's all the way down

  5. #5
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: matrices help again (inverse) please

    Here is a tutorial with fully worked examples on LU decomposition and its application tfor finding the inverse of a matrix.

    And this is from the very famous "Numerical Recipes" book that's available on-line: http://www.library.cornell.edu/nr/bookcpdf/c2-3.pdf
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  6. #6
    Member Thomas154321's Avatar
    Join Date
    Apr 2006
    Posts
    38

    Re: matrices help again (inverse) please

    Let Matrix A =
    (a b)
    (c d)

    So the inverse = A^-1 =
    (d -b) x 1/[ad-bc]
    (-c a)

    So for your matrix, the inverse of
    (19 81)
    (2 10)
    is
    (10 -81) x 1/(190-162) =
    (-2 19)

    ([5/14] [-81/28])
    ([-1/14] [19/28]).

  7. #7
    Frenzied Member
    Join Date
    Jul 1999
    Location
    Huntingdon Valley, PA 19006
    Posts
    1,151

    Re: matrices help again (inverse) please

    Several years ago there was a thread at this forum whihc descibed matrix inversion, determinant evaluation, and solution of simultaneous linear equations.

    A search might find it.
    Live long & prosper.

    The Dinosaur from prehistoric era prior to computers.

    Eschew obfuscation!
    If a billion people believe a foolish idea, it is still a foolish idea!
    VB.net 2010 Express
    64Bit & 32Bit Windows 7 & Windows XP. I run 4 operating systems on a single PC.

  8. #8
    Fanatic Member x-ice's Avatar
    Join Date
    Mar 2004
    Location
    UK
    Posts
    671

    Re: matrices help again (inverse) please

    Quote Originally Posted by lakitu
    hi there would anyone be able to give me a link or guidence as how i would go about finding the inverse of A? I have a book that tells me add subtract and multiply.

    the question is this: find the inverse of A

    A =

    (19 81)
    (2 10)

    sorry for the crude matrices. any help would be great

    lakitu
    For your martix:

    A inverse =

    (10 -81)
    (-2 19)

  9. #9
    Member Thomas154321's Avatar
    Join Date
    Apr 2006
    Posts
    38

    Re: matrices help again (inverse) please

    You didn't multiply by the reciprocal of the determinant x-ice.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width