hadamard.prod {matrixcalc} | R Documentation |
Hadamard product of two matrices
Description
This function returns the Hadamard or Shur product of two matrices, x and y, that have the same row and column dimensions.
Usage
hadamard.prod(x, y)
Arguments
x |
a numeric matrix or vector object |
y |
a numeric matrix or vector object |
Details
The Hadamard product is an element-by-element product of the two matrices. Let
and
be two
numeric matrices. The Hadamard product is
.
It uses the * operation in R.
Value
A matrix.
Note
The function converts vectors to matrices if necessary. The function stops running if x or y is not numeric and an error message is displayed. The function also stops running if x and y do not have the same row and column dimensions and an error mesage is displayed.
Author(s)
Frederick Novomestky fnovomes@poly.edu
References
Hadamard, J (1983). Resolution d'une question relative aux determinants, Bulletin des Sciences Mathematiques, 17, 240-246.
Styan, G. P. H. (1973). Hadamard Products and Multivariate Statistical Analysis, Linear Algebra and Its Applications, Elsevier, 6, 217-240.
Examples
x <- matrix( c( 1, 2, 3, 4 ), nrow=2, byrow=TRUE )
y <- matrix( c( 2, 4, 6, 8 ), nrow=2, byrow=TRUE )
z <- hadamard.prod( x, y )
print( z )