Skip to content

Instantly share code, notes, and snippets.

@nicoguaro
Last active November 13, 2022 00:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicoguaro/121fc88da0ed4335ab5687aaddbcaad7 to your computer and use it in GitHub Desktop.
Save nicoguaro/121fc88da0ed4335ab5687aaddbcaad7 to your computer and use it in GitHub Desktop.
Eigenvalues for random matrices
# -*- coding: utf-8 -*-
"""
Eigenvalues for matrices with random entries with values of 1 or -1
@author: Nicolás Guarín-Zapata
@date: November 2022
"""
import numpy as np
import matplotlib.pyplot as plt
repo = "https://raw.githubusercontent.com/nicoguaro/matplotlib_styles/master"
style = repo + "/styles/clean.mplstyle"
plt.style.use(style)
dim = 5
S = 10000
plt.figure(figsize=(8, 8))
for _ in range(S):
M = (np.random.rand(dim, dim) > 0.5).astype(float) - 0.5
eigenvals, _ = np.linalg.eig(2*M)
plt.scatter(np.real(eigenvals), np.imag(eigenvals), s=20,
color='#e41a1c', marker=".", alpha=0.2)
plt.axis("image")
plt.savefig("random_mats_eigs_5x5.svg", bbox_inches="tight")
plt.show()
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment