Reputation: 244
I am learning how to plot pdf in gnuplot. The code is sourced from http://gnuplot.sourceforge.net/demo/random.html
the code is
unset contour
unset parametric
load "stat.inc"
print ""
print "Simple Monte Carlo simulation"
print ""
print "The first curve is a histogram where the binned frequency of occurence"
print "of a pseudo random variable distributed according to the normal"
print "(Gaussian) law is scaled such that the histogram converges to the"
print "normal probability density function with increasing number of samples"
print "used in the Monte Carlo simulation. The second curve is the normal"
print "probability density function with unit variance and zero mean."
print ""
nsamp = 5000
binwidth = 20
xlow = -3.0
xhigh = 3.0
scale = (binwidth/(xhigh-xlow))
# Generate N random data points.
set print "random.tmp"
do for [i=1:nsamp] {
print sprintf("%8.5g %8.5g", invnorm(rand(0)), (1.0*scale/nsamp))
}
unset print
#
set samples 200
tstring(n) = sprintf("Histogram of %d random samples from a univariate\nGaussian PDF with unit variance and zero mean", n)
set title tstring(nsamp)
set key
set grid
set terminal png
set output "x.png"
set xrange [-3:3]
set yrange [0:0.45]
bin(x) = (1.0/scale)*floor(x*scale)
plot "random.tmp" using (bin($1)):2 smooth frequency with steps title "scaled bin frequency", normal(x,0,1) with lines title "Gaussian p.d.f."
I get the error
Cannot open load file 'stat.inc'
"stat.inc", line 4: util.c: No such file or directory
The version of gnuplot I am using is gnuplot 4.6 patchlevel 0. Please help as I am unable to locate this particular file or run the code on ubuntu platform.
Upvotes: 1
Views: 2476
Reputation: 3765
you find all that file in the source release of gnuplot. You can download it from sourceforge
you'll find the stat.inc in the demo directory
Upvotes: 1