+ Reply to Thread
Results 1 to 9 of 9

How do I get the diagonal of a matrix from excel?

  1. #1
    JoeNiner
    Guest

    How do I get the diagonal of a matrix from excel?

    excel 2003 or 2007 beta 2

    How can I get the diagonal of a matrix returned as a single column vector?

  2. #2
    Max
    Guest

    Re: How do I get the diagonal of a matrix from excel?

    "JoeNiner" wrote:
    > How can I get the diagonal of a matrix returned as a single column vector?


    One try ..

    Assuming a 4 x 4 grid in B2:E5 (top left cell is B2)

    Perhaps this expression:
    =OFFSET(B2,ROW(INDIRECT("1:4"))-1,ROW(INDIRECT("1:4"))-1)

    Or maybe this expression below,
    array-entered into a 4 cell columnar range, say into B20:B23 :
    =INDEX(B2:E5,ROW(INDIRECT("1:4")),ROW(INDIRECT("1:4")))

    --
    Max
    Singapore
    http://savefile.com/projects/236895
    xdemechanik
    ---

  3. #3
    Biff
    Guest

    Re: How do I get the diagonal of a matrix from excel?

    =INDEX(B2:E2,,ROWS($1:1))

    Copied down

    Biff

    "Max" <[email protected]> wrote in message
    news:[email protected]...
    > "JoeNiner" wrote:
    >> How can I get the diagonal of a matrix returned as a single column
    >> vector?

    >
    > One try ..
    >
    > Assuming a 4 x 4 grid in B2:E5 (top left cell is B2)
    >
    > Perhaps this expression:
    > =OFFSET(B2,ROW(INDIRECT("1:4"))-1,ROW(INDIRECT("1:4"))-1)
    >
    > Or maybe this expression below,
    > array-entered into a 4 cell columnar range, say into B20:B23 :
    > =INDEX(B2:E5,ROW(INDIRECT("1:4")),ROW(INDIRECT("1:4")))
    >
    > --
    > Max
    > Singapore
    > http://savefile.com/projects/236895
    > xdemechanik
    > ---




  4. #4
    Harlan Grove
    Guest

    Re: How do I get the diagonal of a matrix from excel?

    Max wrote...
    >"JoeNiner" wrote:
    >>How can I get the diagonal of a matrix returned as a single column vector?

    >
    >One try ..
    >
    >Assuming a 4 x 4 grid in B2:E5 (top left cell is B2)
    >
    >Perhaps this expression:
    >=OFFSET(B2,ROW(INDIRECT("1:4"))-1,ROW(INDIRECT("1:4"))-1)

    ....

    FWIW, can't use the expression above as a term in an array formula.
    It's need to be

    N(OFFSET(B2,ROW(INDIRECT("1:4"))-1,ROW(INDIRECT("1:4"))-1))

    This can be done without volatile functions. As a column vector,

    =MMULT((ROW(M)-MIN(ROW(M))=COLUMN(M)-MIN(COLUMN(M)))*M,
    TRANSPOSE(COLUMN(M))^0)


  5. #5
    Max
    Guest

    Re: How do I get the diagonal of a matrix from excel?

    "Harlan Grove" wrote:
    > FWIW, can't use the expression above as a term in an array formula.
    > It's need to be
    > N(OFFSET(B2,ROW(INDIRECT("1:4"))-1,ROW(INDIRECT("1:4"))-1))


    Thanks for correction, Harlan.

    > This can be done without volatile functions. As a column vector,
    > =MMULT((ROW(M)-MIN(ROW(M))=COLUMN(M)-MIN(COLUMN(M)))*M,
    > TRANSPOSE(COLUMN(M))^0)


    I suppose M is a defined range referring to the matrix,
    eg to the 4 x 4 grid in B2:E5

    Does the N(..) need to be likewise applied here ?
    --
    Max
    Singapore
    http://savefile.com/projects/236895
    xdemechanik
    ---

  6. #6
    Harlan Grove
    Guest

    Re: How do I get the diagonal of a matrix from excel?

    Max wrote...
    >"Harlan Grove" wrote:
    >>FWIW, can't use the expression above as a term in an array formula.
    >>It's need to be
    >>N(OFFSET(B2,ROW(INDIRECT("1:4"))-1,ROW(INDIRECT("1:4"))-1))

    >
    >Thanks for correction, Harlan.


    Wasn't a correction per se. Your formula works when entered as an array
    formula into 1-column by 4-row ranges, but

    =SUMPRODUCT(OFFSET(B2,ROW(INDIRECT("1:4"))-1,ROW(INDIRECT("1:4"))-1))

    returns #VALUE! errors while

    =SUMPRODUCT(N(OFFSET(B2,ROW(INDIRECT("1:4"))-1,ROW(INDIRECT("1:4"))-1)))

    returns expected results.

    >>This can be done without volatile functions. As a column vector,
    >>=MMULT((ROW(M)-MIN(ROW(M))=COLUMN(M)-MIN(COLUMN(M)))*M,
    >>TRANSPOSE(COLUMN(M))^0)

    >
    >I suppose M is a defined range referring to the matrix,
    >eg to the 4 x 4 grid in B2:E5


    Correct.

    >Does the N(..) need to be likewise applied here ?


    Why don't you test it? Hint, try the array formula

    =SUM(MMULT((ROW(M)-MIN(ROW(M))=COLUMN(M)-MIN(COLUMN(M)))*M,
    TRANSPOSE(COLUMN(M))^0))

    It has to be an array formula because both MMULT and TRANSPOSE require
    array formula entry.


  7. #7
    Max
    Guest

    Re: How do I get the diagonal of a matrix from excel?

    Thanks for the clarifications, Harlan.
    Much appreciated.
    --
    Max
    Singapore
    http://savefile.com/projects/236895
    xdemechanik
    ---

  8. #8
    Registered User
    Join Date
    05-26-2017
    Location
    San Francisco
    MS-Off Ver
    Excel Mac 2011
    Posts
    1

    Re: How do I get the diagonal of a matrix from excel?

    =SUMPRODUCT(N(OFFSET(B2,ROW(INDIRECT("1:4"))-1,ROW(INDIRECT("1:4"))-1))) works really well. But I'm wondering if there's a way to make it sum up-and-to-the-right rather than down-and-to-the-right?

  9. #9
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,939

    Re: How do I get the diagonal of a matrix from excel?

    elyobsemaj welcome to the forum

    Unfortunately your post does not comply with Rule 2 of our Forum RULES. Do not post a question in the thread of another member -- start your own thread.

    If you feel an existing thread is particularly relevant to your need, provide a link to the other thread in your new thread.

    Old threads are often only monitored by the original participants. New threads not only open you up to all possible participants again, they typically get faster response, too.
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

+ 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