-
Notifications
You must be signed in to change notification settings - Fork 22
/
test.R
50 lines (42 loc) · 2.71 KB
/
test.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
> data = complex(real=rnorm(16), imaginary=rnorm(16))
> data
[1] -0.4209720+0.8931618i -0.0506288-0.1393241i 0.1712773-0.5090373i -1.1261630+0.9376884i
[5] -0.9446302+0.4809594i 0.4350762-0.6798474i 1.1376732+0.5828174i -0.9753698+1.2662274i
[9] 1.1347980+1.0438244i 1.1299678+0.4221103i 1.6033854-1.3337606i -0.6119327+0.0123565i
[13] 0.2018914+0.7217532i -0.9584058+0.0647572i 1.0895567-0.5057453i -1.3822117+0.4768580i
> matrix(data=data, nrow=4, ncol=4)
[,1] [,2] [,3] [,4]
[1,] -0.4209720+0.8931618i -0.9446302+0.4809594i 1.1347980+1.0438244i 0.2018914+0.7217532i
[2,] -0.0506288-0.1393241i 0.4350762-0.6798474i 1.1299678+0.4221103i -0.9584058+0.0647572i
[3,] 0.1712773-0.5090373i 1.1376732+0.5828174i 1.6033854-1.3337606i 1.0895567-0.5057453i
[4,] -1.1261630+0.9376884i -0.9753698+1.2662274i -0.6119327+0.0123565i -1.3822117+0.4768580i
> c[lower.tri(c)] = c[upper.tri(c)]
> c
[,1] [,2] [,3] [,4]
[1,] -0.4209720+0.8931618i -0.9446302+0.4809594i 1.134798+1.043824i 0.2018914+0.7217532i
[2,] -0.9446302+0.4809594i 0.4350762-0.6798474i 1.129968+0.422110i -0.9584058+0.0647572i
[3,] 1.1347980+1.0438244i 0.2018914+0.7217532i 1.603385-1.333761i 1.0895567-0.5057453i
[4,] 1.1299678+0.4221103i -0.9584058+0.0647572i 1.089557-0.505745i -1.3822117+0.4768580i
> a = matrix(complex(real=rnorm(8), imaginary = rnorm(8)), nrow=4, ncol=2)
> a
[,1] [,2]
[1,] -0.7939294-1.4826152i 1.965057-0.312665i
[2,] 0.0044153+1.0705172i 1.719627+0.436114i
[3,] 0.5935871+0.0329470i -1.452431+0.368372i
[4,] 0.5640821+0.9536697i -0.912274-1.032309i
> t(a) %*% (a)
[,1] [,2]
[1,] -2.953849+3.478647i -2.887350-2.103881i
[2,] -2.887350-2.103881i 8.271052+1.084526i
> (a) %*% t(a)
[,1] [,2] [,3] [,4]
[1,] 2.195865+1.125374i 5.099183-0.537140i -3.161350+0.271777i -1.149355-3.336773i
[2,] 5.099183-0.537140i 1.620936+1.509361i -2.690941+0.635628i -2.136997-1.564972i
[3,] -3.161350+0.271777i -2.690941+0.635628i 2.325117-1.030956i 2.008700+1.747972i
[4,] -1.149355-3.336773i -2.136997-1.564972i 2.008700+1.747972i -0.824714+2.959394i
> (a %*% t(a)) + c
[,1] [,2] [,3] [,4]
[1,] 1.774893+2.018536i 4.154553-0.056181i -2.026552+1.315602i -0.947463-2.615019i
[2,] 4.154553-0.056181i 2.056012+0.829513i -1.560973+1.057738i -3.095403-1.500215i
[3,] -2.026552+1.315602i -2.489050+1.357381i 3.928502-2.364716i 3.098257+1.242226i
[4,] -0.019387-2.914662i -3.095403-1.500215i 3.098257+1.242226i -2.206926+3.436252i