createOptimProblem

Create optimization problem structure

Syntax

problem = createOptimProblem('solverName')

problem = createOptimProblem('solverName','ParameterName',ParameterValue,...)

Description

problem = createOptimProblem('solverName') creates an empty optimization problem structure for the solverName solver.

problem = createOptimProblem('solverName','ParameterName',ParameterValue,...) accepts one or more comma-separated parameter name/value pairs. Specify ParameterName inside single quotes.

Input Arguments

solverName

Name of the solver. For a GlobalSearch problem, use 'fmincon'. For a MultiStart problem, use 'fmincon', 'fminunc', 'lsqcurvefit' or 'lsqnonlin'.

Name-Value Pair Arguments

'Aeq'

Matrix for linear equality constraints. The constraints have the form:

Aeq x = beq

'Aineq'

Matrix for linear inequality constraints. The constraints have the form:

Aineq xbineq

'beq'

Vector for linear equality constraints. The constraints have the form:

Aeq x = beq

'bineq'

Vector for linear inequality constraints. The constraints have the form:

Aineq xbineq

'lb'

Vector of lower bounds.

lb can also be an array; see Matrix Arguments.

'nonlcon'

Function handle to the nonlinear constraint function. The constraint function must accept a vector x and return two vectors: c, the nonlinear inequality constraints, and ceq, the nonlinear equality constraints. If one of these constraint functions is empty, nonlcon must return [] for that function.

If the GradConstr option is 'on', then in addition nonlcon must return two additional outputs, gradc and gradceq. The gradc parameter is a matrix with one column for the gradient of each constraint, as is gradceq.

For more information, see Write Constraints.

'objective'

Function handle to the objective function. For all solvers except lsqnonlin and lsqcurvefit, the objective function must accept a vector x and return a scalar. If the GradObj option is 'on', then the objective function must return a second output, a vector, representing the gradient of the objective. For lsqnonlin, the objective function must accept a vector x and return a vector. lsqnonlin sums the squares of the objective function values. For lsqcurvefit, the objective function must accept two inputs, x and xdata, and return a vector.

For more information, see Compute Objective Functions.

'options'

Optimization options. Create options with optimoptions, or by exporting from the Optimization app.

'ub'

Vector of upper bounds.

ub can also be an array; see Matrix Arguments.

'x0'

A vector, a potential starting point for the optimization. Gives the dimensionality of the problem.

x0 can also be an array; see Matrix Arguments.

'xdata'

Vector of data points for lsqcurvefit.

'ydata'

Vector of data points for lsqcurvefit.

Output Arguments

problem

Optimization problem structure.

Examples

Create a problem structure using Rosenbrock's function as objective (see Include a Hybrid Function), the interior-point algorithm for fmincon, and bounds with absolute value 2:

anonrosen = @(x)(100*(x(2) - x(1)^2)^2 + (1-x(1))^2);
opts = optimoptions(@fmincon,'Algorithm','interior-point');
problem = createOptimProblem('fmincon','x0',randn(2,1),...
    'objective',anonrosen,'lb',[-2;-2],'ub',[2;2],...
    'options',opts);

Alternatives

You can create a problem structure by exporting from the Optimization app (optimtool), as described in Exporting from the Optimization app.

Was this topic helpful?