Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
three 3D matrix multiplication

Subject: three 3D matrix multiplication

From: Jeyakumar

Date: 6 Jan, 2013 08:24:08

Message: 1 of 7

hi ,
my problem is that i have 3 3D matrices A(4,1,1), B(1,4,1) and C(1,1,4) respectively. i wanna perform matrix multiplication i.e A*B*C such that the resulting matrix shud be of dimension
4-by-4-by-4 i.e 4x4x4 cube. i just tried using mtimes function but it gave the following error
"Inputs must be 2-D, or at least
one input must be scalar.
To compute elementwise TIMES, use
TIMES (.*) instead."
i went thro lots of discussions here but still feelin puzzled.
help me fellas...

Thanks a lot in advanace :-)

Subject: three 3D matrix multiplication

From: Bruno Luong

Date: 6 Jan, 2013 08:32:06

Message: 2 of 7

"Jeyakumar " <jeymagnetron@gmail.com> wrote in message <kcbcb8$em6$1@newscl01ah.mathworks.com>...
> hi ,
> my problem is that i have 3 3D matrices A(4,1,1), B(1,4,1) and C(1,1,4) respectively. i wanna perform matrix multiplication i.e A*B*C such that the resulting matrix shud be of dimension
> 4-by-4-by-4 i.e 4x4x4 cube.

This is NOT matrix-multiplication. This operation is called tensor product.

Try
bsxfun(@times, bsxfun(@times, A, B), C)

Bruno

Subject: three 3D matrix multiplication

From: Jeyakumar

Date: 6 Jan, 2013 16:35:08

Message: 3 of 7

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <kcbcq6$g99$1@newscl01ah.mathworks.com>...
> "Jeyakumar " <jeymagnetron@gmail.com> wrote in message <kcbcb8$em6$1@newscl01ah.mathworks.com>...
> > hi ,
> > my problem is that i have 3 3D matrices A(4,1,1), B(1,4,1) and C(1,1,4) respectively. i wanna perform matrix multiplication i.e A*B*C such that the resulting matrix shud be of dimension
> > 4-by-4-by-4 i.e 4x4x4 cube.
>
> This is NOT matrix-multiplication. This operation is called tensor product.
>
> Try
> bsxfun(@times, bsxfun(@times, A, B), C)
>
> Bruno

thanks a lot sir. it worked like charm.:-)

Subject: three 3D matrix multiplication

From: James Tursa

Date: 7 Jan, 2013 07:48:08

Message: 4 of 7

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <kcbcq6$g99$1@newscl01ah.mathworks.com>...
> "Jeyakumar " <jeymagnetron@gmail.com> wrote in message <kcbcb8$em6$1@newscl01ah.mathworks.com>...
> > hi ,
> > my problem is that i have 3 3D matrices A(4,1,1), B(1,4,1) and C(1,1,4) respectively. i wanna perform matrix multiplication i.e A*B*C such that the resulting matrix shud be of dimension
> > 4-by-4-by-4 i.e 4x4x4 cube.
>
> This is NOT matrix-multiplication. This operation is called tensor product.
>
> Try
> bsxfun(@times, bsxfun(@times, A, B), C)
>
> Bruno

Or just:

bsxfun(@times, A*B, C)

James Tursa

Subject: three 3D matrix multiplication

From: Jeyakumar

Date: 7 Jan, 2013 15:17:14

Message: 5 of 7

"James Tursa" wrote in message <kcdujo$a69$1@newscl01ah.mathworks.com>...
> "Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <kcbcq6$g99$1@newscl01ah.mathworks.com>...
> > "Jeyakumar " <jeymagnetron@gmail.com> wrote in message <kcbcb8$em6$1@newscl01ah.mathworks.com>...
> > > hi ,
> > > my problem is that i have 3 3D matrices A(4,1,1), B(1,4,1) and C(1,1,4) respectively. i wanna perform matrix multiplication i.e A*B*C such that the resulting matrix shud be of dimension
> > > 4-by-4-by-4 i.e 4x4x4 cube.
> >
> > This is NOT matrix-multiplication. This operation is called tensor product.
> >
> > Try
> > bsxfun(@times, bsxfun(@times, A, B), C)
> >
> > Bruno
>
> Or just:
>
> bsxfun(@times, A*B, C)
>
> James Tursa


thank u ...so much.. ths is simpler even... saves a fraction of time on large dimensions...:-)

Subject: three 3D matrix multiplication

From: Matt J

Date: 7 Jan, 2013 15:27:15

Message: 6 of 7

"Jeyakumar " <jeymagnetron@gmail.com> wrote in message <kceotp$cum$1@newscl01ah.mathworks.com>...
>
> thank u ...so much.. ths is simpler even... saves a fraction of time on large dimensions...:-)

When working with large dimensions, you probably shouldn't be computing tensor products directly. You should be exploiting the properties of tensor products. For example, with,

D=bsxfun(@times, A*B, C)

Instead of doing something like

 sum(D,3)

it is more efficient to avoid computing D altogether and do

 sum(C,3)*A*B

Subject: three 3D matrix multiplication

From: Jeyakumar

Date: 8 Jan, 2013 17:12:09

Message: 7 of 7

"Matt J" wrote in message <kcepgj$f8k$1@newscl01ah.mathworks.com>...
> "Jeyakumar " <jeymagnetron@gmail.com> wrote in message <kceotp$cum$1@newscl01ah.mathworks.com>...
> >
> > thank u ...so much.. ths is simpler even... saves a fraction of time on large dimensions...:-)
>
> When working with large dimensions, you probably shouldn't be computing tensor products directly. You should be exploiting the properties of tensor products. For example, with,
>
> D=bsxfun(@times, A*B, C)
>
> Instead of doing something like
>
> sum(D,3)
>
> it is more efficient to avoid computing D altogether and do
>
> sum(C,3)*A*B


well .. i will try this n get back to u sir..:-).. thank u

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us