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

f = GSL::Function.new { |x|
  if x < 0.5
    0.25
  else
    0.75
  end
}

n = 1000
order = 40
cs = GSL::Cheb.new(order)

#p f
#p f.proc
#p f.params

cs.init(f, 0, 1)
file = File.open("cheb.dat", "w")
for i in 0..n do
  x = i.to_f/n
  r10 = cs.eval_n(10, x)
  r40 = cs.eval(x)
  file.printf("%d %e %e %e %e\n", i, x, f.eval(x), r10, r40)
end
system("gnuplot -persist cheb.gp")
File.delete("cheb.dat")

