Filter löschen
Filter löschen

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

4 Ansichten (letzte 30 Tage)
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

Akzeptierte Antwort

Bruno Luong
Bruno Luong am 29 Aug. 2023
Bearbeitet: Bruno Luong am 29 Aug. 2023
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 Kommentare
Bruno Luong
Bruno Luong am 30 Aug. 2023
Bearbeitet: Bruno Luong am 30 Aug. 2023
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 am 30 Aug. 2023
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([]).

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange

Produkte


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by