Example: Zeros of a Univariate Function
In this example 3 zeros of the sin function are found.
using System;
using Imsl.Math;
public class ZeroFunctionEx1 : ZeroFunction.IFunction
{
public double F(double x)
{
return Math.Sin(x);
}
public static void Main(String[] args)
{
ZeroFunction.IFunction fcn = new ZeroFunctionEx1();
ZeroFunction zf = new ZeroFunction();
double[] guess = new double[]{5, 18, - 6};
double[] zeros = zf.ComputeZeros(fcn, guess);
for (int k = 0; k < zeros.Length; k++)
{
Console.Out.WriteLine
(zeros[k] + " = " + (zeros[k] / Math.PI) + " pi");
}
}
}
Output
6.28318530717953 = 1.99999999999998 pi
18.8495559215893 = 6.0000000000161 pi
-6.28318530717954 = -1.99999999999999 pi
Link to C# source.