Skip to content

Commit fde5bea

Browse files
committed
chapter 7 (7.1 and 7.2) eigenvalue sums
1 parent 1656a7e commit fde5bea

File tree

3 files changed

+87
-0
lines changed

3 files changed

+87
-0
lines changed

demos/book/6/.gitignore

Whitespace-only changes.

demos/book/7/centrallimit.jl

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#centrallimit.jl
2+
#Algorithm 7.2 of Random Eigenvalues by Alan Edelman
3+
4+
using Winston
5+
6+
function centrallimit(m, t)
7+
# sums m random matrices and histograms their eigenvalues
8+
# normalized by 1/sqrt(m)
9+
# Input :
10+
# m : number of matrices to sum
11+
# t : number of trials to perform
12+
n = 100 # matrix size
13+
dx = .1 # bin size
14+
v = Float64[]
15+
# we choose a random diagonal {-1,1} matrx as our prototype
16+
# A = diagm(sign(randn(1,n)))
17+
# proto = kron([1 0; 0 -1], eye(n/2))
18+
for i = 1:t # for each trial
19+
B = zeros(n,n) # initialize the accumulator
20+
for z = 1:m # sum up the random matrices
21+
Q = full(QR(randn(n,n) + im*randn(n,n))[:Q]) # (piecewise) Haar orthogonal
22+
A = diagm(sign(randn(n,1)))
23+
B = B + Q'*A*Q # A and Q'AQ are asymptotically free
24+
end
25+
append!(v, real(eigvals(B)/sqrt(m))) # normalize eigenvalues
26+
end
27+
grid, count = hist(v, -2-dx/2:dx:2)
28+
29+
p = FramedPlot()
30+
h = Histogram(count*pi/2/(dx*n*t), step(grid))
31+
h.x0 = first(grid)
32+
add(p, h)
33+
if isinteractive()
34+
Winston.display(p)
35+
else
36+
file(p, "centrallimit_m=$(m)_t=$(t).png")
37+
end
38+
end

demos/book/7/eigfreesum.jl

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#eigfreesum.jl
2+
#Algorithm 7.1 of Random Eigenvalues by Alan Edelman
3+
4+
#Experiment: n by n diagonal matrices with random entries +1 or -1
5+
#Plot: classical and free sums
6+
#Theory: arcsine distribution
7+
8+
## Parameters
9+
t = 1 # number of trials
10+
n = 1000 # size of matrix
11+
dx = .1
12+
13+
## Experiment
14+
function eigfreesum_experiment(t, n, dx)
15+
v = Float64[]
16+
w = Float64[]
17+
for i = 1:t
18+
a = sign(randn(n))
19+
b = sign(randn(n))
20+
Q = full(QR(randn(n,n))[:Q]) # random orthogonal matrix
21+
append!(v, a+b) # classical sum
22+
append!(w, eigvals(diagm(a) + Q'*diagm(b)*Q)) # free sum
23+
end
24+
x = -2-dx/2:dx:2+dx/2
25+
_,countw = hist(w, x)
26+
_,countv = hist(v, x)
27+
x, countw, countv
28+
end
29+
grid, countw, countv = eigfreesum_experiment(t, n, dx)
30+
31+
## Theory
32+
x = -2+dx/20:dx/10:2-dx/20
33+
y = (1/pi) ./ sqrt(4 - x.^2)
34+
35+
## Plot
36+
using Winston
37+
p = FramedPlot()
38+
hw = Histogram(countw*pi/(n*t*dx), step(grid), "color", "blue")
39+
hw.x0 = first(grid)
40+
add(p, hw)
41+
hv = Histogram(countv*pi/(n*t), step(grid), "color", "green")
42+
hv.x0 = first(grid)
43+
add(p, hv)
44+
add(p, Curve(x, y, "color", "red", "linewidth", 2))
45+
if isinteractive()
46+
Winston.display(p)
47+
else
48+
file(p, "eigfreesum.png")
49+
end

0 commit comments

Comments
 (0)