Vesnog <ongunarisev <at> gmail.com> writes:
>
> My purpose is to plot x vs. summed y values over a certain x interval. How
> can I do so? Later I will calculate the mean, variance and median of the
> data from this plot. I think it should be possible in Gnuplot someway. Any
> help and suggestion is welcome and appreciated.
>
> P.S: I have a RNG and the random numbers generated are given as an argument
> to Gaussian PDF, my aim is to find the mean, variance and median from this
> accumulated data.
>
an example:
we use a simple random generator producing something
like a normal distribution and write the numbers to
a file:
gnuplot> set print 'ts.dat'
gnuplot> do for [i=0:10000] {print
(rand(0)*2.-1.)+(rand(0)*2.-1.)+(rand(0)*2.-1.)}
gnuplot> unset print
we may plot the density function of these numbers by
binning the data and using the 'smooth frequency'
option of the plot command (to give all numbers the
same weight we set the y-value to 1.):
gnuplot> binwidth=0.05
gnuplot> round(x) = floor(x + 0.5)
gnuplot> plot 'ts.dat' using (round($1/binwidth)*binwidth):(1.) smooth
frequency with linespoints
we now have a nice distribution in our plot canvas but
to use these data points we need to write them into a
file:
gnuplot> set table 'ts.tab'
gnuplot> replot
gnuplot> unset table
this file we use for plotting the distribution:
gnuplot> plot 'ts.tab' with linespoints
or for fitting a gaussian function to it:
gnuplot> gauss(x,a,x0,sigma)=a/(sigma*sqrt(2.*pi))*exp(-(x-x0)**2/(2.*sigma**2))
gnuplot> fit gauss(x,a,x0,sigma) 'ts.tab' via a, x0, sigma
gnuplot> plot 'ts.tab' with linespoints, gauss(x,a,x0,sigma)
that's all.
|