I’ve written a function in C# that does a numerical differentiation. It looks like this:
public double Diff(double x)
{
double h = 0.0000001;
return (Function(x + h) - Function(x)) / h;
}
I would like to be able to pass in any function, as in:
public double Diff(double x, function f)
{
double h = 0.0000001;
return (f(x + h) - f(x)) / h;
}
I think this is possible with delegates (maybe?) but I’m not sure how to use them.
Using the Func as mentioned above works but there are also delegates that do the same task and also define intent within the naming: