Example 2: Minimum of a smooth function

The minimum of e^x - 5x is found using function evaluations and first derivative evaluations.
import com.imsl.math.*;

public class MinUnconEx2 implements MinUncon.Derivative {
    public double f(double x) {
        return Math.exp(x) - 5.*x;
    }
    
    public double g(double x) {
        return Math.exp(x) - 5.;
    }
    
    public static void main(String args[]) {
        int	n = 1;
        double	xinit = 0.;
        double	x[] = {0.};
        MinUncon zf = new MinUncon();
        zf.setGuess(xinit);
        zf.setAccuracy(.001);
        MinUnconEx2 fcn = new MinUnconEx2();
        x[0] = zf.computeMin(fcn);
        for (int k = 0;  k < n;  k++) {
            System.out.println("x["+k+"] = "+x[k]);
        }
    }
}

Output

x[0] = 1.6100113162270329
Link to Java source.