Язык программирования R/Математика: различия между версиями

Содержимое удалено Содержимое добавлено
→‎Matrix calculations: к удалению
Строка 296:
 
==== Транспонирование ====
 
=== Matrix calculations ===
 
* Inner product <tt>X%*%Y</tt>
 
<pre width = 80>
 
> b=matrix(nrow=2,ncol=2,c(1,2,3,4))
> a=matrix(nrow=2,ncol=2,c(1,0,0,-1))
> a
[,1] [,2]
[1,] 1 0
[2,] 0 -1
> b
[,1] [,2]
[1,] 1 3
[2,] 2 4
> a%*%b
[,1] [,2]
[1,] 1 3
[2,] -2 -4
> b%*%a
[,1] [,2]
[1,] 1 -3
[2,] 2 -4
 
</pre>
 
* compute the Kronecker product using <tt>%x%</tt> or <tt>kron()</tt> (fUtilities).
 
<pre width = 80>
> M <- matrix(rep(2,4),nrow = 2)
> M
[,1] [,2]
[1,] 2 2
[2,] 2 2
> I <- eye(2)
> I
[,1] [,2]
[1,] 1 0
[2,] 0 1
> I %x% M
[,1] [,2] [,3] [,4]
[1,] 2 2 0 0
[2,] 2 2 0 0
[3,] 0 0 2 2
[4,] 0 0 2 2
> library(fUtilities)
> kron(I,M)
[,1] [,2] [,3] [,4]
[1,] 2 2 0 0
[2,] 2 2 0 0
[3,] 0 0 2 2
[4,] 0 0 2 2
</pre>
 
* Outer Product X%o%Y
 
=== Matrix transposition ===