+ Reply to Thread
Results 1 to 3 of 3

Chain linking matrix multiplication function

Hybrid View

  1. #1
    Registered User
    Join Date
    12-19-2007
    Posts
    4

    Chain linking matrix multiplication function

    Hi,
    I have 30 different matrices and I want a function that chain links them by multiplication. To do this with MMult quickly becomes a very long formula.

    I have already a matrix power function which raises a particular matrix to a certain power, n

    Function MPower(Matrix, n)
        If n = 1 Then
            MPower = Matrix
            Else: MPower = Application.MMult(MPower(Matrix, n - 1), Matrix)
        End If
    End Function
    Now I need a similar function that multiplies different matrices together

    I.e. Matrix 1 x Matrix 2 x Matrix 3....Matrix n

    so
    if n=3, then the function returns Matrix 1 x Marrix 2 x Matrix 3.
    if n=2, function returns Matrix 1 x Matrix 2 etc

    Can anyone help?
    thanks
    toby
    Last edited by NBVC; 03-03-2010 at 12:00 PM.

  2. #2
    Valued Forum Contributor
    Join Date
    10-15-2007
    Location
    Home
    MS-Off Ver
    Office 2010, W10
    Posts
    373

    Re: Chain linking matrix multiplication function

    Hi toby

    I hope this will get you started.

    The code has no error checking, you can add it. I assumed you use it with at least 2 matrices, the dimensions of the matrices are correct, etc.

    You can use for ex. like this:

    =MMultN(B3:C4,E3:G4,I3:J5)

    Function MMultN(ParamArray vMatrices() As Variant) As Variant
    Dim j As Long
    
    MMultN = Application.MMult(vMatrices(0), vMatrices(1))
    For j = 2 To UBound(vMatrices)
        MMultN = Application.MMult(MMultN, vMatrices(j))
    Next j
    End Function
    Last edited by lecxe; 03-03-2010 at 11:53 AM.

  3. #3
    Registered User
    Join Date
    12-19-2007
    Posts
    4

    Re: Chain linking matrix multiplication function

    thats great
    thanks

+ 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