Notes - Tutorial for the Optimization Toolbox...

Info icon This preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Tutorial for the Optimization Toolbox file:///C:/Program%20Files/MATLAB/R2007a%20Student/toolbox/opti... 1 of 11 8/21/2008 5:03 PM Run in the Command Window Tutorial for the Optimization Toolbox This is a demonstration for the medium-scale algorithms in the Optimization Toolbox. It closely follows the Tutorial section of the users' guide. All the principles outlined in this demonstration apply to the other nonlinear solvers: FGOALATTAIN, FMINIMAX, LSQNONLIN, FSOLVE. The routines differ from the Tutorial Section examples in the User's Guide only in that some objectives are anonymous functions instead of M-file functions. Contents Unconstrained Optimization Example Constrained Optimization Example: Inequalities Constrained Optimization Example: Inequalities and Bounds Constrained Optimization Example: User-Supplied Gradients Constrained Optimization Example: Equality Constraints Changing the Default Termination Tolerances Unconstrained Optimization Example Consider initially the problem of finding a minimum of the function: 2 2 f(x) = exp(x(1)) . (4x(1) + 2x(2) + 4x(1).x(2) + 2x(2) + 1) Define the objective to be minimized as an anonymous function: fun = @(x) exp(x(1)) * (4*x(1)^2 + 2*x(2)^2 + 4*x(1)*x(2) + 2*x(2) + 1) fun = @(x)exp(x(1))*(4*x(1)^2+2*x(2)^2+4*x(1)*x(2)+2*x(2)+1) Take a guess at the solution: x0 = [-1; 1]; Set optimization options: turn off the large-scale algorithms (the default): options = optimset( 'LargeScale' , 'off' ); Call the unconstrained minimization function: [x, fval, exitflag, output] = fminunc(fun, x0, options); Optimization terminated: relative infinity-norm of gradient less than options.TolFun. The optimizer has found a solution at: x Open tutdemo.m in the Editor
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Tutorial for the Optimization Toolbox file:///C:/Program%20Files/MATLAB/R2007a%20Student/toolbox/opti... 2 of 11 8/21/2008 5:03 PM x = 0.5000 -1.0000 The function value at the solution is: fval fval = 3.6609e-015 The total number of function evaluations was: output.funcCount ans = 66 Constrained Optimization Example: Inequalities Consider the above problem with two additional constraints: 2 2 minimize f(x) = exp(x(1)) . (4x(1) + 2x(2) + 4x(1).x(2) + 2x(2) + 1) subject to 1.5 + x(1).x(2) - x(1) - x(2) <= 0 - x(1).x(2) <= 10 The objective function this time is contained in an M-file, objfun.m: type objfun function f = objfun(x) % Objective function % Copyright 1990-2004 The MathWorks, Inc. % $Revision: 1.1.6.1 $ $Date: 2006/11/11 22:48:52 $ f = exp(x(1)) * (4*x(1)^2 + 2*x(2)^2 + 4*x(1)*x(2) + 2*x(2) + 1); The constraints are also defined in an M-file, confun.m: type confun function [c, ceq] = confun(x) % Nonlinear inequality constraints: % Copyright 1990-2004 The MathWorks, Inc. % $Revision: 1.1.6.1 $ $Date: 2006/11/11 22:48:27 $ c = [1.5 + x(1)*x(2) - x(1) - x(2);
Image of page 2
Tutorial for the Optimization Toolbox file:///C:/Program%20Files/MATLAB/R2007a%20Student/toolbox/opti... 3 of 11 8/21/2008 5:03 PM -x(1)*x(2) - 10]; % No nonlinear equality constraints: ceq = []; Take a guess at the solution: x0 = [-1 1]; Set optimization options: turn off the large-scale algorithms (the default) and turn on the display of results at each iteration: options = optimset( 'LargeScale' , 'off' , 'Display' , 'iter' ); Call the optimization algorithm. We have no linear equalities or inequalities or bounds, so we pass [] for
Image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern