Solves nonnegative least-squares curve fitting problems.
xopt = lsqnonneg(C,d) xopt = lsqnonneg(C,d,options) [xopt,resnorm,residual,exitflag,output,lambda] = lsqnonneg( ... )
A matrix of doubles, representing the multiplier of x in the expression C⋅x - d. The number of columns in C is equal to the number of elements in x.
A vector of doubles, representing the additive constant term in the expression C⋅x - d. The number of elements in d is equal to the number of rows in C matrix.
A list, containing the option for user to specify. See below for details.
A vector of doubles, containing the computed solution of the optimization problem.
A double, containing the objective value returned as a scalar value norm(C⋅x-d)^2.
A vector of doubles, containing the solution residuals, returned as a vector d-C⋅x.
An integer, containing the flag which denotes the reason for termination of algorithm. See below for details.
A structure, containing the information about the optimization. See below for details.
A structure, containing the Lagrange multipliers at the optimized point. See below for details.
Solves nonnegative least-squares curve fitting problems specified by :
lsqlin calls Ipopt, an optimization library written in C++, to solve the nonnegative least-squares curve fitting problem.
The options should be defined as type "list" and consist of the following fields:
options= list("MaxIter", [---], "CpuTime", [---]);
The default values for the various items are given as:
options = list("MaxIter", [3000], "CpuTime", [600]);
The exitflag allows the user to know the status of the optimization which is returned by Ipopt. The values it can take and what they indicate is described below:
For more details on exitflag, see the Ipopt documentation which can be found on http://www.coin-or.org/Ipopt/documentation/
The output data structure contains detailed information about the optimization process. It is of type "struct" and contains the following fields.
The lambda data structure contains the Lagrange multipliers at the end of optimization. In the current version, the values are returned only when the the solution is optimal. It has type "struct" and contains the following fields.
A few examples displaying the various functionalities of lsqnonneg have been provided below. You will find a series of problems and the appropriate code snippets to solve them.
We begin with a simple objective function.
In this example, we further enhance the functionality of qpipopt by setting input options. This provides us with the ability to control the solver parameters such as the maximum number of solver iterations and the max. CPU time allowed for the computation.
// Example 2: A basic lsqnonneg problem with solver options. C = [1 1 1; 1 1 0; 0 1 1; 1 0 0; 0 0 1] d = [89; 67; 53; 35; 20;] options = list("MaxIter", [5000], "CpuTime", [1000]); [xopt,resnorm,residual,exitflag,output,lambda] = lsqnonneg(C,d,options) |