Example: Nonlinear Constrained Minimization
On this page Problem Formulation: Rosenbrock’s Function Defining the Problem in Toolbox Syntax Running the Optimization Interpreting the Result

Problem Formulation: Rosenbrock’s Function
Consider the problem of minimizing Rosenbrock’s function

over the unit disk , i.e., the disk of radius 1 centered at the origin. In other words, find x that minimizes the function f(x) over the set nonlinear function with a nonlinear constraint. . This problem is a minimization of a

Note   Rosenbrock’s function is a standard test function in optimization. It has a unique minimum value of 0 attained at the point (1,1). Finding the minimum is a challenge for some algorithms since it has a shallow minimum inside a deeply curved valley. Here are two views of Rosenbrock’s function in the unit disk. The vertical axis is log−scaled; in other words, the plot shows log(1+f(x)). Contour lines lie beneath the surface plot. Rosenbrock’s function, log−scaled: two views.

For more details about maximizing.  Back to Top Defining the Problem in Toolbox Syntax To use Optimization Toolbox software. The inequality is called a constraint. At the command line enter: . All Optimization Toolbox optimization functions minimize an objective function. To maximize a function f. Create a new function file in any text editor. which are inequalities or equations. Define your objective function in the MATLAB language. see Maximizing an Objective. Constraints limit the set of x over which you may search for a minimum. apply an optimization routine to minimize ˘ f. You can have any number of constraints. or use the built−in MATLAB Editor as follows: 1. Code for generating the figure The function f(x) is called the objective function. you need to 1. 2. This is the function you wish to minimize. Function File for Objective Function A function file is a text file containing MATLAB commands with the extension . as a function file or anonymous function. Define your constraint(s) as a separate file or anonymous function.m. This example will use a function file.

