Purpose
To explore random matrices

> library(RColorBrewer)
> cols <- brewer.pal(4, "Set1")

Generate a random matrix

> m <- 25
> A <- matrix(data = 0, nrow = m, ncol = m)
> set.seed(12345)
> for (j in 1:m) {
+     A[, j] <- rnorm(mean = 0, sd = 1/sqrt(m), n = m)
+ }

What do the eigenvalues of a random matrix look like?

> plot(eigen(A)$values, pch = 19, col = cols[1])

Exer_12_3-003.jpg


What happens, say, if you take 100 random matrices and superimpose all their eigenvalues in a single plot? If you do this for m = 8,16, 32, 64,…, what pattern is suggested?

m = 8

> set.seed(12345)
> m <- 8
> eigvals <- matrix(data = 0, nrow = m, ncol = 100)
> for (k in 1:100) {
+     A <- matrix(data = 0, nrow = m, ncol = m)
+     for (j in 1:m) {
+         A[, j] <- rnorm(mean = 0, sd = 1/sqrt(m), n = m)
+     }
+     eigvals[, k] <- as.real(eigen(A)$values)
+ }
> cols <- rainbow(100)
> k <- 1
> ran <- range(as.vector(eigvals))
> plot.new()
> for (k in 1:100) {
+     par(new = T)
+     plot(eigvals[, k], pch = 19, col = cols[k], ylim = ran, xlab = "",
+         ylab = "", main = "8 by 8 ")
+ }

Exer_12_3-004.jpg

m = 16

> set.seed(12345)
> m <- 16
> eigvals <- matrix(data = 0, nrow = m, ncol = 100)
> for (k in 1:100) {
+     A <- matrix(data = 0, nrow = m, ncol = m)
+     for (j in 1:m) {
+         A[, j] <- rnorm(mean = 0, sd = 1/sqrt(m), n = m)
+     }
+     eigvals[, k] <- as.real(eigen(A)$values)
+ }
> cols <- rainbow(100)
> k <- 1
> ran <- range(as.vector(eigvals))
> plot.new()
> for (k in 1:100) {
+     par(new = T)
+     plot(eigvals[, k], pch = 19, col = cols[k], ylim = ran, xlab = "",
+         ylab = "", main = "16 by 16 ")
+ }

Exer_12_3-005.jpg

m = 32

> set.seed(12345)
> m <- 32
> eigvals <- matrix(data = 0, nrow = m, ncol = 100)
> for (k in 1:100) {
+     A <- matrix(data = 0, nrow = m, ncol = m)
+     for (j in 1:m) {
+         A[, j] <- rnorm(mean = 0, sd = 1/sqrt(m), n = m)
+     }
+     eigvals[, k] <- as.real(eigen(A)$values)
+ }
> cols <- rainbow(100)
> k <- 1
> ran <- range(as.vector(eigvals))
> plot.new()
> for (k in 1:100) {
+     par(new = T)
+     plot(eigvals[, k], pch = 19, col = cols[k], ylim = ran, xlab = "",
+         ylab = "", main = "32 by 32 ")
+ }

Exer_12_3-006.jpg

m = 64

> set.seed(12345)
> m <- 64
> eigvals <- matrix(data = 0, nrow = m, ncol = 100)
> for (k in 1:100) {
+     A <- matrix(data = 0, nrow = m, ncol = m)
+     for (j in 1:m) {
+         A[, j] <- rnorm(mean = 0, sd = 1/sqrt(m), n = m)
+     }
+     eigvals[, k] <- as.real(eigen(A)$values)
+ }
> cols <- rainbow(100)
> k <- 1
> ran <- range(as.vector(eigvals))
> plot.new()
> for (k in 1:100) {
+     par(new = T)
+     plot(eigvals[, k], pch = 19, col = cols[k], ylim = ran, xlab = "",
+         ylab = "", main = "64 by 64 ")
+ }

Exer_12_3-007.jpg

m = 128

> set.seed(12345)
> m <- 128
> eigvals <- matrix(data = 0, nrow = m, ncol = 100)
> for (k in 1:100) {
+     A <- matrix(data = 0, nrow = m, ncol = m)
+     for (j in 1:m) {
+         A[, j] <- rnorm(mean = 0, sd = 1/sqrt(m), n = m)
+     }
+     eigvals[, k] <- as.real(eigen(A)$values)
+ }
> cols <- rainbow(100)
> k <- 1
> ran <- range(as.vector(eigvals))
> plot.new()
> for (k in 1:100) {
+     par(new = T)
+     plot(eigvals[, k], pch = 19, col = cols[k], ylim = ran, xlab = "",
+         ylab = "", main = "128 by 128 ")
+ }

Exer_12_3-008.jpg

The distribution tends to narrow as increase m

All Eigen values in the same plot

> plot(as.vector(eigvals), pch = 19, col = cols[1], ylim = ran,
+     xlab = "", ylab = "", main = "128 by 128 ")

Exer_12_3-009.jpg


m = 8

