Skip to content

Commit d80af76

Browse files
committed
bellcurve2 (code 2.1 and 2.2)
1 parent 59356e5 commit d80af76

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

demos/book/2/bellcurve2.jl

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#bellcurve2.jl
2+
#Algorithm 2.1 of Random Eigenvalues by Alan Edelman
3+
4+
#Experiment: Generate random samples from the normal distribution
5+
#Plot: Histogram of random samples
6+
#Theory: The normal distribution curve
7+
8+
9+
## Experiment
10+
t = 1000000 # Trials
11+
dx = 0.25 # binsize
12+
v = randn(t,2) # samples
13+
x = -4:dx:4 # range
14+
15+
## Plot
16+
using Winston
17+
module Plot3D
18+
# Warning: the 3D interface is very new at the time
19+
# of writing this and is likely to not be available
20+
# and/or have changed
21+
if Winston.output_surface == :gtk
22+
include(Pkg.dir("Winston","src","canvas3d_gtk.jl"))
23+
else
24+
include(Pkg.dir("Winston","src","canvas3d.jl"))
25+
end
26+
end
27+
edg1, edg2, count = hist2(v, x-dx/2)
28+
cntrs = (first(x)+dx/2, last(x)-dx/2, length(x)-1)
29+
x,y = meshgrid(cntrs, cntrs)
30+
Plot3D.plot3d(Plot3D.surf(x,y,count./(t*dx^2) *10*length(cntrs)))
31+
Plot3D.plot3d(Plot3D.surf(x,y,exp(-(x.^2+y.^2)/2)/(2*pi) *10*length(cntrs)))

demos/book/2/hist2d.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#hist2d.jl
2+
#Algorithm 2.2 of Random Eigenvalues by Alan Edelman
3+
4+
#see Base.hist2 for a simple implementation

0 commit comments

Comments
 (0)