필터 지우기
필터 지우기

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에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by