Skip to content

Variable

openscvx.backend.variable.Variable

Bases: Expr

A base class for variables in an optimal control problem.

The Variable class provides the fundamental structure for state and control variables, handling their shapes, bounds, and initial guesses. It supports operations like appending new variables and slicing.

Attributes:

Name Type Description
name str

Name identifier for the variable

_shape tuple

Shape of the variable vector

_min ndarray

Minimum bounds for the variable

_max ndarray

Maximum bounds for the variable

_guess ndarray

Initial guess for the variable trajectory

guess property writable

Get the initial guess for the variable trajectory.

Returns:

Type Description

np.ndarray: Array of initial guesses for each variable at each time point

max property writable

Get the maximum bounds for the variable.

Returns:

Type Description

np.ndarray: Array of maximum values for each variable

min property writable

Get the minimum bounds for the variable.

Returns:

Type Description

np.ndarray: Array of minimum values for each variable

shape property

Get the shape of the variable.

Returns:

Name Type Description
tuple

Shape of the variable vector

append(other=None, *, min=-np.inf, max=np.inf, guess=0.0)

Append another variable or create a new variable.

Parameters:

Name Type Description Default
other Variable

Another Variable object to append

None
min float

Minimum bound for new variable. Defaults to -np.inf

-inf
max float

Maximum bound for new variable. Defaults to np.inf

inf
guess float

Initial guess for new variable. Defaults to 0.0

0.0