Variable

Index

Warning

In the examples in the documentation below, the methods are not prefixed by the module name even if they are private.

julia> using CTModels
julia> x = 1
julia> private_fun(x) # throw an error

must be replaced by

julia> using CTModels
julia> x = 1
julia> CTModels.private_fun(x)

However, if the method is reexported by another package, then, there is no need of prefixing.

julia> module OptimalControl
           import CTModels: private_fun
           export private_fun
       end
julia> using OptimalControl
julia> x = 1
julia> private_fun(x)

Documentation

CTModels.componentsMethod
components(_::CTModels.EmptyVariableModel) -> Vector{String}

Return an empty vector since there are no variable components defined.

CTModels.componentsMethod
components(
    model::CTModels.VariableModelSolution
) -> Vector{String}

Return the names of the components from the variable solution.

CTModels.componentsMethod
components(model::CTModels.VariableModel) -> Vector{String}

Return the names of the components of the variable.

CTModels.dimensionMethod
dimension(_::CTModels.EmptyVariableModel) -> Int64

Return 0 since no variable is defined.

CTModels.dimensionMethod
dimension(model::CTModels.VariableModelSolution) -> Int64

Return the number of components in the variable solution.

CTModels.dimensionMethod
dimension(model::CTModels.VariableModel) -> Int64

Return the dimension (number of components) of the variable.

CTModels.nameMethod
name(_::CTModels.EmptyVariableModel) -> String

Return an empty string, since no variable is defined.

CTModels.nameMethod
name(model::CTModels.VariableModelSolution) -> String

Return the name of the variable stored in the model solution.

CTModels.nameMethod
name(model::CTModels.VariableModel) -> String

Return the name of the variable stored in the model.

CTModels.valueMethod
value(
    model::CTModels.VariableModelSolution{TS<:Union{Real, AbstractVector{<:Real}}}
) -> Union{Real, AbstractVector{<:Real}}

Return the value stored in the variable solution model.

CTModels.variable!Method
variable!(ocp::CTModels.PreModel, q::Int64)
variable!(
    ocp::CTModels.PreModel,
    q::Int64,
    name::Union{String, Symbol}
)
variable!(
    ocp::CTModels.PreModel,
    q::Int64,
    name::Union{String, Symbol},
    components_names::Array{T2<:Union{String, Symbol}, 1}
)

Define a new variable in the optimal control problem ocp with dimension q.

This function registers a named variable (e.g. "state", "control", or other) to be used in the problem definition. You may optionally specify a name and individual component names.

Note

You can call variable! only once. It must be called before setting the objective or dynamics.

Arguments

  • ocp: The PreModel where the variable is registered.
  • q: The dimension of the variable (number of components).
  • name: A name for the variable (default: auto-generated from q).
  • components_names: A vector of strings or symbols for each component (default: ["v₁", "v₂", ...]).

Examples

julia> variable!(ocp, 1, "v")
julia> variable!(ocp, 2, "v", ["v₁", "v₂"])