This is a Jupyter Notebook that contains Julia code I will run in the first lecture of Spectral Graph Theory. I find experiments to be incredibly useful when working on spectral graph theory. They help me figure out what is true, and they help me find counterexamples to my conjectures.
If you want to try using this, you will need to install Jupyter (via Python), Julia and IJulia. You also need my package, called Laplacians.jl
. It may be added in Julia via
Using Pkg
Pkg.add("Laplacians")
using Laplacians
using LinearAlgebra
using Statistics
using Plots
using SparseArrays
using FileIO
using JLD2
using Random
M = path_graph(4)
Matrix(M)
Matrix(lap(M))
L = lap(path_graph(10))
;
E = eigen(Matrix(L))
println(E.values)
E.vectors[:,1]
v2 = E.vectors[:,2]
plot(v2,marker=5,legend=false)
xlabel!("vertex number")
ylabel!("value in eigenvector")
Plots.plot(E.vectors[:,2],label="v2",marker = 5)
Plots.plot!(E.vectors[:,3],label="v3",marker = 5)
Plots.plot!(E.vectors[:,4],label="v4",marker = 5)
xlabel!("Vertex Number")
ylabel!("Value in Eigenvector")
Plots.plot(E.vectors[:,10],label="v10",marker=5)
xlabel!("Vertex Number")
ylabel!("Value in Eigenvector")
M = grid2(3,4)
L = lap(M)
E = eigen(Matrix(L))
V = E.vectors[:,2:3]
plot_graph(M,V[:,1],V[:,2])
using PyPlot: pygui
pygui(false)
@load "YALE.jld2"
scatter(xy[:,1],xy[:,2],legend=false)
plot_graph(a,xy[:,1],xy[:,2])
plot_graph(a, v2,v3, dots=false)
Random.seed!(1)
p = randperm(size(a,1))
M = a[p,p]
E = eigen(Matrix(lap(M)))
V = E.vectors[:,2:3]
plot_graph(M,V[:,1],V[:,2], dots=false)
M = latin_square_graph(5);
println(eigvals(Matrix(lap(M))))
M = readIJV("dodec.txt")
spectral_drawing(M)
E = eigen(Matrix(lap(M)))
println(E.values)
x = E.vectors[:,2]
y = E.vectors[:,3]
z = E.vectors[:,4]
pygui(false)
plot_graph(M, x, y, z; setaxis=false)
pygui(true)
plot_graph(M, x, y, z; setaxis=false)
x = E.vectors[:,11]
y = E.vectors[:,12]
pygui(false)
plot_graph(M, x, y; setaxis=false)
x = E.vectors[:,11]
y = E.vectors[:,12]
z = E.vectors[:,10]
pygui(true)
plot_graph(M, x, y, z; setaxis=false)