The following GUI opens. Save the file unitdisk. Save the file by selecting File > Save .1. File for Constraint Function Constraint functions must be formulated so that they are in the form c(x) 0 or ceq(x)=0. needs to be reformulated as in order to have the Furthermore. Start the Optimization Tool by typing optimtool at the command line. Optimization Tool 1.m . ceq] = unitdisk(x) c = x(1)^2 + x(2)^2 . In the editor enter: function f = rosenbrock(x) f = 100*(x(2) .edit rosenbrock The MATLAB Editor opens. ceq = [ ]. With these considerations in mind. Create a file named unitdisk.x(1)^2)^2 + (1 .m containing the following code: function [c. In this example there is only an inequality constraint. 2. 2. so you must pass an empty array [] as the equality constraint function ceq. The constraint correct syntax. see Minimizing at the Command Line. toolbox functions that accept nonlinear constraints need to have both equality and inequality constraints defined.x(1))^2.  Back to Top Running the Optimization There are two ways to run the optimization: Using the Optimization Tool Graphical User Interface (GUI) Using command line functions. 3. . write a function file for the nonlinear constraint: 1.


since Rosenbrock’s function is nonlinear.m . and the problem has a constraint. 6. For more information about how to choose a solver. The default Solver fmincon . This is the initial point where fmincon begins its search for a minimum. Your Problem Setup and Results pane should match this figure. 7. The @ character indicates that this is a function handle of the file rosenbrock. In the Options pane (center bottom).Constrained nonlinear minimization is selected. click Display to command window . 3. the function handle of unitdisk. Click Start under Run solver and view results . For Nonlinear constraint function enter @unitdisk .For more information about this tool. see Optimization Tool. 5. 2.) This shows the progress of fmincon in the command window. 4. For Objective function enter @rosenbrock .m . see Choosing a Solver. (If you don’t see the option. 8. select iterative in the Level of display pop−up menu. This solver is appropriate for this problem. . For Start point enter [0 0]. In the Algorithm pop−up menu choose Active set ˙the default Trust region reflective algorithm doesn’t handle nonlinear constraints.

Objective function value: 0.[]. fmincon stopped because the predicted change in the objective func is less than the default value of the function tolerance and const are satisfied to within the default value of the constraint tolera Your objective function value may differ slightly.'iter'. and value fval attained by the objective function: [x.The following message appears in the box below the Start button: Optimization running. Exit Flags and Exit Messages discusses exit messages such as these.[]. 1. Run the fmincon solver with the options structure.[]. Constraints satisfied. The constraint is very nearly satisfied. reporting both the location x of the minimizer. .[].[]. Minimizing at the Command Line You can run the same optimization from the command line. depending on your computer system and version of Optimization Toolbox software. The message tells you that: The search for a constrained optimum ended because the derivative of the objective function is nearly 0 in directions allowed by the constraint.options) The six sets of empty brackets represent optional constraints that are not being used in this example.045674808692966654 Local minimum possible. See the fmincon function reference pages for the syntax.fval] = fmincon(@rosenbrock.[0 0].'active-set') 2.... Create an options structure to choose iterative display and the active-set algorithm: options = optimset('Display'. as follows.@unitdisk. The minimizer x appears under Final point . [].'Algorithm'.

0457 The message tells you that the search for a constrained optimum ended because the derivative of the objective function is nearly 0 in directions allowed by the constraint. fmincon stopped because the predicted change in the objective func is less than the default value of the function tolerance and const are satisfied to within the default value of the constraint tolera <stopping criteria details> Active inequalities (to within options.808446 0. and the results of the optimization: Local minimum possible.6783 1 -0.7969 1 -0.07 -0. MATLAB reports the minimization as follows: Max Line search constraint steplength -1 -0.833 -0.7193 1 -0.125 -0.836 0.5 -4. For more details about these links. and that the constraint is very nearly satisfied.TolCon = 1e-006): lower upper ineqlin ineqnonlin 1 x = 0.96 -1.23 -0.0625 -0.908 -0.1592 0.5 Directional Fir derivative opt -2 -2.41 -12.25 -0.340677 0.007618 1 -0.300877 0.003788 0.0750939 0.9375 0.8601 0.164971 0.  Back to Top 0.5 -0.462347 0.284 -2.261949 0.048247 0.912 -1.110766 0.5 -0.5 -0.5 -0.0580974 0.4972 1 -0.6177 Interpreting the Result The iteration table in the command window shows how MATLAB searched for the minimum value of Rosenbrock’s function in the unit disk.0009443 0.0459218 0 0 0 .679 Iter F-count 0 3 1 9 2 16 3 21 4 24 5 27 6 30 7 33 8 36 9 40 10 43 11 47 12 51 13 55 f(x) 1 0. Constraints satisfied.MATLAB outputs a table of iterations. Several phrases in the message contain links that give you more information about the terms used in the message. This table is the same whether you use Optimization Tool or the command line.07 -0.953127 0.0464333 0. see Enhanced Exit Messages .7864 fval = 0.00189 0.3427 1 -0.

at the final iteration. Since the value of unitdisk was nearly 0 at the final iteration. The second column. Acknowledgments .5 0.0456825 0.139 -0.0456785 0. indicating that fmincon evaluated Rosenbrock’s function 79 times in the process of finding a minimum. reports the cumulative number of times Rosenbrock’s function was evaluated. 0.948e-005 -1. 0.4 -0.0457117 0. 0. labeled f(x). This column shows the value of the constraint function unitdisk at each iteration.474e˘005. is the iteration number from 0 to 19. goes from a value of ˘1 at the initial value. The final value. to very nearly 0.5 -0. Inc.5 0. labeled F-count.897e-005 -2.  Back to Top   Was this topic helpful? Yes    No    Product Overview   Example: Linear Programming Terms of Use Patents Trademarks © 1984−2011 The MathWorks. ˘1. there.0002359 -0.0457652 0. The following description applies to the table as displayed.0004719 -0.0456766.5 0.0 This table might differ from yours depending on toolbox version and computing platform. is the minimum that is reported in the Optimization Tool Run solver and view results box.0456912 0. fmincon took 19 iterations to converge.261 -0.474e-005 0. The other columns of the iteration table are described in Iterative Display.0456766 -0.13 0 0. The first column.191 -0.156 -0. Max constraint .5 0.0001179 -5. and at the end of the exit message in the command window.14 15 16 17 18 19 59 63 67 71 75 79 0. The final row shows anF-count of 79. 0. The fourth column. 0. The third column. displays the value of the objective function. labeled Iter.5 0.

Sign up to vote on this title
UsefulNot useful