Last active
November 13, 2022 00:06
-
-
Save nicoguaro/121fc88da0ed4335ab5687aaddbcaad7 to your computer and use it in GitHub Desktop.
Eigenvalues for random matrices
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment