# 訊息

## English

``````> matrix(rep(3,8), nrow=4)
[,1] [,2]
[1,]    3    3
[2,]    3    3
[3,]    3    3
[4,]    3    3
> matrix(3, nrow=4, ncol=3)
[,1] [,2] [,3]
[1,]    3    3    3
[2,]    3    3    3
[3,]    3    3    3
[4,]    3    3    3

> w=matrix(0, nrow=3, ncol=4)
> w
[,1] [,2] [,3] [,4]
[1,]    0    0    0    0
[2,]    0    0    0    0
[3,]    0    0    0    0
> w[2,3]=5
> w
[,1] [,2] [,3] [,4]
[1,]    0    0    0    0
[2,]    0    0    5    0
[3,]    0    0    0    0
>
> x=matrix(1:12, nrow=3, ncol=4)
> x
[,1] [,2] [,3] [,4]
[1,]    1    4    7   10
[2,]    2    5    8   11
[3,]    3    6    9   12
> dim(x)
[1] 3 4
> y = 1:12
> y %*% x

> y = 1:3
> y %*% x
[,1] [,2] [,3] [,4]
[1,]   14   32   50   68
> t(x)
[,1] [,2] [,3]
[1,]    1    2    3
[2,]    4    5    6
[3,]    7    8    9
[4,]   10   11   12
> diag(c(3,7,2))
[,1] [,2] [,3]
[1,]    3    0    0
[2,]    0    7    0
[3,]    0    0    2
> diag(x)
[1] 1 5 9
> det(x)

'x' must be a square matrix
> z = matrix(1:9, nrow=3, ncol=3)
> det(z)
[1] 0
> z
[,1] [,2] [,3]
[1,]    1    4    7
[2,]    2    5    8
[3,]    3    6    9
> z[2,1]=10
> z
[,1] [,2] [,3]
[1,]    1    4    7
[2,]   10    5    8
[3,]    3    6    9
> det(z)
[1] 48
> eigen(z)
\$values
[1] 17.936765+0.000000i -1.468383+0.721055i -1.468383-0.721055i

\$vectors
[,1]                  [,2]                  [,3]
[1,] 0.4100596+0i  0.2162169-0.1118877i  0.2162169+0.1118877i
[2,] 0.6875542+0i -0.8668747+0.0000000i -0.8668747+0.0000000i
[3,] 0.5992665+0i  0.4306386+0.0617265i  0.4306386-0.0617265i

> x
[,1] [,2] [,3] [,4]
[1,]    1    4    7   10
[2,]    2    5    8   11
[3,]    3    6    9   12
> rownames(x) = paste("r", 1:3, sep="_")
> x
[,1] [,2] [,3] [,4]
r_1    1    4    7   10
r_2    2    5    8   11
r_3    3    6    9   12
> colnames(x) = paste("c", 1:4, sep="")
> x
c1 c2 c3 c4
r_1  1  4  7 10
r_2  2  5  8 11
r_3  3  6  9 12
>```
```

# 相關套件

page revision: 0, last edited: 26 Oct 2011 05:01