Example: Zeros of a Univariate Function

In this example 3 zeros of the sin function are found.
using System;
using Imsl.Math;

public class ZerosFunctionEx1 : ZerosFunction.IFunction
{
    public virtual double F(double x)
    {
        return Math.Sin(x);
    }

    public static void  Main(String[] args)
    {

        ZerosFunction.IFunction fcn = new ZerosFunctionEx1();
        
        ZerosFunction zf = new ZerosFunction();
        double[] guess = new double[]{5, 18, - 6};
        zf.SetGuess(guess);
        double[] zeros = zf.ComputeZeros(fcn);
        for (int k = 0; k < zeros.Length; k++)
        {
            Console.Out.WriteLine(zeros[k] + " = " + (zeros[k] / Math.PI) + " pi");
        }
    }
}

Output

-2.953824405026E-22 = -9.40231510170729E-23 pi
3.14159265358979 = 1 pi
6.28318530717959 = 2 pi

Link to C# source.