
Why does this special case for associativity of a matrix product with a hadamard product hold true?
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Clay Fulcher
el 30 de Dic. de 2024
Comentada: Clay Fulcher
el 30 de Dic. de 2024
I found this very useful mathematical property to hold true for a special case. Can someone show me why?
Let A = m x n matrix.
Let B = n x p matrix.
Let C = 1 x p vector.
When the hadamard product B .* C is performed, Matlab duplicates the rows of C n times to form a n x p matrix C1 with n identical rows.
Then the following expression holds true:
A x (B .* C1) = (A x B) .* C2 where Matlab again duplicates the rows of C, but this time the 1 x p row vector is duplicated m times to form m x p matrix C2.
Example:
A = rand(2,5);
B = rand(5,7);
C = rand(1,7);
D1 = A * (B .* C)
D2 = (A * B) .* C
D1 and D2 are identical.
The reason this is so useful for my application is that A and B are system matrices that are calculated only once, with m << n. C changes thousands of times, so the operation (A x B) .* C is many times faster than A x (B .* C). I need to show why this works mathematically so that I can write it up.
Thank you.
0 comentarios
Respuesta aceptada
Matt J
el 30 de Dic. de 2024
Editada: Matt J
el 30 de Dic. de 2024
It is clear why this happens when n=1, i.e, when A*B is an outer product. But now for arbitrary n, the matrix product can be written as a sum of outer products, so the result follows because Hadamard product distributes into addition.

7 comentarios
Matt J
el 30 de Dic. de 2024
Maybe this is what you are looking for:

where
denotes a column vector of k ones.
Más respuestas (1)
Paul
el 30 de Dic. de 2024
Hi Clay,
If you're willing to accept (or show, which I think would be straight forward) that, in Matlab, matrix .* row is equal to matrix*diag(row), then it follows that the two cases are equal to each other after converting both to ordinary matrix multiplication.
rng(100);
A = rand(2,5);
B = rand(5,7);
C = rand(1,7);
D1 = A * (B .* C);
D2 = (A * B) .* C;
norm(D1 - D2)
D1prime = A*(B*diag(C));
norm(D1-D1prime)
D2prime = (A*B)*diag(C);
norm(D2-D2prime)
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!