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:
matrix multiplication with zero dimensions

Subject: matrix multiplication with zero dimensions

From: Matt J

Date: 6 Jan, 2013 23:14:08

Message: 1 of 12

Is this documented anywhere?

>> zeros(3,0)*zeros(0,3)

ans =

     0 0 0
     0 0 0
     0 0 0

Subject: matrix multiplication with zero dimensions

From: Bruno Luong

Date: 6 Jan, 2013 23:34:08

Message: 2 of 12

"Matt J" wrote in message <kcd0g0$34t$1@newscl01ah.mathworks.com>...
> Is this documented anywhere?
>
> >> zeros(3,0)*zeros(0,3)
>
> ans =
>
> 0 0 0
> 0 0 0
> 0 0 0

Just like sum([]), prod([]), this result is no exception so to be documented separately.

Bruno

Subject: matrix multiplication with zero dimensions

From: Matt J

Date: 7 Jan, 2013 00:32:07

Message: 3 of 12

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <kcd1lg$6u4$1@newscl01ah.mathworks.com>...
> "Matt J" wrote in message <kcd0g0$34t$1@newscl01ah.mathworks.com>...
>
>
> Just like sum([]), prod([]), this result is no exception so to be documented separately.
==============

I can see the rational behind sum([])=0and prod([])=1. It's so that

sum([A,[]],2)=sum(A,2)+sum([])
prod([A,[]],2)=prod(A,2)*prod([])

I do not see the rationale behind the originally posted relationship, though. Taking a slightly different example, I can see perhaps that

 ones(3,0)*ones(0,3)

should end up being 3x3 because of the outer dimensions, but why should it end up containing zeros.

Subject: matrix multiplication with zero dimensions

From: Roger Stafford

Date: 7 Jan, 2013 03:41:07

Message: 4 of 12

"Matt J" wrote in message <kcd527$hou$1@newscl01ah.mathworks.com>...
> ....... I can see perhaps that
>
> ones(3,0)*ones(0,3)
>
> should end up being 3x3 because of the outer dimensions, but why should it end up containing zeros.
- - - - - - - - - -
  Think of it this way, Matt. Consider the four multiplications:

 M3 = ones(3,3)*ones(3,3);
 M2 = ones(3,2)*ones(2,3);
 M1 = ones(3,1)*ones(1,3);
 M0 = ones(3,0)*ones(0,3);

Each of the elements of 3 x 3 M3 is 3. Each of the elements of 3 x 3 M2 is 2. Each of the elements of 3 x 3 M1 is 1. Therefore by extension of this trend M0 should have 3 x 3 elements and each of them should be 0. As Bruno states, it is consistent with the philosophy behind having the sum of an empty vector be 0 and its product be 1.

  Another line of reasoning:

 M2 = M3 - M1 = 2*ones(3)
 M1 = M2 - M1 = 1*ones(3)
 M0 = M1 - M1 = 0*ones(3)

Roger Stafford

Subject: matrix multiplication with zero dimensions

From: Matt J

Date: 7 Jan, 2013 04:36:09

Message: 5 of 12

"Roger Stafford" wrote in message <kcdg4j$n70$1@newscl01ah.mathworks.com>...
>
> Think of it this way, Matt. Consider the four multiplications:
>
> M3 = ones(3,3)*ones(3,3);
> M2 = ones(3,2)*ones(2,3);
> M1 = ones(3,1)*ones(1,3);
> M0 = ones(3,0)*ones(0,3);
>
> Each of the elements of 3 x 3 M3 is 3. Each of the elements of 3 x 3 M2 is 2. Each of the elements of 3 x 3 M1 is 1. Therefore by extension of this trend M0 should have 3 x 3 elements and each of them should be 0.
=============

OK!

Subject: matrix multiplication with zero dimensions

From: Matt J

Date: 7 Jan, 2013 05:04:09

Message: 6 of 12

"Matt J" wrote in message <kcdjbp$46l$1@newscl01ah.mathworks.com>...
> "Roger Stafford" wrote in message <kcdg4j$n70$1@newscl01ah.mathworks.com>...
> >
> > Think of it this way, Matt. Consider the four multiplications:
> >
> > M3 = ones(3,3)*ones(3,3);
> > M2 = ones(3,2)*ones(2,3);
> > M1 = ones(3,1)*ones(1,3);
> > M0 = ones(3,0)*ones(0,3);
> >
> > Each of the elements of 3 x 3 M3 is 3. Each of the elements of 3 x 3 M2 is 2. Each of the elements of 3 x 3 M1 is 1. Therefore by extension of this trend M0 should have 3 x 3 elements and each of them should be 0.
> =============
>
> OK!


But... I still think these things should be documented somewhere. They don't satisfy the basic definitions of matrix multiplication, PROD, or SUM. They're just extrapolations of them.

Subject: matrix multiplication with zero dimensions

From: Roger Stafford

Date: 7 Jan, 2013 05:33:08

Message: 7 of 12

"Matt J" wrote in message <kcdl09$975$1@newscl01ah.mathworks.com>...
> But... I still think these things should be documented somewhere. They don't satisfy the basic definitions of matrix multiplication, PROD, or SUM. They're just extrapolations of them.
- - - - - - -
  I agree with you there. It should have been explicitly documented somewhere.

Roger Stafford

Subject: matrix multiplication with zero dimensions

From: James Tursa

Date: 7 Jan, 2013 07:38:09

