Optimize - Optimize or solve equations in the Live Editor - MATLAB (original) (raw)

Optimize or solve equations in the Live Editor

Since R2020b

Description

The Optimize task lets you choose between two ways to interactively optimize problems or to solve nonlinear systems of equations:

The task automatically generates MATLAB code for your live script.

Using the problem-based version of this task, you can:

Using the solver-based version of this task, you can:

To get started using Optimize, see Get Started with Solver-Based Optimize Live Editor Task and Get Started with Problem-Based Optimize Live Editor Task. For suggestions on how to use Optimize, see Use Solver-Based Optimize Live Editor Task Effectively or Use Problem-Based Optimize Live Editor Task Effectively. Currently, you cannot use the fseminf, GlobalSearch, orMultiStart solvers withOptimize.

For general information about Live Editor tasks, see Add Interactive Tasks to a Live Script.

Optimize task in Live Editor: Choose between problem-based (recommended) and solver-based

Open the Task

To add the Optimize task to a live script in the MATLAB Editor, on the Live Editor Insert tab, select .

Insert an Optimize Live Editor task

Alternatively, in a code block in the script, type a relevant keyword, such asoptim or fmincon. Select from the suggested command completions.

Choosing Optimize from command completion suggestions

After you insert the task, select either Problem-based (recommended) or Solver-based.

Examples

Parameters

expand all

The problem-based variable names are dynamic; you can choose any names you like subject to the usual naming restrictions (see Variable Names).

Problem-Based

Problem type, specified by clicking the appropriate labeled button.

Objective function, specified as an optimization expression, a local function, or a function file. Applies when the Goal is Minimize or Maximize.

Constraints on solution, specified as an optimization expression, local function, or function file. Add constraints to the problem by clicking the + button.

Problem equations, specified as an optimization expression, local function, or function file. Applies when the Goal is Solve equations. Add equations to the problem by clicking the + button.

Solver-Based

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 Solver).

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 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 Objective andConstraints.

Limitations

Tips

Version History

Introduced in R2020b

expand all

The Optimize Live Editor task now supports the Problem-Based Optimization Workflow.Optimize also supports the problem-based approach forGlobal Optimization Toolbox single-objective and multiobjective solvers. Using problem-basedOptimize you can:

To launch the task, create a Live Editor window, then select or . Then choose the problem-based approach.

For an example, see Get Started with Problem-Based Optimize Live Editor Task. For tips, see Use Problem-Based Optimize Live Editor Task Effectively.