OptimizationExpression - Arithmetic or functional expression in terms of optimization

        variables - MATLAB ([original](https://in.mathworks.com/help/optim/ug/optim.problemdef.optimizationexpression.html)) ([raw](?raw))

Arithmetic or functional expression in terms of optimization variables

Description

An OptimizationExpression is an arithmetic or functional expression in terms of optimization variables. Use anOptimizationExpression as an objective function, or as a part of an inequality or equality in a constraint or equation.

Properties

expand all

This property is read-only.

Optimization variables in the object, specified as a structure of OptimizationVariable objects.

Data Types: struct

Object Functions

evaluate Evaluate optimization expression or objectives and constraints in problem
show Display information about optimization object
write Save optimization object description

Examples

collapse all

Create optimization expressions by arithmetic operations on optimization variables.

x = optimvar('x',3,2); expr = sum(sum(x))

expr = Linear OptimizationExpression

x(1, 1) + x(2, 1) + x(3, 1) + x(1, 2) + x(2, 2) + x(3, 2)

f = [2,10,4]; w = f*x; show(w)

(1, 1)

2x(1, 1) + 10x(2, 1) + 4*x(3, 1)

(1, 2)

2x(1, 2) + 10x(2, 2) + 4*x(3, 2)

Create an optimization expression by transposing an optimization variable.

x = optimvar('x',3,2); y = x'

y = 2×3 Linear OptimizationExpression array with properties:

IndexNames: {{}  {}}
 Variables: [1×1 struct] containing 1 OptimizationVariable

See expression formulation with show.

Simply indexing into an optimization array does not create an expression, but instead creates an optimization variable that references the original variable. To see this, create a variable w that is the first and third row of x. Note that w is an optimization variable, not an optimization expression.

w = 2×2 OptimizationVariable array with properties:

Read-only array-wide properties: Name: 'x' Type: 'continuous' IndexNames: {{} {}}

Elementwise properties: LowerBound: [2×2 double] UpperBound: [2×2 double]

Reference to a subset of OptimizationVariable with Name 'x'.

See variables with show. See bounds with showbounds.

Create an optimization expression by concatenating optimization variables.

y = optimvar('y',4,3); z = optimvar('z',4,7); f = [y,z]

f = 4×10 Linear OptimizationExpression array with properties:

IndexNames: {{}  {}}
 Variables: [1×1 struct] containing 2 OptimizationVariables

See expression formulation with show.

Use optimexpr to create an empty expression, then fill the expression in a loop.

y = optimvar('y',6,4); expr = optimexpr(3,2); for i = 1:3 for j = 1:2 expr(i,j) = y(2i,j) - y(i,2j); end end show(expr)

(1, 1)

y(2, 1) - y(1, 2)

(2, 1)

y(4, 1) - y(2, 2)

(3, 1)

y(6, 1) - y(3, 2)

(1, 2)

y(2, 2) - y(1, 4)

(2, 2)

y(4, 2) - y(2, 4)

(3, 2)

y(6, 2) - y(3, 4)

Create an optimization expression corresponding to the objective function

f(x)=x2/10+exp(-exp(-x)).

x = optimvar('x'); f = x^2/10 + exp(-exp(-x))

f = Nonlinear OptimizationExpression

((x.^2 ./ 10) + exp((-exp((-x)))))

Find the point that minimizes fun starting from the point x0 = 0.

x0 = struct('x',0); prob = optimproblem('Objective',f); [sol,fval] = solve(prob,x0)

Solving problem using fminunc.

Local minimum found.

Optimization completed because the size of the gradient is less than the value of the optimality tolerance.

sol = struct with fields: x: -0.9595

If f were not a supported function, you would convert it using fcn2optimexpr. See Supported Operations for Optimization Variables and Expressions and Convert Nonlinear Function to Optimization Expression.

f = @(x)x^2/10 + exp(-exp(-x)); fun = fcn2optimexpr(f,x)

fun = Nonlinear OptimizationExpression

((x.^2 ./ 10) + exp((-exp((-x)))))

prob = optimproblem('Objective',fun); [sol,fval] = solve(prob,x0)

Solving problem using fminunc.

Local minimum found.

Optimization completed because the size of the gradient is less than the value of the optimality tolerance.

sol = struct with fields: x: -0.9595

Copyright 2018–2020 The MathWorks, Inc.

Create an optimization expression of two variables.

x = optimvar("x",3,2); y = optimvar("y",1,2); expr = sum(x,1) - 2*y;

Evaluate the expression at a point.

xmat = [3,-1; 0,1; 2,6]; sol.x = xmat; sol.y = [4,-3]; val = evaluate(expr,sol)

More About

Version History

Introduced in R2017b