Optimize or solve equations in the Live Editor
The Optimize task lets you interactively optimize linear and nonlinear objective functions subject to constraints of various types, and to solve nonlinear systems of equations. The task automatically generates MATLAB® code for your live script.
Using this task, you can:
Choose a solver based on the characteristics of your problem. If you have Global Optimization Toolbox, you can choose to use its solvers as well.
Specify the objective and constraint functions, either by writing functions or browsing for functions.
Specify solver options.
Run the optimization.
For suggestions on how to use Optimize, see Use Optimize Live Editor Task Effectively. Currently, you cannot use
MultiStart solvers with
For general information about Live Editor tasks, see Add Interactive Tasks to a Live Script.
To add the Optimize task to a live script in the MATLAB Editor, on the Live Editor Insert tab, select Task > Optimize.
Alternatively, in a code block in the script, type a relevant keyword, such as
Optimize from the suggested command completions.
Objective— Objective function type
Objective function type, specified by clicking the appropriate labeled button. The
selected objective function determines which solvers are available and which solver is
recommended for the problem (see
Constraints— Constraint types
Constraint types, specified by clicking the appropriate labeled buttons. You can
specify more than one constraint type. The selected constraints determine which solvers
are available and which solver is recommended for the problem (see
Solver— Optimization solver
Optimization solver that MATLAB uses to solve the problem, specified by selecting a solver from the list
of available solvers. The available solvers and the recommended solver depend on your
license and the selected
|Constraint Type||Objective Type|
|Unconstrained||Solution is trivial|
|Linear + Integer|
|Nonlinear + Integer|
For functions with extra inputs, Optimize requires you to choose the optimization variable, and to specify which workspace variables contain the fixed data inputs. For example, see Place Optimization Variables in One Vector and Data in Other Variables, which contains three function inputs:
Optimize generates code only after you specify all function inputs.
Optimize cannot parse a function containing the
varargin input or a function that contains an error.
If you select an objective or nonlinear constraint function from a file, Optimize adds the file location to your MATLAB path.
If Optimize has a parsing error or if multiple local functions have the same name, the list of available local functions is empty.