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
Bookmarks