Example: Zeros of a Univariate Function

In this example 3 zeros of the sin function are found.
import com.imsl.math.*;

public class ZeroFunctionEx1 {
    public static void main(String args[]) {
        
        ZeroFunction.Function fcn = new ZeroFunction.Function() {
            public double f(double x) {
                return Math.sin(x);
            }
        };
        
        ZeroFunction zf = new ZeroFunction();
        double guess[] = {5, 18, -6};
        double zeros[] = zf.computeZeros(fcn, guess);
        for (int k = 0;  k < zeros.length;  k++) {
            System.out.println(zeros[k]+" = "+(zeros[k]/Math.PI) + " pi");
        }
    }
}

Output

6.283185307179534 = 1.9999999999999833 pi
18.84955592158934 = 6.0000000000161 pi
-6.283185307179542 = -1.9999999999999858 pi
Link to Java source.