-
Notifications
You must be signed in to change notification settings - Fork 3
Polynomials
A polynomial
where
we need the tuple
CaΣoS distinguishes between indeterminate variables (symbols in a polynomial sense) and symbolic variables (variables in an optimization sense).
If for example, we want to solve the optimization problem
then
Note
Polynomials of type casos.PS can have symbolic coefficients that can be used as decision variables in polynomial optimization problems.
In CaΣoS,
casos.Indeterminates('x',n)
casos.Indeterminates('x','y',...)
creates a tupel of n indeterminate variables; in the second case, n corresponds to the number of arguments.
Tupels of indeterminate variables can be converted into polynomials that correspond to vectors of indeterminate variables, and vice-versa.
Moreover, indeterminate variables can be used in algebraic expressions to define polynomials with constant or symbolic coefficients, e.g.,
f = [-x(2); x(1) + (x(1)^2 - 1)*x(2)]
u = K*x
if x is a tuple of indeterminate variables and K is a double, casadi.DM, or casadi.SX matrix of suitable dimensions. Expressions of indeterminate variables and double, casadi.DM, and/or casadi.SX return a compatible polynomial data type.
The classes casos.PD and casos.PS implement polynomials of which the coefficients are constant doubles or can be symbolic expressions, respectively.
In the following, we introduce the syntax to define different polynomials. For a detailed description, see polynomial data types.
Polynomials of degree zero correspond to constant or symbolic expressions without indeterminate variables.
They can be constant matrices where the coefficients are double such as
and
p1 = casos.PD([4 3; 1 0])or constant symbolic matrices such as
and
p2 = casos.PS.sym('a',[2,3])These expressions corresponds to the double or casadi.DMor casadi.SX matrix M.
The following syntaxes for constant matrices are also supported:
casos.PD(m,n)
casos.PD.zeros(m,n)
casos.PD.zeros(n)
creates a zero-degree polynomial which corresponds to a m × n matrix (resp., a column vector with length n) of zeros.
Similarly,
casos.PD.ones(m,n)
casos.PD.ones(n)creates a zero-degree polynomial which corresponds to a m × n matrix (resp., a column vector with length n) of ones.
casos.PD.eye(n)
creates a zero-degree polynomial which corresponds to the n × n identity matrix.
We define
with
A = casos.PS.sym('a', [2,2]);
x = casos.Indeterminates('x',2);
which allows us to define a new polynomial casos.PS using matrix multiplication
The syntax
p3 = A*x;yields
p3 = [(a_0)*x_1 + (a_2)*x_2] [(a_1)*x_1 + (a_3)*x_2]
Polynomials in CaΣoS can be converted to functions in CasADi using the to_function operation. This replaces the indeterminate variables by CasADi's symbolic variables. Each function input corresponds to a scalar indeterminate variable. Thus, a polynomial with
f:(x1,...,xn)->(poly) SXFunction
Note that, if a polynomial has symbolic coefficients (as in the example p3 = A*x above, where A is a matrix of type casadi.SX), those will become free variables of the function. However, this must be explicitly enabled by passing the allow_free option to the created CasADi function, viz.
to_function(A*x,struct('allow_free',true))
Warning
Creating a CasADi function with free variables but without enabling the allow_free option will lead to an exception.
- Getting started
- Available conic solvers
- Convex and nonconvex sum-of-squares optimization
- Supported vector, matrix, and polynomial cones
- Some practical tipps for sum-of-squares
- Transitioning from other toolboxes
- Example code snippets
If you use CaΣoS, please cite us.