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

  • SEARCH
  • Home
  • 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 9166471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:09:43+00:00 2026-06-17T15:09:43+00:00

I want to compute y = a⊗a⊗a , where a is a n-by-1 vector,

  • 0

I want to compute y = a⊗a⊗a, where a is a n-by-1 vector, and ⊗ is the outer product operator. In this case y should be an n-by-n-by-n tensor.

If y = a⊗a, it is easy. I simply do:

y = a * a' 

But what to do in the first case? How do I compute this outer product efficiently in MATLAB if there are more than two vectors?

  • 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-17T15:09:44+00:00Added an answer on June 17, 2026 at 3:09 pm

    In a multi-dimensional (tensor) case of y = u⊗v, I believe that you need to shift the dimensions of the second operand like so:

    v_t = permute(v, circshift(1:(ndims(u) + ndims(v)), [0, ndims(u)]));
    

    and then multiply them with bsxfun:

    y = bsxfun(@times, u, v_t);
    

    The regular matrix multiplication is defined only for vector and 2-D matrices, so we couldn’t use it in the general case.

    Also note that this computation still fails if the second operand is a 1-D vector, because ndims returns 2 instead of 1 for vectors. For this purpose, lets define our own function that counts dimensions:

    my_ndims = @(x)(isvector(x) + ~isvector(x) * ndims(x));
    

    To complete the answer, you can define a new function (e.g. an anonymous function), like so:

    outprod = @(u, v)bsxfun(@times, u, permute(v, circshift(1:(my_ndims(u) + my_ndims(v)), [0, my_ndims(u)])));
    

    and then use it as many times as you want. For example, y = a×a×a would be computed like so:

    y = outprod(outprod(a, a), a);
    

    Of course, you can write a better function that takes a variable number of arguments to save you some typing. Something along these lines:

    function y = outprod(u, varargin)
        my_ndims = @(x)(isvector(x) + ~isvector(x) * ndims(x));
        y = u;
        for k = 1:numel(varargin)
            v = varargin{k};
            v_t = permute(v, circshift(1:(my_ndims(y) + my_ndims(v)),[0, my_ndims(y)]));
            y = bsxfun(@times, y, v_t);
        end
    

    I hope I got the math right!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

first post! major edit.. I've got this program for computing a dot product, compiled
I want to compute the time 4 hours later during the DST transition, either
For use in a rigid body simulation, I want to compute the mass and
I want to ask how to add a computed column in BIRT that compute
I am using CoreGraphics to draw a quadratic bezier but want to computer the
May be it sound dumb but if I want some computed value from other
I want to search the computer from this table and when i have stored
I want install android on my computer but using the sdk it fails to
I want this function (defn ret-lowest-str-len Computes the lengths of two strings. Returns default
Possible Duplicate: Compute Median of Values Stored In Vector - C++? I need to

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.