Is there any matlab documentation that can explain why multiplying empty arrays gives zero matrices?

4 次查看(过去 30 天)
Is there any matlab documentation that can explain why multiplying empty arrays gives zero matrices?
Here is the sample
A=double.empty(5,0);
B=double.empty(0,5);
C=A*B
C =
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0

采纳的回答

Bruno Luong
Bruno Luong 2023-8-29
编辑:Bruno Luong 2023-8-29
From group theory point of view, sum/product (group operator) of an empty set gives the group neutral element. The most basic examples are
sum([])
ans = 0
prod([])
ans = 1
From that property, mathematically by definition of matrix multiplication; the product AB :=A*B of
A = double.empty(m,0)
B = double.empty(0,n)
is equal to
zeros(m,n)
since each element AB(i,j) of A*B is a sum of an empty set.
This is mathematically defined, not MATLAB own convention, no doc description should be necessary.
  24 个评论
Bruno Luong
Bruno Luong 2023-8-30
编辑:Bruno Luong 2023-8-30
a.' performs matrix transposition, if a is column vector as in the context it puts a as row vector
* is matrix multiplication.
So for a and b columns vectors of the same height a.'*b is sum(a.*b)
Actualy the right formula for dot replacement is a'*b not a.'*b as Paul wrote.
Steven Lord
Steven Lord 2023-8-30
The [] matrix in MATLAB is treated kind of specially by a lot of older functions, because as described in the post from Professor Nick Higham's blog that @Dyuman Joshi posted in an earlier comment, in the original version of MATLAB that was the empty matrix.
The behavior of sum of [] returning 0, if you're willing to allow one special quirk of concatenation related to the [] matrix (where it can be concatenated with a vector even though it doesn't have the same number of rows), can be shown as follows. If concatenating a vector and [] together results in that same vector (which it does):
a = 1:5
a = 1×5
1 2 3 4 5
b = [a, []]
b = 1×5
1 2 3 4 5
and if you accept that the sum of the concatenation of two arrays should be the same as the sum of each of those arrays added together:
sum12345 = sum(1:5) % 1:5 is the same as [1:3 4:5]
sum12345 = 15
sum123 = sum(1:3)
sum123 = 6
sum45 = sum(4:5)
sum45 = 9
sum12345 == sum123 + sum45 % true
ans = logical
1
then sum([a []]) equals sum(a) + sum([]). But [a []] is just a, so that simplifies to sum(a) = sum(a) + sum([]). Subtract sum(a) from both sides and 0 = sum([]).

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Operators and Elementary Operations 的更多信息

产品


版本

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by