package com.imsl.test.example.math; import com.imsl.math.*; /** *

* Minimizes a nonlinear function with constraints.

* The problem *

* $${\rm {min}} \,\, f(x) = -x_0x_1x_2$$

*

* subject to

* * $$\begin{array}{c} * -x_0 - 2x_1 -2x_2 \le 0 \\ * x_0 + 2x_1 + 2x_2 \le 72 \\ * 0 \le x_0 \le 20 \\ * 0 \le x_1 \le 11 \\ * 0 \le x_2 \le 42 \\ * \end{array}$$ *

* is solved with an initial guess of \( x_0 = 10 \), * \( x_1 = 10 \) and \( x_2 = 10 \).

* * @see Code * @see Output */ public class MinConGenLinEx2 { public static void main(String args[]) throws Exception { int neq = 0; int ncon = 2; int nvar = 3; double a[] = {-1.0, -2.0, -2.0, 1.0, 2.0, 2.0}; double xlb[] = {0.0, 0.0, 0.0}; double xub[] = {20.0, 11.0, 42.0}; double xguess[] = {10.0, 10.0, 10.0}; double b[] = {0.0, 72.0}; MinConGenLin.Gradient grad = new MinConGenLin.Gradient() { public double f(double[] x) { return -x[0] * x[1] * x[2]; } public void gradient(double[] x, double[] g) { g[0] = -x[1] * x[2]; g[1] = -x[0] * x[2]; g[2] = -x[0] * x[1]; } }; MinConGenLin zf = new MinConGenLin(grad, nvar, ncon, neq, a, b, xlb, xub); zf.setGuess(xguess); zf.solve(); new PrintMatrix("Solution").print(zf.getSolution()); System.out.println("Objective value = " + zf.getObjectiveValue()); } }