Sha256: 589b093e1b82452c9c5483cf0c13ee21f4a731b3b22f44bbf96be114fe88b6cf

Contents?: true

Size: 651 Bytes

Versions: 22

Compression:

Stored size: 651 Bytes

Contents

#!/usr/bin/env ruby
require("gsl")
rng = GSL::Rng.alloc()

N = 100
XMAX = 5.0
sigma = 1.0
h = GSL::Histogram.alloc(N, 0, XMAX)
for i in 0...10000 do
  x = rng.rayleigh(sigma)
  h.increment(x)
end

sig, amp = h.fit_rayleigh
p sig
p amp

v = GSL::Vector.linspace(0, XMAX, N)
val = GSL::Ran::rayleigh_pdf(v, sig)
val *= amp
GSL::graph(h, [v, val], "-T X -C")

h2 = GSL::Histogram.alloc(N, 0, XMAX)
for i in 0...10000 do
  x = rng.gaussian(sigma)
  y = rng.gaussian(sigma)
  r = Math.sqrt(x*x + y*y)
  h2.increment(r)
end
sig2, amp2 = h2.fit_rayleigh
p sig2
p amp2
val2 = GSL::Ran::rayleigh_pdf(v, sig2)
val2 *= amp2
GSL::graph(h2, [v, val2], "-T X -C")

Version data entries

22 entries across 22 versions & 4 rubygems

Version Path
gsl-2.1.0.3 examples/random/rayleigh.rb
gsl-2.1.0.2 examples/random/rayleigh.rb
gsl-2.1.0.1 examples/random/rayleigh.rb
gsl-2.1.0 examples/random/rayleigh.rb
gsl-1.16.0.6 examples/random/rayleigh.rb
rb-gsl-1.16.0.5 examples/random/rayleigh.rb
rb-gsl-1.16.0.4 examples/random/rayleigh.rb
rb-gsl-1.16.0.3 examples/random/rayleigh.rb
rb-gsl-1.16.0.3.rc1 examples/random/rayleigh.rb
gsl-nmatrix-1.15.3.2 examples/random/rayleigh.rb
gsl-nmatrix-1.15.3.1 examples/random/rayleigh.rb
rb-gsl-1.16.0.2 examples/random/rayleigh.rb
rb-gsl-1.16.0.1 examples/random/rayleigh.rb
rb-gsl-1.16.0 examples/random/rayleigh.rb
rb-gsl-1.15.3.2 examples/random/rayleigh.rb
rb-gsl-1.15.3.1 examples/random/rayleigh.rb
blackwinter-gsl-1.15.3.2 examples/random/rayleigh.rb
gsl-nmatrix-1.15.3.0 examples/random/rayleigh.rb
gsl-1.15.3 examples/random/rayleigh.rb
gsl-1.14.7 examples/random/rayleigh.rb