Message: 8 of 12

"Roger Stafford" wrote in message <kcdmmk$ekv$1@newscl01ah.mathworks.com>...
> "Matt J" wrote in message <kcdl09$975$1@newscl01ah.mathworks.com>...
> > But... I still think these things should be documented somewhere. They don't satisfy the basic definitions of matrix multiplication, PROD, or SUM. They're just extrapolations of them.
> - - - - - - -
> I agree with you there. It should have been explicitly documented somewhere.
>
> Roger Stafford

Quoting from the doc for mtimes:

"Note If A is an m-by-0 empty matrix and B is a 0-by-n empty matrix, where m and n are positive integers, A*B is an m-by-n matrix of all zeros."

James Tursa

Subject: matrix multiplication with zero dimensions

From: Roger Stafford

Date: 7 Jan, 2013 08:09:09

Message: 9 of 12

"James Tursa" wrote in message <kcdu10$8bi$1@newscl01ah.mathworks.com>...
> "Note If A is an m-by-0 empty matrix and B is a 0-by-n empty matrix, where m and n are positive integers, A*B is an m-by-n matrix of all zeros."
- - - - - - - - - -
  Thanks James. That is the first place we ought to have looked.

Roger Stafford

Subject: matrix multiplication with zero dimensions

From: Matt J

Date: 7 Jan, 2013 11:26:10

Message: 10 of 12

"James Tursa" wrote in message <kcdu10$8bi$1@newscl01ah.mathworks.com>...
> "Roger Stafford" wrote in message <kcdmmk$ekv$1@newscl01ah.mathworks.com>...
> > "Matt J" wrote in message <kcdl09$975$1@newscl01ah.mathworks.com>...
> > > But... I still think these things should be documented somewhere. They don't satisfy the basic definitions of matrix multiplication, PROD, or SUM. They're just extrapolations of them.
> > - - - - - - -
> > I agree with you there. It should have been explicitly documented somewhere.
> >
> > Roger Stafford
>
> Quoting from the doc for mtimes:
>
> "Note If A is an m-by-0 empty matrix and B is a 0-by-n empty matrix, where m and n are positive integers, A*B is an m-by-n matrix of all zeros."


That's good. But I meant also that sum([])=0 and prod([])=1 should be documented somewhere as well. Maybe I just haven't found it yet, though.

Subject: matrix multiplication with zero dimensions

From: Bruno Luong

Date: 7 Jan, 2013 12:15:11

Message: 11 of 12

"Matt J" wrote in message <kcebci$l59$1@newscl01ah.mathworks.com>...
> But I meant also that sum([])=0 and prod([])=1 should be documented somewhere as well. Maybe I just haven't found it yet, though.

For an abelian's group, the sum/product (operator that operates on the group) of an empty set is always the *unity element* of the group.

http://pine.cs.yale.edu/pinewiki/SummationNotation (see "3. products").

Bruno

Subject: matrix multiplication with zero dimensions

From: Steven_Lord

Date: 7 Jan, 2013 15:20:29

Message: 12 of 12



"Matt J " <mattjacREMOVE@THISieee.spam> wrote in message
news:kcd527$hou$1@newscl01ah.mathworks.com...
> "Bruno Luong" <b.luong@fogale.findmycountry> wrote in message
> <kcd1lg$6u4$1@newscl01ah.mathworks.com>...
>> "Matt J" wrote in message <kcd0g0$34t$1@newscl01ah.mathworks.com>...
>>
>>
>> Just like sum([]), prod([]), this result is no exception so to be
>> documented separately.
> ==============
>
> I can see the rational behind sum([])=0and prod([])=1. It's so that
>
> sum([A,[]],2)=sum(A,2)+sum([])
> prod([A,[]],2)=prod(A,2)*prod([])

Why does SUM of an empty vector return 0 and PROD of an empty vector return
1? Convention.

http://en.wikipedia.org/wiki/Empty_sum
http://en.wikipedia.org/wiki/Empty_product

Now [] is a 0-by-0 empty matrix not an empty vector and so technically
sum([]) should return a 1-by-0 empty instead of 0, but for that explanation
I'm pretty sure you'd have to ask Cleve.

> I do not see the rationale behind the originally posted relationship,
> though. Taking a slightly different example, I can see perhaps that
>
> ones(3,0)*ones(0,3)
>
> should end up being 3x3 because of the outer dimensions, but why should it
> end up containing zeros.

The definition for matrix multiplication plus the MATLAB rule for SUM is why
the result is all zeros.

If C = A*B, then:

1) size(A, 2) must equal size(B, 1)
2) C will be a matrix of size [size(A, 1), size(B, 2)]
3) C(r, c) is the sum of A(r, :) .* (B(:, c).'). This is the definition of
matrix multiplication (slightly tweaked to use MATLAB notation and abide by
the rules about compatible sizes for the .* operator.)

In this case size(A) is [3 0] and size(B) is [0 3] and condition 1 is
satisfied. The resulting C is of size [3 3] and if we compute C(1, 1) we
have:

>> A = zeros(3, 0);
>> B = zeros(0, 3);
>> % C(1, 1) = A(1, :) .* (B(:, 1).')
>> A(1, :).*(B(:, 1).')
ans =
   Empty matrix: 1-by-0

Since this is an empty vector, its SUM is zero.

>> sum(ans)
ans =
     0

This generalizes to the rest of the elements of C.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Tags for this Thread

No tags are associated with 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