/usr/share/doc/ruby-gsl/examples/jacobi/interp.rb is in ruby-gsl 2.1.0.3+dfsg1-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | #!/usr/bin/env ruby
require("gsl")
if ARGV.size != 1
puts("Usage: integrate n\nn is the number of quadrature points.")
exit
end
Q = ARGV[0].to_i
if Q < 1
puts("Usage: integrate n\nn is the number of quadrature points.")
exit
end
def fun(x)
Math::cos(3.0*x)
end
def dfun(x)
-3.0*Math::sin(3.0*x)
end
f = GSL::Vector.alloc(4*Q)
xp = GSL::Vector.linspace(0.1, 0.9, 9)
quad = Jac::Quadrature.alloc(Q)
quad.zwd(Jac::GJ, 0.0, 0.0)
quad.interpmat_alloc(xp)
for i in 0...Q do
f[i] = fun(quad.x[i])
end
fout = quad.interpolate(f)
printf("X \t f(x) \t Error\n");
for i in 0...xp.size do
printf("%f \t %f \t %e\n", xp[i], fout[i], fout[i] - fun(xp[i]));
end
quad.interpmat_free
|