# IMSL_LINLSQ

The IMSL_LINLSQ function solves a linear least-squares problem with linear constraints.

Note: This routine requires an IDL Analyst license. For more information, contact your Exelis VIS sales or technical support representative.

The IMSL_LINLSQ function solves linear least-squares problems with linear constraints. These are systems of least-squares equations of the form

Ax ≅ b

subject to

bl ≤ Cx ≤ bu

xl ≤ x ≤ xu

Here A is the coefficient matrix of the least-squares equations, b is the right-hand side, and C is the coefficient matrix of the constraints. The vectors bl, bu, xl and xu are the lower and upper bounds on the constraints and the variables, respectively. The system is solved by defining dependent variables y ≡ Cx and then solving the leastsquares system with the lower and upper bounds on x and y. The equation Cx − y = 0 is a set of equality constraints. These constraints are realized by heavy weighting, i.e., a penalty method, Hanson (1986, pp. 826-834).

## Examples

For additional information on using IMSL_LINLSQ, see Additional Examples.

### Example 1

This example solves the following problem in the least-squares sense:

a = TRANSPOSE([[3.0, 2.0, 1.0], [4.0, 2.0, 1.0], $

[2.0, 2.0, 1.0], [1.0, 1.0, 1.0]])

b = [3.3, 2.3, 1.3, 1.0]

c = [[1.0], [1.0], [1.0]]

xub = [0.5, 0.5, 0.5]

xlb = [0.0, 0.0, 0.0]

contype = [1]

bc = [1.0]

; Note that only upper bound is set for contype =1.

sol = IMSL_LINLSQ(b, a, c, bc, bc, contype, Xlb = xlb, Xub = xub)

PM, sol, Title = 'Solution'

0.500000

0.300000

0.200000

## Syntax

Result = IMSL_LINLSQ( b, a, c, bl, bu, contype [, ABS_TOLERANCE=value] [, /DOUBLE] [, ITMAX=value] [, REL_TOLERANCE=value] [, RESIDUAL=variable] [, XLB=array] [, XUB=array])

## Return Value

One-dimensional array of length nca containing the approximate solution.

## Arguments

### a

Two-dimensional array of size nra by nca containing the coefficients of the leastsquares equations, where nra is the number of least-squares equations and nca is the number of variables.

### B

One-dimensional array of length nra containing the right-hand sides of the least squares equations.

### C

Two-dimensional array of size ncon by nca containing the coefficients of the constraints, where ncon is the number of constraints.

### BL

One-dimensional array of length ncon containing the lower limit of the general constraints. If there is no lower limit on the i-th constraint, then bl(i) will not be referenced.

### BU

One-dimensional array of length ncon containing the upper limit of the general constraints. If there is no upper limit on the i-th constraint, then bu(i) will not be referenced.

### CONTYPE

One-dimensional array of length ncon indicating the type of constraints exclusive of simple bounds, where CONTYPE(i) = 0, 1, 2, 3 indicates =, ≤, ≥, and range constraints, respectively.

## Keywords

### ABS_TOLERANCE

Absolute rank determination tolerance to be used. Default: ABS_TOLERANCE = SQRT(machine epsilon).

### DOUBLE

If present and nonzero, double precision is used.

### ITMAX

Set the maximum number of iterations. Default: ITMAX = 5*max(nra, nca)

### REL_TOLERANCE

Relative rank determination tolerance to be used. Default: REL_TOLERANCE = SQRT(machine epsilon).

### RESIDUAL

Named variable into which an one-dimensional array containing the residuals b − Ax of the least-squares equations at the approximate solution is stored.

### XLB

One-dimensional array of length nca containing the lower bound on the variables. If there is no lower bound on the i-th variable, then Xlb(i) should be set to 1.0e30.

### XUB

One-dimensional array of length nca containing the upper bound on the variables. If there is no upper bound on the i-th variable, then XUB(i) should be set to −1.0e30.

## Additional Examples

### Example 2

The same problem solved in the first example is solved again. This time residuals of the least-squares equations at the approximate solution are returned, and the norm of the residual vector is printed.

a = TRANSPOSE([[3.0, 2.0, 1.0], [4.0, 2.0, 1.0], $

[2.0, 2.0, 1.0], [1.0, 1.0, 1.0]])

b = [3.3, 2.3, 1.3, 1.0]

c = [[1.0], [1.0], [1.0]]

xub = [0.5, 0.5, 0.5]

xlb = [0.0, 0.0, 0.0]

contype = [1]

bc = [1.0]

sol = IMSL_LINLSQ(b, a, c, bc, bc, contype, Xlb = xlb, $

Xub = xub, Residual = residual)

PM, sol, Title = 'Solution'

Solution

0.500000

0.300000

0.200000

PM, residual, Title = 'Residual'

Residual

-1.00000

0.500000

0.500000

0.00000

PRINT, 'Norm of Residual =', IMSL_NORM(residual)

Norm of Residual = 1.22474

## Version History

6.4 | Introduced

## See Also