|
| 1 | +#Uses the method of Sturm sequences to compute the histogram of eigenvalues of a matrix |
| 2 | +# |
| 3 | +# Reference |
| 4 | +# Cy P. Chan, "Sturm Sequences and the Eigenvalue Distribution of |
| 5 | +# the Beta-Hermite Random Matrix Ensemble", M.Sc. thesis (MIT), 2007 |
| 6 | +# |
| 7 | +# For better numerical stability, this algorithm is modified so that only the sign |
| 8 | +# of the determinant is stored. |
| 9 | +# |
| 10 | +#For general matrices, this is slower than hist(eigvals(M), bins) and is NOT recommended |
| 11 | +function hist_eig{GridPoint <: Number}(M::AbstractMatrix, bins::Vector{GridPoint}) |
| 12 | + n = size(M)[1] |
| 13 | + NumBins = length(bins) |
| 14 | + histogram = zeros(NumBins) |
| 15 | + SturmSequence = zeros(n) |
| 16 | + for BinId=1:NumBins |
| 17 | + K = M - bins[BinId]*eye(n) |
| 18 | + #Progression of determinants of lower-right submatrices |
| 19 | + #SturmSequence = [det(K[end-j+1:end,end-j+1:end]) for j=1:n] |
| 20 | + #SturmRatioSequence = [SturmSequence[j+1]/SturmSequence[j] for j=1:n] |
| 21 | + |
| 22 | + SturmSequenceSigns = [int(sign(det(K[end-j+1:end,end-j+1:end]))) for j=1:n] |
| 23 | + SturmSequenceSigns = [1; SturmSequenceSigns] |
| 24 | + SturmRatioSequence = [SturmSequenceSigns[j+1]/SturmSequenceSigns[j] for j=1:n] |
| 25 | + histogram[BinId] = sum([r < 0 for r in SturmRatioSequence]) |
| 26 | + end |
| 27 | + histogram = int(diff([histogram; n])) |
| 28 | + return histogram |
| 29 | +end |
| 30 | + |
| 31 | + |
| 32 | + |
| 33 | +#Uses the method of Sturm sequences to compute the histogram of eigenvalues of |
| 34 | +#a symmetric tridiagonal mmatrix |
| 35 | +# |
| 36 | +# Reference |
| 37 | +# Cy P. Chan, "Sturm Sequences and the Eigenvalue Distribution of |
| 38 | +# the Beta-Hermite Random Matrix Ensemble", M.Sc. thesis (MIT), 2007 |
| 39 | +# |
| 40 | +function hist_eig{GridPoint <: Number}(M::SymTridiagonal, bins::Vector{GridPoint}) |
| 41 | + n = size(M)[1] |
| 42 | + NumBins = length(bins) |
| 43 | + histogram = zeros(NumBins) |
| 44 | + r = zeros(n) |
| 45 | + for BinId=1:NumBins |
| 46 | + a, b = M.dv - bins[BinId], M.ev |
| 47 | + #Formula (2.3) |
| 48 | + r[1] = a[1] |
| 49 | + for i=2:n |
| 50 | + r[i] = a[i] - b[i-1]^2/r[i-1] |
| 51 | + end |
| 52 | + histogram[BinId] = sum([SturmRatio < 0 for SturmRatio in r]) |
| 53 | + end |
| 54 | + histogram = int(diff([histogram; n])) |
| 55 | + return histogram |
| 56 | +end |
| 57 | + |
0 commit comments