## 10Nonlinear Least Squares Problems

The TOMLAB bundle testprob provides three sets of test problems for (constrained) nonlinear least squares: cls_prob, mgh_prob and ls_prob.

### 10.1  An example of a (constrained) nonlinear least squares

The basic structure of a (constrained) nonlinear least squares problem is the following

 min x
f(x) =
1
2
r(x)T r(x)

s/t
 xL ≤ x ≤ xU, bL ≤ A x ≤ bU cL ≤ c(x) ≤ cU
(12)
where x, xL, xU Rn, r(x) RM, A Rm1 × n, bL,bU Rm1 and cL,c(x),cU Rm2. The following file defines and solves a problem in TOMLAB.

The following files are required to define a problem of this category in TOMLAB.

File: tomlab/quickguide/nllsQG_r.m, nllsQG_J.m
```  r:   Residual vector
J:   Jacobian matrix
```
The following file illustrates how to solve an NLLS problem in TOMLAB. Also view the m-files specified above for more information.

File: tomlab/quickguide/nllsQG.m

An example of a problem of this class, (that is also found in the TOMLAB Quickguide) is nllsQG:
```% nllsQG is a small example problem for defining and solving
% nonlinear least squares using the TOMLAB format.
Name='Gisela';

t = [0.25; 0.5; 0.75; 1; 1.5; 2; 3; 4; 6; 8; 12; 24; 32; 48; 54; 72; 80;...
96; 121; 144; 168; 192; 216; 246; 276; 324; 348; 386];
y = [30.5; 44; 43; 41.5; 38.6; 38.6; 39; 41; 37; 37; 24; 32; 29; 23; 21;...
19; 17; 14; 9.5; 8.5; 7; 6; 6; 4.5; 3.6; 3; 2.2; 1.6];

x_0 = [6.8729, 0.0108, 0.1248]';

% See help clsAssign for more information.
Prob = clsAssign('nllsQG_r', 'nllsQG_J', [], [], [], Name, x_0, ...
y, t);

% Parameter which is passed to r and J routines.
Prob.uP = 5;

Result = tomRun('clsSolve', Prob, 1);
%Result = tomRun('nlssol', Prob, 1);

% Any nonlinear solver can be used. TOMLAB automatically
% uses gateway routines for problem mapping.

%Result = tomRun('filterSQP', Prob, 1);
%Result = tomRun('knitro', Prob, 1);
%Result = tomRun('conopt', Prob, 1);
%Result = tomRun('snopt', Prob, 1);
%Result = tomRun('npsol', Prob, 1);
%Result = tomRun('minos', Prob, 1);
%Result = tomRun('oqnlp', Prob, 1);```

### 10.2cls_prob

cls_prob consists of 45 constrained nonlinear least squares test problems with up to 14 variables and a mixture of linear and nonlinear constraints. In order to define this problem and solve it execute the following in Matlab:
```  Prob   = probInit('cls_prob',1);
Result = tomRun('',Prob);
```

### 10.3mgh_prob

In `mgh_prob` there are 35 nonlinear least squares (More, Garbow, Hillstrom) test problems with up to 40 variables. In order to define this problem and solve it execute the following in Matlab:
```  Prob   = probInit('mgh_prob',1);
Result = tomRun('',Prob);
```

### 10.4ls_prob

In `ls_prob` there are 15 nonlinear least squares test problems with up to 20 variables. In order to define this problem and solve it execute the following in Matlab:
```  Prob   = probInit('ls_prob',1);
Result = tomRun('',Prob);
```