fmincon Solves a multi-variable constrainted optimization problem. Calling Sequence xopt = fmincon(f,x0,A,b) xopt = fmincon(f,x0,A,b,Aeq,beq) xopt = fmincon(f,x0,A,b,Aeq,beq,lb,ub) xopt = fmincon(f,x0,A,b,Aeq,beq,lb,ub,nlc) xopt = fmincon(f,x0,A,b,Aeq,beq,lb,ub,nlc,options) [xopt,fopt] = fmincon(.....) [xopt,fopt,exitflag]= fmincon(.....) [xopt,fopt,exitflag,output]= fmincon(.....) [xopt,fopt,exitflag,output,lambda]=fmincon(.....) [xopt,fopt,exitflag,output,lambda,gradient]=fmincon(.....) [xopt,fopt,exitflag,output,lambda,gradient,hessian]=fmincon(.....) Input Parameters f : A function, representing the objective function of the problem. x0 : A vector of doubles, containing the starting values of variables of size (1 X n) or (n X 1) where 'n' is the number of variables. A : A matrix of doubles, containing the coefficients of linear inequality constraints of size (m X n) where 'm' is the number of linear inequality constraints. b : A vector of doubles, related to 'A' and represents the linear coefficients in the linear inequality constraints of size (m X 1). Aeq : A matrix of doubles, containing the coefficients of linear equality constraints of size (m1 X n) where 'm1' is the number of linear equality constraints. beq : A vector of double, vector of doubles, related to 'Aeq' and represents the linear coefficients in the equality constraints of size (m1 X 1). lb : A vector of doubles, containing the lower bounds of the variables of size (1 X n) or (n X 1) where 'n' is the number of variables. ub : A vector of doubles, containing the upper bounds of the variables of size (1 X n) or (n X 1) where 'n' is the number of variables. nlc : A function, representing the Non-linear Constraints functions(both Equality and Inequality) of the problem. It is declared in such a way that non-linear inequality constraints (c), and the non-linear equality constraints (ceq) are defined as separate single row vectors. options : A list, containing the option for user to specify. See below for details. Outputs xopt : A vector of doubles, containing the computed solution of the optimization problem. fopt : A double, containing the value of the function at x. exitflag : An integer, containing the flag which denotes the reason for termination of algorithm. See below for details. output : A structure, containing the information about the optimization. See below for details. lambda : A structure, containing the Lagrange multipliers of the lower bounds, upper bounds and constraints at the optimized point. See below for details. gradient : A vector of doubles, containing the objective's gradient of the solution. hessian : A matrix of doubles, containing the Lagrangian's hessian of the solution. Description Search the minimum of a constrained optimization problem specified by: Find the minimum of f(x) such that \begin{eqnarray} &\mbox{min}_{x}\ f(x) \\ & \text{Subjected to}\\ & & A\boldsymbol{\cdot} x \leq b \\ & &A_{eq}\boldsymbol{\cdot} {x} = b_{eq}\\ & &c(x) \leq 0\\ & &c_{eq}(x) \ = 0\\ & &lb \leq x \leq ub \\ \end{eqnarray} fmincon calls Ipopt, an optimization library written in C++, to solve the Constrained Optimization problem. Options The options allow the user to set various parameters of the Optimization problem. The syntax for the options is given by: options= list("MaxIter", [---], "CpuTime", [---], "GradObj", ---, "Hessian", ---, "GradCon", ---); The options should be defined as type "list" and consist of the following fields: MaxIter : A Scalar, specifying the maximum number of iterations that the solver should take. CpuTime : A Scalar, specifying the maximum amount of CPU time in seconds that the solver should take. GradObj : A function, representing the gradient function of the Objective in vector form. Hessian : A function, representing the hessian function of the Lagrange in the form of a Symmetric Matrix with Input parameters as x, Objective factor and Lambda. Refer to Example 5 for definition of Lagrangian Hessian function. GradCon : A function, representing the gradient of the Non-Linear Constraints (both Equality and Inequality) of the problem. It is declared in such a way that gradient of non-linear inequality constraints are defined first as a separate Matrix (cg of size m2 X n or as an empty), followed by gradient of non-linear equality constraints as a separate matrix (ceqg of size m2 X n or as an empty) where m2 & m3 are number of non-linear inequality and equality constraints respectively. 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: 0 : Optimal Solution Found 1 : Maximum Number of Iterations Exceeded. Output may not be optimal. 2 : Maximum amount of CPU Time exceeded. Output may not be optimal. 3 : Stop at Tiny Step. 4 : Solved To Acceptable Level. 5 : Converged to a point of local infeasibility. 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. output.Iterations: The number of iterations performed. output.Cpu_Time : The total cpu-time taken. output.Objective_Evaluation: The number of Objective Evaluations performed. output.Dual_Infeasibility : The Dual Infeasiblity of the final soution. output.Message: The output message for the problem. 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. lambda.lower: The Lagrange multipliers for the lower bound constraints. lambda.upper: The Lagrange multipliers for the upper bound constraints. lambda.eqlin: The Lagrange multipliers for the linear equality constraints. lambda.ineqlin: The Lagrange multipliers for the linear inequality constraints. lambda.eqnonlin: The Lagrange multipliers for the non-linear equality constraints. lambda.ineqnonlin: The Lagrange multipliers for the non-linear inequality constraints. A few examples displaying the various functionalities of fmincon have been provided below. You will find a series problems and the appropriate code snippets to solve them. Example Here we solve a simple non-linear objective function, subjected to three linear inequality constraints. Find x in R^2 such that it minimizes: \begin{eqnarray} \mbox{min}_{x}\ f(x) = x_{1}^{2} - x_{1} \boldsymbol{\cdot} x_{2}/3 + x_{2}^{2} \end{eqnarray} \\\text{Subjected to:}\\ \begin{eqnarray} \hspace{70pt} &x_{1} + x_{2}&\leq 2\\ \hspace{70pt} &x_{1} + x_{2}/4&\leq 1\\ \hspace{70pt} &-x_{1} + x_{2}&\geq -1\\ \end{eqnarray} Example Here we build up on the previous example by adding linear equality constraints. We add the following constraints to the problem specified above: \begin{eqnarray} &x_{1} - x_{2}&= 1 \\&2x_{1} + x_{2}&= 2 \\ \end{eqnarray} Example In this example, we proceed to add the upper and lower bounds to the objective function. \begin{eqnarray} -1 &\leq x_{1} &\leq \infty\\ -\infty &\leq x_{2} &\leq 1 \end{eqnarray} Example Finally, we add the non-linear constraints to the problem. Note that there is a notable difference in the way this is done as compared to defining the linear constraints. \begin{eqnarray} x_{1}^2-1&\leq 0\\ x_{1}^2+x_{2}^2-1&\leq 0\\ \end{eqnarray} Example Additional Functionality: We can further enhance the functionality of fmincon by setting input options. We can pre-define the gradient of the objective function and/or the hessian of the lagrange function and thereby improve the speed of computation. This is elaborated on in example 5. We take the following problem and add simple non-linear constraints, specify the gradients and the hessian of the Lagrange Function. We also set solver parameters using the options. \begin{eqnarray} \mbox{min}_{x}\ f(x)= x_{1}*x_{2} + x_{2}*x_{3} \end{eqnarray} \\ \text{Subjected to:}\\ \begin{eqnarray} \hspace{70pt} &c_{1}: x_{1}^2 - x_{2}^2 + x_{3}^2&\leq 2 \\ \hspace{70pt} &c_{2}: x_{1}^2 + x_{2}^2 + x_{3}^2&\leq 10 \end{eqnarray} Example Infeasible Problems: Find x in R^2 such that it minimizes: \begin{eqnarray} f(x) = x_{1}^{2} - x_{1} \boldsymbol{\cdot} x_{2}/3 + x_{2}^{2} \end{eqnarray} \\\text{Subjected to:}\\ \begin{eqnarray} \hspace{70pt} &x_{1} + x_{2}&\leq 2\\ \hspace{70pt} &x_{1} + x_{2}/4&\leq 1\\ \hspace{70pt} &-x_{1} + x_{2}&\geq -1\\ \hspace{70pt} &x_{1} + x_{2}&= 2 \end{eqnarray} Example Unbounded Problems: Find x in R^2 such that it minimizes: \begin{eqnarray} f(x) = x_{1} \boldsymbol{\cdot} x_{2}/3 - x_{1}^{2} - x_{2}^{2} \end{eqnarray} \\\text{Subjected to:}\\ \begin{eqnarray} \hspace{70pt} &x_{1} + x_{2}&\geq 2\\ \hspace{70pt} &x_{1} + x_{2}&\geq -1 \\\end{eqnarray} Authors R.Vidyadhar , Vignesh Kannan