package com.imsl.test.example.math; import com.imsl.math.*; /** *
* Solves a linear least squares problem * with bounds on the variables.
* * The following example solves a linear least squares problem with bounds on * the variables and compares the result to its unbounded solution. The system * is \( Ax = b \) where $$A =\begin{pmatrix} 1.0 & -3.0 & 2.0 \\ -3.0 & 10.0 & * -5.0 \\ 2.0 & -5.0 & 6.0 \end{pmatrix} $$ ** \( b = (27.0, -78.0, 64.0)^T\) and \( -1.0 \le x_i \le 5.0, i=1,2,3\). *
* * @see Code * @see Output */ public class BoundedVariableLeastSquaresEx1 { public static void main(String args[]) throws Exception { double a[][] = { {1, -3, 2}, {-3, 10, -5}, {2, -5, 6} }; double b[] = {27, -78, 64}; double xlb[] = {-1, -1, -1}; double xub[] = {5, 5, 5}; double xl_ub[] = {Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY}; double xu_ub[] = {Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY}; // compute the bounded solution BoundedVariableLeastSquares bvls = new BoundedVariableLeastSquares(a, b, xlb, xub); bvls.solve(); double[] x_bounded = bvls.getSolution(); new PrintMatrix("Bounded Solution").print(x_bounded); System.out.println("Norm of the Residuals = " + bvls.getResidualNorm()); // compute the unbounded solution bvls = new BoundedVariableLeastSquares(a, b, xl_ub, xu_ub); bvls.solve(); double[] x_unbounded = bvls.getSolution(); new PrintMatrix("\nUnbounded Solution").print(x_unbounded); System.out.println("Norm of the Residuals = " + bvls.getResidualNorm()); } }