Documentation

Supported Operations on Optimization Variables and Expressions

Notation for Supported Operations

For the legal operations on optimization variables and expressions:

• x1 and x2 represent optimization arrays of arbitrary size (usually the same size).

• x3 represents a 2-D optimization array.

• a is a scalar numeric constant.

• M is a constant numeric matrix.

• c is a numeric array of the same size as x1.

Operations Returning Optimization Expressions

These operations on optimization variables or expressions return an optimization expression.

• Addition of a constant, x1+c or c+x1

• Addition of two or more variables, x1+x2

• Unary plus, +x1

• Subtraction of a constant, x1-c

• Subtraction of two or more variables, x1–x2

• Unary minus, -x1

• Multiplication by a constant scalar, a*x1 or a.*x1 or x1*a or x1.*a

• Division by a constant scalar, x1/a or x1./a or a\x1 or a.\x1

• Pointwise multiplication by an array, c.*x1 or x1.*c

• Pointwise division by an array, x1./c or c.\x1

• Pointwise multiplication of two optimization variables, x1.*x2

• Multiplication of two optimization variables of sizes that make sense for matrix multiplication, x1*x2

• Raising a 2-D variable with the same number of rows as columns to a power, x1^a

• Pointwise raising a variable to a power, x1.^a

• Multiplication of a 2-D variable by a 2-D matrix, M*x3 or x3*M

• Dot product of a variable and an array dot(x1,c) or dot(c,x1)

• Linear combination of variables, including sum, sum(x1), sum(x1,dim), mean(x1), and mean(x1,dim)

• Transpose operation, x1' or x1.'

• Concatenation (cat, vertcat, and horzcat)

• Reshape operation, reshape(x1,[10 1])

Operations Returning Optimization Variables

These operations on optimization variables return an optimization variable.

• N-D numeric indexing (includes colon and end)

• N-D logical indexing

• N-D string indexing

• N-D mixed indexing (combination of numeric, logical, colon, end, and string)

• Linear numeric indexing (includes colon and end)

• Linear logical indexing

• Linear string indexing

Operations on Optimization Expressions

Optimization expressions support all the operations that optimization variables support, and return optimization expressions. Also, you can index into or assign into an optimization expression using numeric, logical, string, or linear indexing, including the colon and end operators for numeric or linear indexing.

Operations Returning Constraint Expressions

Constraints are any two comparable expressions that include one of these comparison operators: ==, <=, or >=. Comparable expressions have the same size, or one of the expressions must be scalar, meaning of size 1-by-1. For examples, see Expressions for Constraints and Equations.

Some Undocumented Operations Work on Optimization Variables and Expressions

Internally, some functions and operations call only the documented supported operations. In these cases you can obtain sensible results from the functions or operations. For example, currently squeeze internally calls reshape, which is a documented supported operation. So if you squeeze an optimization variable then you can obtain a sensible expression.