Sha256: ed3d58572009a74c788e989638a8ae998ce5581c6d321ff86634626bd034b9c4

Contents?: true

Size: 856 Bytes

Versions: 6

Compression:

Stored size: 856 Bytes

Contents

#!/usr/bin/env ruby
require("gsl")
include Math
include GSL

n = 10
xa = Vector[n]
ya = Vector[n]
for i in 0...n do
  a = i.to_f
  xa[i] = i + 0.5*sin(a)
  ya[i] = i + cos(a*a)
end

def spline_compare(type, xa, ya, filename)
  n = xa.size
  spline = Spline.alloc(type, xa, ya)
  p spline.name

  xi = xa[0]
  File.open(filename, "w") do |file|
    while xi < xa[n-1]
      yi = spline.eval(xi)
      file.printf("%e %e\n", xi, yi)
      xi += 0.01
    end
  end
end

types = ["linear", "polynomial", "cspline", "cspline_periodic",
         "akima", "akima_periodic"]

types.each do |t|
  filename = t + ".dat"
  spline_compare(t, xa, ya, filename)
end

#puts("6 interpolation types are examined.")
#puts("Try \"gnuplot -persist spline-compare.gp\"")
system("gnuplot -persist demo.gp")

types.each do |t|
  filename = t + ".dat"
  File.delete(filename)
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
gsl-2.1.0.3 examples/interp/demo.rb
gsl-2.1.0.2 examples/interp/demo.rb
gsl-2.1.0.1 examples/interp/demo.rb
gsl-2.1.0 examples/interp/demo.rb
gsl-1.16.0.6 examples/interp/demo.rb
rb-gsl-1.16.0.5 examples/interp/demo.rb