## Advanced Math (Matrix * Vector)

1155 Views 16 Replies Latest reply: May 8, 2012 8:12 PM by MVittiS
Previous Next
Calculating status...
Currently Being Moderated
May 8, 2012 1:36 PM

Hello.

In Numbers (iWork '08), is there any way to calculate the elements resulting from multiplying a Matrix (square table) to a Vector (single-column table) in another Vector (single-column table)?

I'm currently multiplying term by term, but it's a pain for lots of data. There must be a smarter way to do that.

Numbers '08, Mac OS X (10.7.3)
• Level 7 (28,175 points)
Currently Being Moderated
May 8, 2012 2:02 PM (in response to MVittiS)

Numbers doesn't support Matrix math, not in either Numbers 08 or Numbers 09.

Jerry

• Level 6 (12,625 points)
Currently Being Moderated
May 8, 2012 2:24 PM (in response to MVittiS)

there is a function called sumproduct() you can use to assist in this task:

• Level 6 (12,625 points)
Currently Being Moderated
May 8, 2012 2:37 PM (in response to MVittiS)

So if you have the following two matrices:

V[10] and W[10, 10] then you want to perform operations to make a new matrix X which is 10 x 10 and is:

V[0]*W[0, 0], V[1]*W[0, 1], ... V[9]*W[0, 9]

V[0]*W[1, 0], V[1]*W[1, 1], ... V[9]*W[1, 9]

.

.

.

V[0]*W[9, 0], V[1]*W[9, 1],...  V[9]*W[9, 9]

right?

• Level 6 (12,625 points)
Currently Being Moderated
May 8, 2012 3:03 PM (in response to Wayne Contello)

If the answer to my previous question is "Yes", then you can use a method like this:

I am multiplying a 1 dimensional array times a two dimensional array resulting in a two dimensional array.

To make this easier I transpose the 2D array, then multiply each row in table "Vector 1" by the corresponding row in each column of  the table "Vector 2".  This is stored in the table "Result Transposed".  Then I un-transpose and store in the table "Result".

To do this we can start with transposing the table "Vector 2" into the table "Vector 2 Transposed" (the table with the highlighted cell in the image above):

A1=OFFSET(Vector 2 :: \$A\$1, COLUMN()-1, ROW()-1, 1, 1)

select A1 and fill to the right

select A1 thru J1 and fill down

Now let's put together the table "Result Transposed":

A1=Vector 1 :: \$A1*Vector 2 Transposed :: A1

select A1 and fill DOWN

now select A1 through A10 and fill to the right

Now let's un trasnpose the data in table "Result Transposed" and store in the table "Result":

in table "Result":

A1=OFFSET(Result Transposed :: \$A\$1, COLUMN()-1, ROW()-1, 1, 1)

select A1 and fill to the right

now select A1 thru J1 and fill down

• Level 6 (12,625 points)
Currently Being Moderated
May 8, 2012 5:53 PM (in response to MVittiS)

With regards to:

You got close; my intention was to multiply what you called "Vector 1" with "Vector 2" (a Matrix, although mathematically speaking you would need to invert the terms order) resulting in another "Vector 3" (which would be a single-column table; each line the sum of all numbers in a line of "Result").

Please be specific with what you would like similar to the v[0]*W[0, 1]...

The aux tables can be combined but I do not like doing that because:

1) it makes reading what you did more difficult

2) it make debugging more difficult

As I indicated you can hide the aux tables so you won't see them.

• Level 7 (28,175 points)
Currently Being Moderated
May 8, 2012 5:59 PM (in response to Wayne Contello)

MV,

The free LibreOffice will probably do what you need with no sleight of hand and you can copy the results into a Numbers document if Numbers has other features you wish to retain.

Jerry

• Level 6 (12,625 points)
Currently Being Moderated
May 8, 2012 7:33 PM (in response to MVittiS)

you can paste values only by using the menu item "Edit > Paste Values"

• Level 6 (12,625 points)
Currently Being Moderated
May 8, 2012 7:43 PM (in response to Wayne Contello)

So based on your input I think you want something like this:

the only difference is that the last table "Result" is now a single column with the formulas:

A1=SUM(Result Transposed :: A1:J1)

select A1 and fill down

you can make the final solution look like this by:

1) disabling the table name

2) sliding the aux tables under the table "Vector 2"

Previous Next

#### More Like This

• Retrieving data ...

#### Legend

• This solved my question - 10 points
• This helped me - 5 points
This site contains user submitted content, comments and opinions and is for informational purposes only. Apple disclaims any and all liability for the acts, omissions and conduct of any third parties in connection with or related to your use of the site. All postings and use of the content on this site are subject to the Apple Support Communities Terms of Use.