How to find the cross product of two matrix
>
> D_mat = matrix(c(2, 2, 2, 2, 2, 2), 2, 3)
>
> crossprod(C_mat, D_mat)
[,1] [,2] [,3]
[1,] 6 6 6
[2,] 14 14 14
[3,] 24 24 24
>
> t(C_mat) %*% D_mat
[,1] [,2] [,3]
[1,] 6 6 6
[2,] 14 14 14
[3,] 24 24 24
>
> all.equal(crossprod(C_mat, D_mat), t(C_mat) %*% D_mat)
[1] TRUE
> crossprod(C_mat, C_mat)
[,1] [,2] [,3]
[1,] 5 11 19
[2,] 11 25 43
[3,] 19 43 74
>
> t(C_mat) %*% C_mat
[,1] [,2] [,3]
[1,] 5 11 19
[2,] 11 25 43
[3,] 19 43 74
>
> all.equal(crossprod(C_mat, C_mat), t(C_mat) %*% C_mat)
[1] TRUE
0 Comments