1.11 Arranging the derivative of a function
The derivative of any function f (x) at x0 can be estimated according to the following formula:Write a program that prints three columns of numbers: x, f (x) and the derivative f '(x) for some simple functions, e.g. sin (x) or arctan(x).
public static class Derrivative
{
public static double Compute(Func<double, double> f, double x0, double h)
{
return (f(x0+h) - f(x0-h)) / (2*h);
}
}
class Program
{
static void Main(string[] args)
{
const int N = 10;
Console.WriteLine("Derivative of sin(x)");
Func<double, double> function = Math.Sin;
for (int i = 0; i < N; i++)
{
Console.WriteLine($"{i}\t{function(i)}\t{Derrivative.Compute(function, i, 0.5)}");
}
Console.WriteLine();
Console.WriteLine("Derivative of arctan(x)");
function = Math.Atan;
for (int i = 0; i < N; i++)
{
Console.WriteLine($"{i}\t{function(i)}\t{Derrivative.Compute(function, i, 0.5)}");
}
Console.ReadLine();
}
}
Kindly, review this source code.