Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7951685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:38:06+00:00 2026-06-04T02:38:06+00:00

I have a matrix A : 1 3 1 7 5 2 4 3

  • 0

I have a matrix A:

1 3 1
7 5 2
4 3 7
8 2 1
3 9 6
4 5 2

and a matrix B:

2 9 1
4 3 8
9 7 3
4 4 2
6 5 7
2 9 2

I want to compute C:

1*2+3*9+1*1
7*4+5*3+2*8
4*9+3*7+7*3
8*4+2*4+1*2
3*6+9*5+6*7
4*2+5*9+2*2

How can I express this purely using matrix operations? I realize I can do this using . versions but I am interested in pure matrix operations. For example, when I have two vectors x and y, I vastly prefer x'*y over sum(x.*y). Hence I am interested in how to do the above also using matrix operations.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T02:38:07+00:00Added an answer on June 4, 2026 at 2:38 am

    If you do not want to use vector operators, you can get the same result by performing a matrix multiplication with the transpose of the second multiplicand (otherwise you’ll get a 3×3 result, in this case), and then extracting the diagonal.

    Like so: C = diag(A * B')

    I’m not quite sure how Octave optimizes this, but it appears to only be slightly slower than the element-wise approach. (at least, for this data set)

    function test(func, n, a, b)
        for i = 1:n
            func(a, b);
        endfor
    endfunction
    
    octave> tic; test(@(a, b) sum(a.*b, 2), 100000, A, B); toc
    Elapsed time is 2.843 seconds.
    
    octave> tic; test(@(a, b) diag(a*b'), 100000, A, B); toc
    Elapsed time is 3.2 seconds.
    

    CAUTION: A real life problem shows this to be far slower than the element-wise approach:

    octave:100> size(yy)
    ans =
    
       5000     10
    
    octave:101> size(expected)
    ans =
    
       5000     10
    
    octave:102> tic; diag(yy * expected'); toc;
    Elapsed time is 0.5447 seconds.
    octave:103> tic; sum(yy .* expected, 2); toc;
    Elapsed time is 0.0016899 seconds.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this matrix of size 10000 by 1. I want to remove some
so we have this matrix a=[1;2;3] and we want to multiply it by itself
I have this following numpy matrix that I want to sort in ascending order
I have a matrix M thats's 16384 x 81 . I want to compute
I have a NxM matrix and I want to compute the NxN matrix of
I have a 101x82 size matrix called A . Using this variable matrix, I
I have a matrix A consisting of 200 vectors of size d. I want
I have a square matrix file, and I want to load it into Perl.
I have two dimensional matrix which stores values between 0 to 1. I want
I have one column matrix with n rows. I want difference between row 2

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.