Skip to content

Instantly share code, notes, and snippets.

@zimolzak
Created February 20, 2018 20:15
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 zimolzak/3ecaf5fae6acdc08bd07a83bcac82595 to your computer and use it in GitHub Desktop.
Save zimolzak/3ecaf5fae6acdc08bd07a83bcac82595 to your computer and use it in GitHub Desktop.
How often a random real matrix has complex eigenvalues
from random import uniform
def myvariate():
return uniform(-2,2)
for i in range(1000000):
a = myvariate()
b = myvariate()
c = myvariate()
d = myvariate()
print a**2 + 2*a*d + d**2 - 4*a*d - 4*b*c
all : dist.py
python dist.py > variates.txt
library(ggplot2)
library(e1071)
X = read.csv("../Desktop/variates.txt")
qplot(X[,1])
ggplot(X, aes(X[,1])) + geom_density()
moment(X[,1], order=1)
moment(X[,1], order=2, center=TRUE)
moment(X[,1], order=3, center=TRUE)
moment(X[,1], order=4, center=TRUE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment