+ Reply to Thread
Results 1 to 2 of 2

Inverse Matrix Function Problem

  1. #1
    Registered User
    Join Date
    09-14-2011
    Location
    Munich
    MS-Off Ver
    Excel 2003
    Posts
    1

    Inverse Matrix Function Problem

    Hello,


    I am trying to create a VBA function that calculates the inverse of a Matrix, but it does not work. I want to use this Function in other parts of my VBA code.

    Function InvMatrix(A11 As Double, A12 As Double, A21 As Double, A22 As Double) As Double


    Dim MatrixA(2, 2) As Double

    MatrixA(1, 1) = A11
    MatrixA(1, 2) = A12
    MatrixA(2, 1) = A21
    MatrixA(2, 2) = A22

    InvMatrix = Application.WorksheetFunction.MInverse(MatrixA)
    End Function

    Sub Test()
    Dim Matrix(2, 2) As Double
    ' example that does not work'
    Matrix = InvMatrix(2, 2, 1, 1)
    ' Check if Function works correctly
    Worksheets("ABDmatrix").Cells(1, 1) = Matrix(1, 1)
    Worksheets("ABDmatrix").Cells(1, 2) = Matrix(1, 2)
    Worksheets("ABDmatrix").Cells(2, 1) = Matrix(2, 1)
    Worksheets("ABDmatrix").Cells(2, 2) = Matrix(2, 2)

    End Sub

  2. #2
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Inverse Matrix Function Problem

    Welcome to the forum,

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1