/usr/share/doc/ruby-gsl/examples/deriv/diff.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 | #!/usr/bin/env ruby
require("gsl")
f = GSL::Function.alloc { |x|
GSL::pow(x, 1.5)
}
printf("f(x) = x^(3/2)\n");
x = 2.0
result, abserr,status = f.diff_central(x)
printf("x = 2.0\n");
printf("f'(x) = %.10f +/- %.5f\n", result, abserr);
printf("exact = %.10f\n\n", 1.5 * Math::sqrt(2.0));
x = 0.0
result, abserr, status = f.diff_forward(x)
printf("x = 0.0\n");
printf("f'(x) = %.10f +/- %.5f\n", result, abserr);
printf("exact = %.10f\n", 0.0);
f2 = GSL::Function.alloc { |x, a| Math::exp(a*x) }
f2.set_params(2)
p f2.diff_central(0)
f2.set_params(3)
p f2.diff_central(0)
f2.set_params(123)
p f2.diff_central(0)
p GSL::Diff.central(f2, 0)
p GSL::Diff.forward(f2, 0)
p GSL::Diff.backward(f2, 0)
|