Tags: dot, matlab, matrices, product, programming, reshaped, versions, wherethe

dot product of matrices

On Programmer » Matlab

2,953 words with 3 Comments; publish: Wed, 30 Apr 2008 18:26:00 GMT; (200109.38, « »)

Hello,

I have two matrices, say A = [1 2; 3 4] and B = [5 6; 7 8].

I need to take the dot product of the reshaped versions, where

the reshaped versions are vectors formed by stacking the rows

after one another, starting from the first row, then the second row

etc. The reshaped A would then be a = [1 2 3 4] and b= [5 6 7 8].

So I want to do a*b', i.e. [1 2 3 4]*[5;6;7;8]. Is it possible

to do this using A and B instead of using 'reshape' on A and B, i.e.

can one use 'dot' on A and B to get a*b' ? Or is there some other

faster way than 'dot' ?

-frege

All Comments

Leave a comment...

  • 3 Comments
    • "frege" <frege.matlab.todaysummary.com.on_REMOVE_line.no> wrote in message

      news:ef0269b.-1.matlab.todaysummary.com.webx.raydaftYaTP...

      > Hello,

      > I have two matrices, say A = [1 2; 3 4] and B = [5 6; 7 8].

      > I need to take the dot product of the reshaped versions, where

      > the reshaped versions are vectors formed by stacking the rows

      > after one another, starting from the first row, then the second row

      > etc. The reshaped A would then be a = [1 2 3 4] and b= [5 6 7 8].

      > So I want to do a*b', i.e. [1 2 3 4]*[5;6;7;8]. Is it possible

      > to do this using A and B instead of using 'reshape' on A and B, i.e.

      > can one use 'dot' on A and B to get a*b' ? Or is there some other

      > faster way than 'dot' ?

      > -frege

      dot(A(:)',B(:))

      Brett

      #1; Wed, 30 Apr 2008 18:28:00 GMT
    • You can use trace. But it's more efficient to just evaluate it as

      A(:)'*B(:). If the matrices are symmetric then there are additional tricks

      you can do (such as scaling the diagonal elements and only taking products

      using the upper triangles).

      #3; Wed, 30 Apr 2008 18:30:00 GMT