# NAME

constrained_least_squares - Solves Ax=b in the least squares sense with linear constraints.

# SYNOPSIS

```#include "n2/n2_quadratic.h"

Example compile flags (system dependent):
-DLINUX_X86_64 -DLINUX_X86_64_OPTERON  -DGNU_COMPILER
-I/home/kobus/include
-lKJB                               -lfftw3  -lgsl -lgslcblas -ljpeg  -lSVM -lstdc++                    -lpthread -lSLATEC -lg2c    -lacml -lacml_mv -lblas -lg2c      -lncursesw

int constrained_least_squares
(
Vector **result_vpp,
const Matrix *A_mp,
const Vector *b_vp,
const Matrix *le_constraint_mp,
const Vector *le_constraint_vp,
const Matrix *eq_constraint_mp,
const Vector *eq_constraint_vp,
const Vector *lb_vp,
const Vector *ub_vp
);
```

# DESCRIPTION

This routine solves Ax=b in the least squares sense subject to linear constraints. Put differently, this routine calculates
```
MIN { || Ax - b ||  }
x                2

Subject to:

Lx <= m
Ex  = e
x <= u
x >= l
```
Note that it is generally easy to convert a basic sum of squared error objective function into Ax=0, least squares sense. The result is put into the vector pointed to by *result_vpp, which is created if it is NULL, resized if it is the wrong sized, and reused otherwise. The number of rows in the matrix pointed to by the argument "A_mp" (i.e, A, above) must be the same as the length of the vector pointed to by the argument "b_vp" (i.e. b, above). In addition, the number of columns of of *A_mp (i.e, number of unknowns) cannot exceed the number of rows of *A_mp (number of equations). With respect to the above formulation, the parameter le_constraint_mp corresponds to L, le_constraint_vp to m, eq_constraint_mp to E, eq_constraint_vp to e, lb_row_arg_vp corresponds to l, and ub_row_arg_vp corresponds to u. Any of these constraint arguments can be set to NULL if there are no constraints of the corresponding type.

# RETURNS

NO_ERROR on success, and ERROR on failure, with an appropriate error message being set.

# DISCLAIMER

This software is not adequatedly tested. It is recomended that results are checked independantly where appropriate.

Kobus Barnard

Kobus Barnard