一、数学上的矩阵运算:
1.生成矩阵:matrix()
> a<-matrix(data = 1:16,nrow = 4)
> a
[,1] [,2] [,3] [,4]
[1,] 1 5 9 13
[2,] 2 6 10 14
[3,] 3 7 11 15
[4,] 4 8 12 16
2.矩阵加法:+ –
> a+a
[,1] [,2] [,3] [,4]
[1,] 2 10 18 26
[2,] 4 12 20 28
[3,] 6 14 22 30
[4,] 8 16 24 32
> a-a
[,1] [,2] [,3] [,4]
[1,] 0 0 0 0
[2,] 0 0 0 0
[3,] 0 0 0 0
[4,] 0 0 0 0
3.矩阵乘法(数乘法: *矩阵乘法:
%
*%)
> 10*a
[,1] [,2] [,3] [,4]
[1,] 10 50 90 130
[2,] 20 60 100 140
[3,] 30 70 110 150
[4,] 40 80 120 160
> a*a
[,1] [,2] [,3] [,4]
[1,] 1 25 81 169
[2,] 4 36 100 196
[3,
版权声明:本文为weixin_33321637原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。