All the GSL routines for numerical differentiaion is provided
as methods of GSL::Function objects, and
the singleton methods of the GSL::Diff module. For GSL 1.4.90 or later,
GSL::Deriv module and its singleton methods are also available.
GSL::Function#diff_central(x)GSL::Diff.central(f, x)GSL::Function#diff_forward(x)GSL::Diff.forward(f, x)GSL::Function#diff_backward(x)GSL::Diff.backward(f, x)GSL::Function#deriv_central(x, h)GSL::Deriv.central(f, x, h)GSL::Function#deriv_forward(x, h)GSL::Deriv.forward(f, x, h)GSL::Function#deriv_backward(x, h)GSL::Deriv.backward(f, x, h)#!/usr/bin/env ruby
require "gsl"
f = Function.new { |x|
pow(x, 1.5)
}
printf ("f(x) = x^(3/2)\n");
x = 2.0
result, abserr = 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 = f.diff_forward(x)
printf("x = 0.0\n");
printf("f'(x) = %.10f +/- %.5f\n", result, abserr);
printf("exact = %.10f\n", 0.0);