Numerical Differentiation

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.

Methods

GSL::Function#diff_central(x)
GSL::Diff.central(f, x)
These compute the numerical derivative of the function at the point x using an adaptive central difference algorithm. An array is returned which contain the derivative and an estimate of its absolute error.
GSL::Function#diff_forward(x)
GSL::Diff.forward(f, x)
These compute the numerical derivative of the function at the point x using an adaptive forward difference algorithm.
GSL::Function#diff_backward(x)
GSL::Diff.backward(f, x)
These compute the numerical derivative of the function at the point x using an adaptive backward difference algorithm.

For GSL 1.4.90 or later

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)

Example

#!/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);

back