+ Reply to Thread
Results 1 to 13 of 13

Array elements from MMULT

  1. #1
    Registered User
    Join Date
    10-26-2016
    Location
    Rome, NY
    MS-Off Ver
    2013
    Posts
    7

    Array elements from MMULT

    I'm using the LARGE function to find the largest element value in an array created by the MMULT function. Any ideas on how I can directly determine the (i,j) reference for the a maximum value w/o VBA (which I can do if necessary) and w/o placing the result from MMULT in a block of cells on a sheet?

    For example, two arrays of data in columns C and D. I'd like to know the row and column reference where the largest value occurs in the matrix produced by MMULT.

    =LARGE(MMULT(C2:C7,TRANSPOSE(D2:D7)),1)

    Thanks,
    Steve

  2. #2
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Array elements from MMULT

    Post some sample data and tell us what result you expect.
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  3. #3
    Registered User
    Join Date
    10-26-2016
    Location
    Rome, NY
    MS-Off Ver
    2013
    Posts
    7

    Re: Array elements from MMULT

    Capture.JPG

    Attached shows data in cells C2:D7. The result of MMULT(C2:C7,TRANSPOSE(D2:D7)) is shown of effect in cells F2:K7. What I'm looking for is the row and column pair with the maximum value, in this example row 5, column 2 has the maximum element 0.2. What I don't want to do is dump the result of MMULT to a set of cells like I have shown in cells F2:K7. I'm thinking that I'm asking for too much

    Thanks for looking at this.
    Steve

  4. #4
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,583

    Re: Array elements from MMULT

    Same formula enter as ARRAY formula. Then result will appear.

    How to enter ARRAY formula.
    Select the cell with your formula.
    Press F2
    now press Ctrl+Shift+Enter keys together.
    {} will surround the formula by excel.
    Click else where.

  5. #5
    Registered User
    Join Date
    10-26-2016
    Location
    Rome, NY
    MS-Off Ver
    2013
    Posts
    7

    Re: Array elements from MMULT

    My apologies for the lack of clarity, I do understand array formulas, what I want is effectively this (i.e., something that returns the row or column number where the max occurs):

    {ROW(LARGE(MMULT(C2:C7,TRANSPOSE(D2:D7)),1)} = 5

  6. #6
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,819

    Re: Array elements from MMULT

    First question: with 1E6 by 16k cells, why are you worried about using too many cells? IMO, the easiest first approach is to do like you are doing -- compute the resulting product matrix, then find the largest value (probably a two step process of finding the largest in each row or column, then find the largest in that resulting vector), then return the desired row and column for that value (using MATCH() functions).

    Perhaps it is my emphasis on understanding the math behind a problem, but it seems like it should be possible to locate the max value in the result matrix without computing the entire matrix in this case. Can I assume that you can recall the definitions of matrix multiplication well enough to "work backwards" from the max in the result matrix? Here's the thought process:

    1) Looking at the matrix product of vector1*transpose(vector2), what you end up with is the product of each possible pairing of values in vector1 and vector2.
    2) You are looking for the maximum of those products.
    3) I would hypothesize (you may need to do enough leg work to prove to yourself that this would be true) that the maximum of the products will be the product of the maxima.
    4) If (3) is true, then you can find the maximum value by finding the two maxima =MAX(C2:C7) =MAX(D2:D7). The maximum value in the result matrix will simply be the product of these two values =PRODUCT(MAX(C2:C7),MAX(D2:D7))
    5) Thinking through the way that matrix multiplication works on two vectors like this, the position of a value in vector1 corresponds to the row number in the result matrix, and the position of a value in vector2 corresponds to the column number in the result matrix. The MATCH() function is well suited to finding the position of a value within a vector (https://support.office.com/en-us/art...9-533f4a37673a ), so, the desired row number would =MATCH(MAX(C2:C7),C2:C7,0).

    A lot of that development is math and not programming. But, if you can convince yourself that (3) is true, then the programming part is down to two MAX() functions, two MATCH() functions, and a PRODUCT() function, and you have successfully avoided computing the entire result matrix.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  7. #7
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Array elements from MMULT

    I'm not sure what result you want.

    The max value will be obtained by multiplying the max values from each column.

    So, max from C2:C7 = 0.5 = relative position = 5

    Max from D2:D7 = 0.4 = relative position = 2.

    Do you want these values returned to separate cells or combined into a single cell?

  8. #8
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,583

    Re: Array elements from MMULT

    ARRAY formulas
    For ROW
    Please Login or Register  to view this content.
    For COLUMN
    Please Login or Register  to view this content.
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    10-26-2016
    Location
    Rome, NY
    MS-Off Ver
    2013
    Posts
    7

    Re: Array elements from MMULT

    MrShorty,

    Excellent discussion that now has me looking at this problem from a different angle, thanks for taking the time to write so much. I certainly can convince myself that 3) is true.

    What I didn't mention from the beginning, is that I'll eventually need the top n values in the matrix (and thus probably got focused in on the LARGE function), but suspect that I can find those values via a similar line of thinking.

    I'll get back to the whiteboard and mark this solved.

    Cheers,
    Steve

  10. #10
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Array elements from MMULT

    Quote Originally Posted by kvsrinivasamurthy View Post
    ARRAY formulas
    For ROW

    =LARGE(IF(MMULT($C$2:$C$7,TRANSPOSE($D$2:$D$7))=MAX(MMULT($C$2:$C$7,TRANSPOSE($D$2:$D$7))),ROW($C$2:$C$7),""),1)-ROW($C$2)+1

    For COLUMN

    =LARGE(IF(MMULT($C$2:$C$7,TRANSPOSE($D$2:$D$7))=MAX(MMULT($C$2:$C$7,TRANSPOSE($D$2:$D$7))),TRANSPOSE(ROW($D$2:$D$7)-ROW($D$2)+1),""),1)
    I think you're overcomplicating it.

    Row:

    =MATCH(MAX(C2:C7),C2:C7,0)

    Column:

    =MATCH(MAX(D2:D7),D2:D7,0)

  11. #11
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,819

    Re: Array elements from MMULT

    What I didn't mention from the beginning, is that I'll eventually need the top n values in the matrix (and thus probably got focused in on the LARGE function), but suspect that I can find those values via a similar line of thinking.
    Maybe, but I think this logic will become rather complex rather quickly as you work your way down through the n largest.

    kvsrinivasamurthy's solution seems to work, and may be easily adapted to the n largest, but I note that it performs the matrix multiplication at least twice per function (and two functions per nth-largest value). Depending on how many values you end up looking for, it seems that there is getting to be a lot of extra computer and programming effort to avoid using a few cells. I will come back to my first question -- with 16 million cells per tab (and tabs limited only by available memory), why are we going to such lengths to avoid calculating and storing the result matrix in the spreadsheet?

  12. #12
    Registered User
    Join Date
    10-26-2016
    Location
    Rome, NY
    MS-Off Ver
    2013
    Posts
    7

    Re: Array elements from MMULT

    Admittedly, my initial desire to not just to place the result of MMULT into a set of cells was just a matter of looking for an elegant solution. I just didn't like the idea of having a 25K element matrix lying around just to make an index reference. I'll fiddle around with kvsrinivasamurthy's solution (thank you!, kvsrinivasamurthy), but in the end, I'll probably do just exactly that on a hidden sheet.

    Thanks all.

  13. #13
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,583

    Re: Array elements from MMULT

    Thanks for feed back.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. How to sum some elements of another array into a new one
    By love0126 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-17-2015, 10:15 PM
  2. Array Storage Problem: Array Elements Deleted on 'End' Command
    By AidenS in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-15-2014, 10:38 AM
  3. [SOLVED] Removing specific elements from an Array based on matching elements in a different Array
    By jamesdeuce in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-24-2014, 10:35 PM
  4. help assigning elements of dictionary to array and then pasting array into worksheet
    By welchs101 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 12-05-2013, 10:37 AM
  5. [SOLVED] Populate Listbox with all rows of a dynamic array where elements of a single array match.
    By Tayque_J_Holmes in forum Excel Programming / VBA / Macros
    Replies: 21
    Last Post: 08-07-2012, 04:54 AM
  6. PCA or MMULT on large array
    By lady_Jane in forum Excel General
    Replies: 4
    Last Post: 06-17-2011, 02:06 PM
  7. how array functions work mmult,minverse etc
    By ramki in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 03-02-2006, 10:40 AM

Tags for this Thread

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