private double derivative(double[] x, int index, double output)
{
// Saves the original parameter value
double original = x[index];
int order = orders[index];
double step = stepSizes[index];
if (original != 0.0)
step *= System.Math.Abs(original);
// Create the interpolation points
var points = new double[pointCount];
int center = (points.Length - 1) / 2;
for (int i = 0; i < points.Length; i++)
{
if (i != center)
{
// Make a small perturbation in the original parameter
x[index] = original + (i - center) * step;
// Recompute the function to measure its importance
points[i] = Function(x);
}
else
{
// The center point is the original function
points[i] = output;
}
}
// Reverts the modified value
x[index] = original;
return Interpolate(coefficients, points, order, center, step);
}