> set.seed(12345)
> m <- 8
> eigvals <- matrix(data = 0, nrow = 1, ncol = 100)
> for (k in 1:100) {
+     A <- matrix(data = 0, nrow = m, ncol = m)
+     for (j in 1:m) {
+         A[, j] <- rnorm(mean = 0, sd = 1/sqrt(m), n = m)
+     }
+     eigvals[, k] <- max(abs(as.real(eigen(A)$values)))
+ }
> ran <- range(as.vector(eigvals))
> plot(as.vector(eigvals), pch = 19, col = "blue", ylim = ran,
+     xlab = "", ylab = "", main = "8 by 8 ")

Exer_12_3-010.jpg

m = 16

> set.seed(12345)
> m <- 16
> eigvals <- matrix(data = 0, nrow = 1, ncol = 100)
> for (k in 1:100) {
+     A <- matrix(data = 0, nrow = m, ncol = m)
+     for (j in 1:m) {
+         A[, j] <- rnorm(mean = 0, sd = 1/sqrt(m), n = m)
+     }
+     eigvals[, k] <- max(abs(as.real(eigen(A)$values)))
+ }
> ran <- range(as.vector(eigvals))
> plot(as.vector(eigvals), pch = 19, col = "blue", ylim = ran,
+     xlab = "", ylab = "", main = "16 by 16 ")

Exer_12_3-011.jpg

m = 32

> set.seed(12345)
> m <- 32
> eigvals <- matrix(data = 0, nrow = 1, ncol = 100)
> for (k in 1:100) {
+     A <- matrix(data = 0, nrow = m, ncol = m)
+     for (j in 1:m) {
+         A[, j] <- rnorm(mean = 0, sd = 1/sqrt(m), n = m)
+     }
+     eigvals[, k] <- max(abs(as.real(eigen(A)$values)))
+ }
> ran <- range(as.vector(eigvals))
> plot(as.vector(eigvals), pch = 19, col = "blue", ylim = ran,
+     xlab = "", ylab = "", main = "32 by 32 ")

Exer_12_3-012.jpg

m = 64

> set.seed(12345)
> m <- 64
> eigvals <- matrix(data = 0, nrow = 1, ncol = 100)
> for (k in 1:100) {
+     A <- matrix(data = 0, nrow = m, ncol = m)
+     for (j in 1:m) {
+         A[, j] <- rnorm(mean = 0, sd = 1/sqrt(m), n = m)
+     }
+     eigvals[, k] <- max(abs(as.real(eigen(A)$values)))
+ }
> ran <- range(as.vector(eigvals))
> plot(as.vector(eigvals), pch = 19, col = "blue", ylim = ran,
+     xlab = "", ylab = "", main = "64 by 64 ")

Exer_12_3-013.jpg

m = 128

> set.seed(12345)
> m <- 128
> eigvals <- matrix(data = 0, nrow = 1, ncol = 100)
> for (k in 1:100) {
+     A <- matrix(data = 0, nrow = m, ncol = m)
+     for (j in 1:m) {
+         A[, j] <- rnorm(mean = 0, sd = 1/sqrt(m), n = m)
+     }
+     eigvals[, k] <- max(abs(as.real(eigen(A)$values)))
+ }
> ran <- range(as.vector(eigvals))
> plot(as.vector(eigvals), pch = 19, col = "blue", ylim = ran,
+     xlab = "", ylab = "", main = "128 by 128 ")

Exer_12_3-014.jpg

What about condition numbers or more simply, the smallest singular value ?

m = 8

> set.seed(12345)
> m <- 8
> eigvals <- matrix(data = 0, nrow = 1, ncol = 100)
> for (k in 1:100) {
+     A <- matrix(data = 0, nrow = m, ncol = m)
+     for (j in 1:m) {
+         A[, j] <- rnorm(mean = 0, sd = 1/sqrt(m), n = m)
+     }
+     eigvals[, k] <- min(abs(as.real(eigen(A)$values)))
+ }
> ran <- range(as.vector(eigvals))
> plot(as.vector(eigvals), pch = 19, col = "blue", ylim = ran,
+     xlab = "", ylab = "", main = "8 by 8 ")

Exer_12_3-015.jpg

> hist(eigvals, fill = "blue")

Exer_12_3-016.jpg

m = 128

> set.seed(12345)
> m <- 128
> eigvals <- matrix(data = 0, nrow = 1, ncol = 100)
> for (k in 1:100) {
+     A <- matrix(data = 0, nrow = m, ncol = m)
+     for (j in 1:m) {
+         A[, j] <- rnorm(mean = 0, sd = 1/sqrt(m), n = m)
+     }
+     eigvals[, k] <- min(abs(as.real(eigen(A)$values)))
+ }
> ran <- range(as.vector(eigvals))
> plot(as.vector(eigvals), pch = 19, col = "blue", ylim = ran,
+     xlab = "", ylab = "", main = "128 by 128 ")

Exer_12_3-017.jpg

> hist(eigvals, fill = "blue")

Exer_12_3-018.jpg