# sdo.optimize

Package: sdo

Design optimization problem solution

## Syntax

`[param_opt,opt_info] = sdo.optimize(opt_fcn,param)[param_opt,opt_info] = sdo.optimize(opt_fcn,param,options)[param_opt,opt_info] = sdo.optimize(prob)`

## Description

`[param_opt,opt_info] = sdo.optimize(opt_fcn,param)` uses `fmincon` (the default optimization method) to solve a design optimization problem of the form:

where

• F — Cost (objective)

• p — Design variable

• Cleq, Ceq — Nonlinear inequality and equality constraints

• A, B — Linear inequality constraints

• Aeq, Beq — Linear equality constraints

• lb, ub — Upper and lower bounds on p

`[param_opt,opt_info] = sdo.optimize(opt_fcn,param,options)` specifies the optimization options. For parameter estimation, you typically use the Nonlinear Least Squares method:

`opts = sdo.OptimizeOptions('Method','lsqnonlin');`

`[param_opt,opt_info] = sdo.optimize(prob)` uses a structure that contains the function to be minimized, design variables and optimization options.

## Input Arguments

 `opt_fcn` Cost function to be minimized. The optimization solver calls this function during optimization. The function requires: One input argument, which is a vector of `param.Continuous` objects to be tuned.To pass additional input arguments, use an anonymous function. For example, `new_fcn = @(p) fcn(p,arg1,arg2, ...)`.One output argument, which is a structure with one or more of the following fields:`F` — Value of the cost (objective) evaluated at `p`. The solver minimizes `F`.`F` is a `1x1` double. `Cleq` — Value of the nonlinear inequality constraint violations evaluated at `p`. The solver satisfies `Cleq(p) <= 0`.`Cleq` is a double `mx1` vector, where `m` is the number of nonlinear inequality constraints.`Ceq` — Value of the nonlinear equality constraint violations evaluated at `p`. The solver satisfies `Ceq(p) == 0`.The value is a double `rx1` vector, where `r` is the number of nonlinear equality constraints.`leq` — Value of the linear inequality constraint violations evaluated at `p`. The solver satisfies `leq(p) <= 0`.`leq` is a double `nx1` vector, where `n` is the number of linear inequality constraints.`eq` — Value of the linear equality constraint violations evaluated at `p`. The solver satisfies `eq(p) == 0`.`eq` is a double `sx1` vector or `[]`, where `s` is the number of linear equality constraints.To specify a pure feasibility problem, omit `F` or set `F = []`. To specify a minimization problem, omit `Cleq`, `Ceq`, `leq` and `eq` or set their values to `[]`.The software computes gradients of the cost and constraint violations using numeric perturbation. If you want to specify how the gradients are computed, include a second output argument and set the `GradFcn` property of `sdo.OptimizeOptions` to `'on'`. This argument must be a structure with one or more of the following fields:`F` — Double `nx1` vector that contains `dF(p)/dp`, where `n` is the number of scalar parameters.`Cleq` — Double `nxm` matrix that contains `dCleq(p)/dp`, where `m` is the number of nonlinear inequality constraints.`Ceq` — Double `nxr` matrix that contains `dCeq(p)/dp`, where `r` is the number of nonlinear equality constraints.You must return the derivatives of all applicable objective and constraint violations. For an example, type `edit sdoExampleCostFunction`. `param` A `param.Continuous` object or a vector of objects. `options` Optimization options. `options` is an options set, created using `sdo.OptimizeOptions`. Use this options set to specify: Optimization methodMaximum number of iterationsTolerances `prob` Structure with the following fields: `OptFcn` — Name of the function to be minimized. See `opt_fcn` for the input and output argument requirements of this function.`Parameters` — A `param.Continuous` object or a vector of objects`Options` — Optimization options, specified using `sdo.OptimizeOptions`

## Output Arguments

 `param_opt` A `param.Continuous` object or vector of objects, containing the optimized parameter values in the `Value` property. `opt_info` Optimization information. Structure with one or more of the following fields:`F` — Optimized cost (objective) value.`Cleq` — Optimized nonlinear inequality constraint violations. The field appears if you specify a nonlinear inequality constraint in `opt_fcn`. The value is a `mx1` vector, where the order of the elements correspond to the order specified in `opt_fcn`. Positive values indicate that the constraint has not been satisfied. Check `exitflag` to confirm that the optimization succeeded.`Ceq` — Optimized nonlinear equality constraint violations. The field appears if you specify a nonlinear equality constraint in `opt_fcn`.The value is a double `rx1` vector, where the order of the elements correspond to the order specified in `opt_fcn`. Any nonzero values indicate that the constraint has not been satisfied. Check `exitflag` to confirm that the optimization succeeded.`leq` — Optimized linear equality constraint violations.The field appears if you specify a linear equality constraint in `opt_fcn`.The value is a double `nx1` vector, where the order of the elements correspond to the order specified in `opt_fcn`. Nonzero values indicate that the constraint has not been satisfied. Check `exitflag` to confirm that the optimization succeeded.`eq` — Optimized linear equality constraint violations.The field appears if you specify linear equality constraints in `opt_fcn`.The value is a double `sx1` vector, where the order of the elements correspond to the order specified in `opt_fcn`. Nonzero values indicate that the constraint has not been satisfied. Check `exitflag` to confirm that the optimization succeeded.`Gradients` — Cost and constraint gradients at the optimized parameter values. See How the Optimization Algorithm Formulates Minimization Problems on how the solver computes gradients.This field appears if the solver specified in the `Method` property of `sdo.OptimizeOptions` computes gradients.The value is a structure whose fields are dependent on `opt_fcn`.`exitflag` — Integer identifying the reason the algorithm terminated. See `fmincon`, `patternsearch` and `fminsearch` for a list of the values and the corresponding termination reasons.`iterations` — Number of optimization iterations`SolverOutput` — A structure with solver-specific output information. The fields of this structure depends on the optimization solver specified in the `Method` property of `sdo.OptimizeOptions`. See `fmincon`, `patternsearch` and `fminsearch` for a list of solver outputs and their description.`Stats` — A structure that contains statistics collected during optimization, such as start and end times, number of function evaluations and restarts.

## Examples

collapse all

Create design variables.

```p = param.Continuous('x',1); ```

Specify optimization options.

```opts = sdo.OptimizeOptions; opts.GradFcn = 'on'; ```

Optimize the parameter.

```[pOpt,opt_info] = sdo.optimize(@(p) sdoExampleCostFunction(p),p,opts); ```
``` Optimization started 30-Aug-2016 22:05:56 max Step-size First-order Iter F-count f(x) constraint optimality 0 3 1 0 1 5 0.09 0 0.7 0.59 2 6 0.0716349 0.001047 0.0324 0.0129 3 7 0.0717968 9.127e-08 0.000302 2.37e-06 Local minimum found that satisfies the constraints. Optimization completed because the objective function is non-decreasing in feasible directions, to within the selected value of the optimality tolerance, and constraints are satisfied to within the selected value of the constraint tolerance. ```

collapse all

### Tips

• By default, the software displays the optimization information for each iteration in the MATLAB® command window. To learn more about the information displayed, see:

• Iterative Display when the optimization method is specified as `'fmincon'` (default), `'fminsearch'`, or `'lsqnonlin'`

• Display to Command Window Options when the optimization method is specified as `'patternsearch'`

You can configure the level of this display using the `MethodOptions.Display` property of an optimization option set.