Numerical Differentiation

All the GSL routines for numerical differentiaion is provided as methods of GSL::Function objects.

Methods

GSL::Function#diff_central(x)
This computes 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)
This computes the numerical derivative of the function at the point x using an adaptive forward difference algorithm.
GSL::Function#diff_backward(x)
This computes the numerical derivative of the function at the point x using an adaptive backward difference algorithm.

Example

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

f = GSL::Function.new { |x|
  GSL::Math::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