diff options
Diffstat (limited to 'macros/lsqlin.sci')
-rw-r--r-- | macros/lsqlin.sci | 45 |
1 files changed, 38 insertions, 7 deletions
diff --git a/macros/lsqlin.sci b/macros/lsqlin.sci index 9460424..532e6ad 100644 --- a/macros/lsqlin.sci +++ b/macros/lsqlin.sci @@ -31,13 +31,13 @@ function [xopt,resnorm,residual,exitflag,output,lambda] = lsqlin (varargin) // lb : a vector of double, contains lower bounds of the variables. // ub : a vector of double, contains upper bounds of the variables. // x0 : a vector of double, contains initial guess of variables. - // param : a list containing the the parameters to be set. + // param : a list containing the parameters to be set. // xopt : a vector of double, the computed solution of the optimization problem. // resnorm : a double, objective value returned as the scalar value norm(C*x-d)^2. // residual : a vector of double, solution residuals returned as the vector d-C*x. - // exitflag : A flag showing returned exit flag from Ipopt. It could be 0, 1 or 2 etc. i.e. Optimal, Maximum Number of Iterations Exceeded, CPU time exceeded. Other flags one can see in the lsqlin macro. - // output : Structure containing information about the optimization. This version only contains number of iterations. - // lambda : Structure containing the Lagrange multipliers at the solution x (separated by constraint type).It contains lower, upper bound multiplier and linear equality, inequality constraint multiplier. + // exitflag : The exit status. See below for details. + // output : The structure consist of statistics about the optimization. See below for details. + // lambda : The structure consist of the Lagrange multipliers at the solution of problem. See below for details. // // Description // Search the minimum of a constrained linear least square problem specified by : @@ -54,6 +54,35 @@ function [xopt,resnorm,residual,exitflag,output,lambda] = lsqlin (varargin) // // The routine calls Ipopt for solving the linear least square problem, Ipopt is a library written in C++. // + // The exitflag allows to know the status of the optimization which is given back by Ipopt. + // <itemizedlist> + // <listitem>exitflag=0 : Optimal Solution Found </listitem> + // <listitem>exitflag=1 : Maximum Number of Iterations Exceeded. Output may not be optimal.</listitem> + // <listitem>exitflag=2 : Maximum CPU Time exceeded. Output may not be optimal.</listitem> + // <listitem>exitflag=3 : Stop at Tiny Step.</listitem> + // <listitem>exitflag=4 : Solved To Acceptable Level.</listitem> + // <listitem>exitflag=5 : Converged to a point of local infeasibility.</listitem> + // </itemizedlist> + // + // For more details on exitflag see the ipopt documentation, go to http://www.coin-or.org/Ipopt/documentation/ + // + // The output data structure contains detailed informations about the optimization process. + // It has type "struct" and contains the following fields. + // <itemizedlist> + // <listitem>output.iterations: The number of iterations performed during the search</listitem> + // <listitem>output.constrviolation: The max-norm of the constraint violation.</listitem> + // </itemizedlist> + // + // 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. + // <itemizedlist> + // <listitem>lambda.lower: The Lagrange multipliers for the lower bound constraints.</listitem> + // <listitem>lambda.upper: The Lagrange multipliers for the upper bound constraints.</listitem> + // <listitem>lambda.eqlin: The Lagrange multipliers for the linear equality constraints.</listitem> + // <listitem>lambda.ineqlin: The Lagrange multipliers for the linear inequality constraints.</listitem> + // </itemizedlist> + // // Examples // //A simple linear least square example // C = [ 2 0; @@ -330,11 +359,13 @@ function [xopt,resnorm,residual,exitflag,output,lambda] = lsqlin (varargin) residual = d-C*xopt; resnorm = residual'*residual; exitflag = status; - output = struct("Iterations" , []); + output = struct("Iterations" , [], .. + "ConstrViolation" ,[]); output.Iterations = iter; + output.ConstrViolation = max([0;norm(Aeq*xopt-beq, 'inf');(lb'-xopt);(xopt-ub');(A*xopt-b)]); lambda = struct("lower" , [], .. - "upper" , [], .. - "eqlin" , [], .. + "upper" , [], .. + "eqlin" , [], .. "ineqlin" , []); lambda.lower = Zl; |