Sha256: f5533a3fc8c26b69a21bb97f91e345d63ba753d5c6cdabb19f041dc32a022e3a

Contents?: true

Size: 740 Bytes

Versions: 16

Compression:

Stored size: 740 Bytes

Contents

#!/usr/bin/env ruby
# 1-dimensional random work:
# This demonstrates M = 1000 trials of N = 6, 50 and 100 left-or-right steps.
# The distribution of the end points of the trials
# will be Gaussian of standard deviation sqrt(N).

require("gsl")

M = 1000
GSL::Rng.env_setup()
T = GSL::Rng::DEFAULT
seed = 2
rng = GSL::Rng.alloc(T, seed)

h = Array.new(3)
h[0] = GSL::Histogram.alloc(61, -30, 30)
h[1] = GSL::Histogram.alloc(61, -30, 30)
h[2] = GSL::Histogram.alloc(61, -30, 30)

i = 0
for n in [6, 50, 100] do
  M.times do 
    s = 0
    n.times do
      ds = rng.get%2 == 0 ? 1 : -1
      s += ds
    end
    h[i].increment(s)
  end
  i += 1
end

#GSL::graph(h[0].shift(250), h[1].shift(100), h[2])
GSL::graph(h[0] + 250, h[1] + 100, h[2])

Version data entries

16 entries across 16 versions & 4 rubygems

Version Path
rb-gsl-1.16.0.4 examples/random/diffusion.rb
rb-gsl-1.16.0.3 examples/random/diffusion.rb
rb-gsl-1.16.0.3.rc1 examples/random/diffusion.rb
gsl-nmatrix-1.15.3.2 examples/random/diffusion.rb
gsl-nmatrix-1.15.3.1 examples/random/diffusion.rb
rb-gsl-1.16.0.2 examples/random/diffusion.rb
rb-gsl-1.16.0.1 examples/random/diffusion.rb
rb-gsl-1.16.0 examples/random/diffusion.rb
rb-gsl-1.15.3.2 examples/random/diffusion.rb
rb-gsl-1.15.3.1 examples/random/diffusion.rb
blackwinter-gsl-1.15.3.2 examples/random/diffusion.rb
gsl-nmatrix-1.15.3.0 examples/random/diffusion.rb
gsl-1.15.3 examples/random/diffusion.rb
gsl-1.14.7 examples/random/diffusion.rb
gsl-1.14.6 examples/random/diffusion.rb
gsl-1.14.5 examples/random/diffusion.rb