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

* Solves a general minimization problem with constraints.

* * The problem *

* $${\rm {min}} \,\, f(x) = x_1^2 + x_2^2 + x_3^2 + x_4^2 + x_5^2 - 2x_2x_3 - * 2x_4x_5 - 2x_1$$

*

* subject to

*

* $$x_1 + x_2 + x_3 + x_4 + x_5 = 5$$
* $$x_3 - 2x_4 - 2x_5 = -3$$
* $$0 \le x \le 10$$

*

* is solved.

* * @see Code * @see Output */ public class MinConGenLinEx1 { public static void main(String args[]) throws Exception { int neq = 2; int ncon = 2; int nvar = 5; double a[] = {1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 1.0, -2.0, -2.0}; double b[] = {5.0, -3.0}; double xlb[] = {0.0, 0.0, 0.0, 0.0, 0.0}; double xub[] = {10.0, 10.0, 10.0, 10.0, 10.0}; MinConGenLin.Function fcn = new MinConGenLin.Function() { @Override public double f(double[] x) { return x[0] * x[0] + x[1] * x[1] + x[2] * x[2] + x[3] * x[3] + x[4] * x[4] - 2.0 * x[1] * x[2] - 2.0 * x[3] * x[4] - 2.0 * x[0]; } }; MinConGenLin zf = new MinConGenLin(fcn, nvar, ncon, neq, a, b, xlb, xub); zf.solve(); new PrintMatrix("Solution").print(zf.getSolution()); } }