# Optimization

`qpsol`
```[x, obj, info, lambda]
= qpsol (x, H, c, lb, ub, lb, A, ub)
```
Solve quadratic programs using Gill and Murray's QPSOL. Because QPSOL is not freely redistributable, this function is only available if you have obtained your own copy of QPSOL. See section Installing Octave.

Tolerances and other options for `qpsol` may be specified using the function `qpsol_options`.

## Nonlinear Programming

`npsol`
```[x, obj, info, lambda]
= npsol (x, 'phi', lb, ub, lb, A, ub, lb, 'g', ub)
```
Solve nonlinear programs using Gill and Murray's NPSOL. Because NPSOL is not freely redistributable, this function is only available if you have obtained your own copy of NPSOL. See section Installing Octave. The second argument is a string containing the name of the objective function to call. The objective function must be of the form
```y = phi (x)
```
where x is a vector and y is a scalar.

Tolerances and other options for `npsol` may be specified using the function `npsol_options`.

## Linear Least Squares

`gls (Y, X, O)`
Generalized least squares (GLS) estimation for the multivariate model
```Y = X * B + E,  mean(E) = 0,  cov(vec(E)) = (s^2)*O
```
with
```Y an T x p matrix
X an T x k matrix
B an k x p matrix
E an T x p matrix
O an Tp x Tp matrix
```
Each row of Y and X is an observation and each column a variable. Returns BETA, v, and, R, where BETA is the GLS estimator for B, v is the GLS estimator for s^2, and R = Y - X*BETA is the matrix of GLS residuals.
`ols (Y, X)`
Ordinary Least Squares (OLS) estimation for the multivariate model
```Y = X*B + E,  mean (E) = 0,  cov (vec (E)) = kron (S, I)
```
with
```Y an T x p matrix
X an T x k matrix
B an k x p matrix
E an T x p matrix
```
Each row of Y and X is an observation and each column a variable. Returns BETA, SIGMA, and R, where BETA is the OLS estimator for B, i.e.
```BETA = pinv(X)*Y,
```
where pinv(X) denotes the pseudoinverse of X, SIGMA is the OLS estimator for the matrix S, i.e.
```SIGMA = (Y - X*BETA)'*(Y - X*BETA) / (T - rank(X))
```
and R = Y - X*BETA is the matrix of OLS residuals.