CTBase API

This is just a dump of CTBase API documentation. For more details about CTBase.jl package, see the documentation.

Index

Documentation

CTBase.CTBaseModule

CTBase module.

Lists all the imported modules and packages:

  • Base
  • Core
  • DataStructures
  • DocStringExtensions
  • LinearAlgebra
  • MLStyle
  • Parameters
  • Plots
  • PrettyTables
  • Printf
  • ReplMaker
  • Unicode

List of all the exported names:

source
CTBase.AmbiguousDescriptionType
struct AmbiguousDescription <: CTException

Exception thrown when the description is ambiguous / incorrect.

Fields

  • var::Tuple{Vararg{Symbol}}
source
CTBase.BoundaryConstraintType
struct BoundaryConstraint{variable_dependence}

Fields

  • f::Function

The default value for variable_dependence is Fixed.

Constructor

The constructor BoundaryConstraint returns a BoundaryConstraint of a function. The function must take 2 or 3 arguments (x0, xf) or (x0, xf, v), if the function is variable, it must be specified. Dependencies are specified with a boolean, variable, false by default or with a DataType, NonFixed/Fixed, Fixed by default.

Examples

julia> B = BoundaryConstraint((x0, xf) -> [xf[2]-x0[1], 2xf[1]+x0[2]^2])
julia> B = BoundaryConstraint((x0, xf, v) -> [v[3]+xf[2]-x0[1], v[1]-v[2]+2xf[1]+x0[2]^2], variable=true)
julia> B = BoundaryConstraint((x0, xf, v) -> [v[3]+xf[2]-x0[1], v[1]-v[2]+2xf[1]+x0[2]^2], NonFixed)
Warning

When the state is of dimension 1, consider x0 and xf as a scalar. When the constraint is dimension 1, return a scalar.

Call

The call returns the evaluation of the BoundaryConstraint for given values. If a variable is given for a non variable dependent boundary constraint, it will be ignored.

Examples

julia> B = BoundaryConstraint((x0, xf) -> [xf[2]-x0[1], 2xf[1]+x0[2]^2])
julia> B([0, 0], [1, 1])
[1, 2]
julia> B = BoundaryConstraint((x0, xf) -> [xf[2]-x0[1], 2xf[1]+x0[2]^2])
julia> B([0, 0], [1, 1],Real[])
[1, 2]
julia> B = BoundaryConstraint((x0, xf, v) -> [v[3]+xf[2]-x0[1], v[1]-v[2]+2xf[1]+x0[2]^2], variable=true)
julia> B([0, 0], [1, 1], [1, 2, 3])
[4, 1]
source
CTBase.BoundaryConstraintMethod
BoundaryConstraint(
    f::Function,
    dependencies::DataType...
) -> BoundaryConstraint{Fixed}

Return a BoundaryConstraint of a function. Dependencies are specified with a DataType, NonFixed/Fixed, Fixed by default.

julia> B = BoundaryConstraint((x0, xf) -> [xf[2]-x0[1], 2xf[1]+x0[2]^2])
julia> B = BoundaryConstraint((x0, xf, v) -> [v[3]+xf[2]-x0[1], v[1]-v[2]+2xf[1]+x0[2]^2], NonFixed)
source
CTBase.BoundaryConstraintMethod
BoundaryConstraint(
    f::Function;
    variable
) -> BoundaryConstraint{Fixed}

Return a BoundaryConstraint of a function. Dependencies are specified with a boolean, variable, false by default.

julia> B = BoundaryConstraint((x0, xf) -> [xf[2]-x0[1], 2xf[1]+x0[2]^2])
julia> B = BoundaryConstraint((x0, xf, v) -> [v[3]+xf[2]-x0[1], v[1]-v[2]+2xf[1]+x0[2]^2], variable=true)
source
CTBase.BoundaryConstraintMethod

Return the evaluation of the BoundaryConstraint.

julia> B = BoundaryConstraint((x0, xf) -> [xf[2]-x0[1], 2xf[1]+x0[2]^2])
julia> B([0, 0], [1, 1])
[1, 2]
julia> B = BoundaryConstraint((x0, xf) -> [xf[2]-x0[1], 2xf[1]+x0[2]^2])
julia> B([0, 0], [1, 1],Real[])
[1, 2]
julia> B = BoundaryConstraint((x0, xf, v) -> [v[3]+xf[2]-x0[1], v[1]-v[2]+2xf[1]+x0[2]^2], variable=true)
julia> B([0, 0], [1, 1], [1, 2, 3])
[4, 1]
source
CTBase.ControlConstraintType
struct ControlConstraint{time_dependence, variable_dependence}

Fields

  • f::Function

Similar to VectorField in the usage, but the dimension of the output of the function f is arbitrary.

The default values for time_dependence and variable_dependence are Autonomous and Fixed respectively.

Constructor

The constructor ControlConstraint returns a ControlConstraint of a function. The function must take 1 to 3 arguments, u to (t, u, v), if the function is variable or non autonomous, it must be specified. Dependencies are specified either with :

  • booleans, autonomous and variable, respectively true and false by default
  • DataType, Autonomous/NonAutonomous and NonFixed/Fixed, respectively Autonomous and Fixed by default.

Examples

julia> IncorrectArgument ControlConstraint(u -> [u[1]^2, 2u[2]], Int64)
julia> IncorrectArgument ControlConstraint(u -> [u[1]^2, 2u[2]], Int64)
julia> C = ControlConstraint(u -> [u[1]^2, 2u[2]], Autonomous, Fixed)
julia> C = ControlConstraint((u, v) -> [u[1]^2, 2u[2]+v[3]], Autonomous, NonFixed)
julia> C = ControlConstraint((t, u) -> [t+u[1]^2, 2u[2]], NonAutonomous, Fixed)
julia> C = ControlConstraint((t, u, v) -> [t+u[1]^2, 2u[2]+v[3]], NonAutonomous, NonFixed)
julia> C = ControlConstraint(u -> [u[1]^2, 2u[2]], autonomous=true, variable=false)
julia> C = ControlConstraint((u, v) -> [u[1]^2, 2u[2]+v[3]], autonomous=true, variable=true)
julia> C = ControlConstraint((t, u) -> [t+u[1]^2, 2u[2]], autonomous=false, variable=false)
julia> C = ControlConstraint((t, u, v) -> [t+u[1]^2, 2u[2]+v[3]], autonomous=false, variable=true)
Warning

When the control is of dimension 1, consider u as a scalar.

Call

The call returns the evaluation of the ControlConstraint for given values.

Examples

julia> C = ControlConstraint(u -> [u[1]^2, 2u[2]], autonomous=true, variable=false)
julia> C([1, -1])
[1, -2]
julia> t = 1
julia> v = Real[]
julia> C(t, [1, -1], v)
[1, -2]
julia> C = ControlConstraint((u, v) -> [u[1]^2, 2u[2]+v[3]], autonomous=true, variable=true)
julia> C([1, -1], [1, 2, 3])
[1, 1]
julia> C(t, [1, -1], [1, 2, 3])
[1, 1]
julia> C = ControlConstraint((t, u) -> [t+u[1]^2, 2u[2]], autonomous=false, variable=false)
julia> C(1, [1, -1])
[2, -2]
julia> C(1, [1, -1], v)
[2, -2]
julia> C = ControlConstraint((t, u, v) -> [t+u[1]^2, 2u[2]+v[3]], autonomous=false, variable=true)
julia> C(1, [1, -1], [1, 2, 3])
[2, 1]
source
CTBase.ControlConstraintMethod
ControlConstraint(
    f::Function,
    dependencies::DataType...
) -> ControlConstraint{Autonomous, Fixed}

Return the StateConstraint of a function. Dependencies are specified with DataType, Autonomous, NonAutonomous and Fixed, NonFixed.

julia> IncorrectArgument ControlConstraint(u -> [u[1]^2, 2u[2]], Int64)
julia> IncorrectArgument ControlConstraint(u -> [u[1]^2, 2u[2]], Int64)
julia> C = ControlConstraint(u -> [u[1]^2, 2u[2]], Autonomous, Fixed)
julia> C = ControlConstraint((u, v) -> [u[1]^2, 2u[2]+v[3]], Autonomous, NonFixed)
julia> C = ControlConstraint((t, u) -> [t+u[1]^2, 2u[2]], NonAutonomous, Fixed)
julia> C = ControlConstraint((t, u, v) -> [t+u[1]^2, 2u[2]+v[3]], NonAutonomous, NonFixed)
source
CTBase.ControlConstraintMethod
ControlConstraint(
    f::Function;
    autonomous,
    variable
) -> ControlConstraint{Autonomous, Fixed}

Return the ControlConstraint of a function. Dependencies are specified with a boolean, variable, false by default, autonomous, true by default.

julia> C = ControlConstraint(u -> [u[1]^2, 2u[2]], autonomous=true, variable=false)
julia> C = ControlConstraint((u, v) -> [u[1]^2, 2u[2]+v[3]], autonomous=true, variable=true)
julia> C = ControlConstraint((t, u) -> [t+u[1]^2, 2u[2]], autonomous=false, variable=false)
julia> C = ControlConstraint((t, u, v) -> [t+u[1]^2, 2u[2]+v[3]], autonomous=false, variable=true)
source
CTBase.ControlConstraintMethod

Return the value of the ControlConstraint function.

julia> IncorrectArgument ControlConstraint(u -> [u[1]^2, 2u[2]], Int64)
julia> IncorrectArgument ControlConstraint(u -> [u[1]^2, 2u[2]], Int64)
julia> C = ControlConstraint(u -> [u[1]^2, 2u[2]], autonomous=true, variable=false)
julia> C([1, -1])
[1, -2]
julia> t = 1
julia> v = Real[]
julia> C(t, [1, -1], v)
[1, -2]
julia> C = ControlConstraint((u, v) -> [u[1]^2, 2u[2]+v[3]], autonomous=true, variable=true)
julia> C([1, -1], [1, 2, 3])
[1, 1]
julia> C(t, [1, -1], [1, 2, 3])
[1, 1]
julia> C = ControlConstraint((t, u) -> [t+u[1]^2, 2u[2]], autonomous=false, variable=false)
julia> C(1, [1, -1])
[2, -2]
julia> C(1, [1, -1], v)
[2, -2]
julia> C = ControlConstraint((t, u, v) -> [t+u[1]^2, 2u[2]+v[3]], autonomous=false, variable=true)
julia> C(1, [1, -1], [1, 2, 3])
[2, 1]
source
CTBase.ControlLawType
struct ControlLaw{time_dependence, variable_dependence}

Fields

  • f::Function

Similar to Hamiltonian in the usage, but the dimension of the output of the function f is arbitrary.

The default values for time_dependence and variable_dependence are Autonomous and Fixed respectively.

Constructor

The constructor ControlLaw returns a ControlLaw of a function. The function must take 2 to 4 arguments, (x, p) to (t, x, p, v), if the function is variable or non autonomous, it must be specified. Dependencies are specified either with :

  • booleans, autonomous and variable, respectively true and false by default
  • DataType, Autonomous/NonAutonomous and NonFixed/Fixed, respectively Autonomous and Fixed by default.

Examples

julia> ControlLaw((x, p) -> x[1]^2+2p[2], Int64)
IncorrectArgument
julia> ControlLaw((x, p) -> x[1]^2+2p[2], Int64)
IncorrectArgument
julia> u = ControlLaw((x, p) -> x[1]^2+2p[2], Autonomous, Fixed)
julia> u = ControlLaw((x, p, v) -> x[1]^2+2p[2]+v[3], Autonomous, NonFixed)
julia> u = ControlLaw((t, x, p) -> t+x[1]^2+2p[2], NonAutonomous, Fixed)
julia> u = ControlLaw((t, x, p, v) -> t+x[1]^2+2p[2]+v[3], NonAutonomous, NonFixed)
julia> u = ControlLaw((x, p) -> x[1]^2+2p[2], autonomous=true, variable=false)
julia> u = ControlLaw((x, p, v) -> x[1]^2+2p[2]+v[3], autonomous=true, variable=true)
julia> u = ControlLaw((t, x, p) -> t+x[1]^2+2p[2], autonomous=false, variable=false)
julia> u = ControlLaw((t, x, p, v) -> t+x[1]^2+2p[2]+v[3], autonomous=false, variable=true)
Warning

When the state and costate are of dimension 1, consider x and p as scalars.

Call

The call returns the evaluation of the ControlLaw for given values.

Examples

julia> u = ControlLaw((x, p) -> x[1]^2+2p[2], autonomous=true, variable=false)
julia> u([1, 0], [0, 1])
3
julia> t = 1
julia> v = Real[]
julia> u(t, [1, 0], [0, 1])
MethodError
julia> u([1, 0], [0, 1], v)
MethodError
julia> u(t, [1, 0], [0, 1], v)
3
julia> u = ControlLaw((x, p, v) -> x[1]^2+2p[2]+v[3], autonomous=true, variable=true)
julia> u([1, 0], [0, 1], [1, 2, 3])
6
julia> u(t, [1, 0], [0, 1], [1, 2, 3])
6
julia> u = ControlLaw((t, x, p) -> t+x[1]^2+2p[2], autonomous=false, variable=false)
julia> u(1, [1, 0], [0, 1])
4
julia> u(1, [1, 0], [0, 1], v)
4
julia> u = ControlLaw((t, x, p, v) -> t+x[1]^2+2p[2]+v[3], autonomous=false, variable=true)
julia> u(1, [1, 0], [0, 1], [1, 2, 3])
7
source
CTBase.ControlLawMethod
ControlLaw(
    f::Function,
    dependencies::DataType...
) -> ControlLaw{Autonomous, Fixed}

Return the ControlLaw of a function. Dependencies are specified with DataType, Autonomous, NonAutonomous and Fixed, NonFixed.

julia> ControlLaw((x, p) -> x[1]^2+2p[2], Int64)
IncorrectArgument
julia> ControlLaw((x, p) -> x[1]^2+2p[2], Int64)
IncorrectArgument
julia> u = ControlLaw((x, p) -> x[1]^2+2p[2], Autonomous, Fixed)
julia> u = ControlLaw((x, p, v) -> x[1]^2+2p[2]+v[3], Autonomous, NonFixed)
julia> u = ControlLaw((t, x, p) -> t+x[1]^2+2p[2], NonAutonomous, Fixed)
julia> u = ControlLaw((t, x, p, v) -> t+x[1]^2+2p[2]+v[3], NonAutonomous, NonFixed)
source
CTBase.ControlLawMethod
ControlLaw(
    f::Function;
    autonomous,
    variable
) -> ControlLaw{Autonomous, Fixed}

Return the ControlLaw of a function. Dependencies are specified with a boolean, variable, false by default, autonomous, true by default.

julia> u = ControlLaw((x, p) -> x[1]^2+2p[2], autonomous=true, variable=false)
julia> u = ControlLaw((x, p, v) -> x[1]^2+2p[2]+v[3], autonomous=true, variable=true)
julia> u = ControlLaw((t, x, p) -> t+x[1]^2+2p[2], autonomous=false, variable=false)
julia> u = ControlLaw((t, x, p, v) -> t+x[1]^2+2p[2]+v[3], autonomous=false, variable=true)
source
CTBase.ControlLawMethod

Return the value of the ControlLaw function.

julia> ControlLaw((x, p) -> x[1]^2+2p[2], Int64)
IncorrectArgument
julia> ControlLaw((x, p) -> x[1]^2+2p[2], Int64)
IncorrectArgument
julia> u = ControlLaw((x, p) -> x[1]^2+2p[2], autonomous=true, variable=false)
julia> u([1, 0], [0, 1])
3
julia> t = 1
julia> v = Real[]
julia> u(t, [1, 0], [0, 1])
MethodError
julia> u([1, 0], [0, 1], v)
MethodError
julia> u(t, [1, 0], [0, 1], v)
3
julia> u = ControlLaw((x, p, v) -> x[1]^2+2p[2]+v[3], autonomous=true, variable=true)
julia> u([1, 0], [0, 1], [1, 2, 3])
6
julia> u(t, [1, 0], [0, 1], [1, 2, 3])
6
julia> u = ControlLaw((t, x, p) -> t+x[1]^2+2p[2], autonomous=false, variable=false)
julia> u(1, [1, 0], [0, 1])
4
julia> u(1, [1, 0], [0, 1], v)
4
julia> u = ControlLaw((t, x, p, v) -> t+x[1]^2+2p[2]+v[3], autonomous=false, variable=true)
julia> u(1, [1, 0], [0, 1], [1, 2, 3])
7
source
CTBase.DynamicsType
struct Dynamics{time_dependence, variable_dependence}

Fields

  • f::Function

The default value for time_dependence and variable_dependence are Autonomous and Fixed respectively.

Constructor

The constructor Dynamics returns a Dynamics of a function. The function must take 2 to 4 arguments, (x, u) to (t, x, u, v), if the function is variable or non autonomous, it must be specified. Dependencies are specified either with :

  • booleans, autonomous and variable, respectively true and false by default
  • DataType, Autonomous/NonAutonomous and NonFixed/Fixed, respectively Autonomous and Fixed by default.

Examples

julia> Dynamics((x, u) -> [2x[2]-u^2, x[1]], Int64)
IncorrectArgument
julia> Dynamics((x, u) -> [2x[2]-u^2, x[1]], Int64)
IncorrectArgument
julia> D = Dynamics((x, u) -> [2x[2]-u^2, x[1]], Autonomous, Fixed)
julia> D = Dynamics((x, u, v) -> [2x[2]-u^2+v[3], x[1]], Autonomous, NonFixed)
julia> D = Dynamics((t, x, u) -> [t+2x[2]-u^2, x[1]], NonAutonomous, Fixed)
julia> D = Dynamics((t, x, u, v) -> [t+2x[2]-u^2+v[3], x[1]], NonAutonomous, NonFixed)
julia> D = Dynamics((x, u) -> [2x[2]-u^2, x[1]], autonomous=true, variable=false)
julia> D = Dynamics((x, u, v) -> [2x[2]-u^2+v[3], x[1]], autonomous=true, variable=true)
julia> D = Dynamics((t, x, u) -> [t+2x[2]-u^2, x[1]], autonomous=false, variable=false)
julia> D = Dynamics((t, x, u, v) -> [t+2x[2]-u^2+v[3], x[1]], autonomous=false, variable=true)
Warning

When the state is of dimension 1, consider x as a scalar. Same for the control.

Call

The call returns the evaluation of the Dynamics for given values.

Examples

julia> D = Dynamics((x, u) -> [2x[2]-u^2, x[1]], autonomous=true, variable=false)
julia> D([1, 0], 1)
[-1, 1]
julia> t = 1
julia> v = Real[]
julia> D(t, [1, 0], 1, v)
[-1, 1]
julia> D = Dynamics((x, u, v) -> [2x[2]-u^2+v[3], x[1]], autonomous=true, variable=true)
julia> D([1, 0], 1, [1, 2, 3])
[2, 1]
julia> D(t, [1, 0], 1, [1, 2, 3])
[2, 1]
julia> D = Dynamics((t, x, u) -> [t+2x[2]-u^2, x[1]], autonomous=false, variable=false)
julia> D(1, [1, 0], 1)
[0, 1]
julia> D(1, [1, 0], 1, v)
[0, 1]
julia> D = Dynamics((t, x, u, v) -> [t+2x[2]-u^2+v[3], x[1]], autonomous=false, variable=true)
julia> D(1, [1, 0], 1, [1, 2, 3])
[3, 1]
source
CTBase.DynamicsMethod
Dynamics(
    f::Function,
    dependencies::DataType...
) -> Dynamics{Autonomous, Fixed}

Return the Dynamics of a function. Dependencies are specified with DataType, Autonomous, NonAutonomous and Fixed, NonFixed.

julia> Dynamics((x, u) -> [2x[2]-u^2, x[1]], Int64)
IncorrectArgument
julia> Dynamics((x, u) -> [2x[2]-u^2, x[1]], Int64)
IncorrectArgument
julia> D = Dynamics((x, u) -> [2x[2]-u^2, x[1]], Autonomous, Fixed)
julia> D = Dynamics((x, u, v) -> [2x[2]-u^2+v[3], x[1]], Autonomous, NonFixed)
julia> D = Dynamics((t, x, u) -> [t+2x[2]-u^2, x[1]], NonAutonomous, Fixed)
julia> D = Dynamics((t, x, u, v) -> [t+2x[2]-u^2+v[3], x[1]], NonAutonomous, NonFixed)
source
CTBase.DynamicsMethod
Dynamics(
    f::Function;
    autonomous,
    variable
) -> Dynamics{Autonomous, Fixed}

Return the Dynamics of a function. Dependencies are specified with a boolean, variable, false by default, autonomous, true by default.

julia> D = Dynamics((x, u) -> [2x[2]-u^2, x[1]], autonomous=true, variable=false)
julia> D = Dynamics((x, u, v) -> [2x[2]-u^2+v[3], x[1]], autonomous=true, variable=true)
julia> D = Dynamics((t, x, u) -> [t+2x[2]-u^2, x[1]], autonomous=false, variable=false)
julia> D = Dynamics((t, x, u, v) -> [t+2x[2]-u^2+v[3], x[1]], autonomous=false, variable=true)
source
CTBase.DynamicsMethod

Return the value of the Dynamics function.

julia> D = Dynamics((x, u) -> [2x[2]-u^2, x[1]], autonomous=true, variable=false)
julia> D([1, 0], 1)
[-1, 1]
julia> t = 1
julia> v = Real[]
julia> D(t, [1, 0], 1, v)
[-1, 1]
julia> D = Dynamics((x, u, v) -> [2x[2]-u^2+v[3], x[1]], autonomous=true, variable=true)
julia> D([1, 0], 1, [1, 2, 3])
[2, 1]
julia> D(t, [1, 0], 1, [1, 2, 3])
[2, 1]
julia> D = Dynamics((t, x, u) -> [t+2x[2]-u^2, x[1]], autonomous=false, variable=false)
julia> D(1, [1, 0], 1)
[0, 1]
julia> D(1, [1, 0], 1, v)
[0, 1]
julia> D = Dynamics((t, x, u, v) -> [t+2x[2]-u^2+v[3], x[1]], autonomous=false, variable=true)
julia> D(1, [1, 0], 1, [1, 2, 3])
[3, 1]
source
CTBase.FeedbackControlType
struct FeedbackControl{time_dependence, variable_dependence}

Fields

  • f::Function

Similar to VectorField in the usage, but the dimension of the output of the function f is arbitrary.

The default values for time_dependence and variable_dependence are Autonomous and Fixed respectively.

Constructor

The constructor FeedbackControl returns a FeedbackControl of a function. The function must take 1 to 3 arguments, x to (t, x, v), if the function is variable or non autonomous, it must be specified. Dependencies are specified either with :

  • booleans, autonomous and variable, respectively true and false by default
  • DataType, Autonomous/NonAutonomous and NonFixed/Fixed, respectively Autonomous and Fixed by default.

Examples

julia> FeedbackControl(x -> x[1]^2+2x[2], Int64)
IncorrectArgument
julia> FeedbackControl(x -> x[1]^2+2x[2], Int64)
IncorrectArgument
julia> u = FeedbackControl(x -> x[1]^2+2x[2], Autonomous, Fixed)
julia> u = FeedbackControl((x, v) -> x[1]^2+2x[2]+v[3], Autonomous, NonFixed)
julia> u = FeedbackControl((t, x) -> t+x[1]^2+2x[2], NonAutonomous, Fixed)
julia> u = FeedbackControl((t, x, v) -> t+x[1]^2+2x[2]+v[3], NonAutonomous, NonFixed)
julia> u = FeedbackControl(x -> x[1]^2+2x[2], autonomous=true, variable=false)
julia> u = FeedbackControl((x, v) -> x[1]^2+2x[2]+v[3], autonomous=true, variable=true)
julia> u = FeedbackControl((t, x) -> t+x[1]^2+2x[2], autonomous=false, variable=false)
julia> u = FeedbackControl((t, x, v) -> t+x[1]^2+2x[2]+v[3], autonomous=false, variable=true)
Warning

When the state is of dimension 1, consider x as a scalar.

Call

The call returns the evaluation of the FeedbackControl for given values.

Examples

julia> u = FeedbackControl(x -> x[1]^2+2x[2], autonomous=true, variable=false)
julia> u([1, 0])
1
julia> t = 1
julia> v = Real[]
julia> u(t, [1, 0])
MethodError
julia> u([1, 0], v)
MethodError
julia> u(t, [1, 0], v)
1
julia> u = FeedbackControl((x, v) -> x[1]^2+2x[2]+v[3], autonomous=true, variable=true)
julia> u([1, 0], [1, 2, 3])
4
julia> u(t, [1, 0], [1, 2, 3])
4
julia> u = FeedbackControl((t, x) -> t+x[1]^2+2x[2], autonomous=false, variable=false)
julia> u(1, [1, 0])
2
julia> u(1, [1, 0], v)
2
julia> u = FeedbackControl((t, x, v) -> t+x[1]^2+2x[2]+v[3], autonomous=false, variable=true)
julia> u(1, [1, 0], [1, 2, 3])
5
source
CTBase.FeedbackControlMethod
FeedbackControl(
    f::Function,
    dependencies::DataType...
) -> FeedbackControl{Autonomous, Fixed}

Return the FeedbackControl of a function. Dependencies are specified with DataType, Autonomous, NonAutonomous and Fixed, NonFixed.

julia> FeedbackControl(x -> x[1]^2+2x[2], Int64)
IncorrectArgument
julia> FeedbackControl(x -> x[1]^2+2x[2], Int64)
IncorrectArgument
julia> u = FeedbackControl(x -> x[1]^2+2x[2], Autonomous, Fixed)
julia> u = FeedbackControl((x, v) -> x[1]^2+2x[2]+v[3], Autonomous, NonFixed)
julia> u = FeedbackControl((t, x) -> t+x[1]^2+2x[2], NonAutonomous, Fixed)
julia> u = FeedbackControl((t, x, v) -> t+x[1]^2+2x[2]+v[3], NonAutonomous, NonFixed)
source
CTBase.FeedbackControlMethod
FeedbackControl(
    f::Function;
    autonomous,
    variable
) -> FeedbackControl{Autonomous, Fixed}

Return the FeedbackControl of a function. Dependencies are specified with a boolean, variable, false by default, autonomous, true by default.

julia> u = FeedbackControl(x -> x[1]^2+2x[2], autonomous=true, variable=false)
julia> u = FeedbackControl((x, v) -> x[1]^2+2x[2]+v[3], autonomous=true, variable=true)
julia> u = FeedbackControl((t, x) -> t+x[1]^2+2x[2], autonomous=false, variable=false)
julia> u = FeedbackControl((t, x, v) -> t+x[1]^2+2x[2]+v[3], autonomous=false, variable=true)
source
CTBase.FeedbackControlMethod

Return the value of the FeedbackControl function.

julia> FeedbackControl(x -> x[1]^2+2x[2], Int64)
IncorrectArgument
julia> FeedbackControl(x -> x[1]^2+2x[2], Int64)
IncorrectArgument
julia> u = FeedbackControl(x -> x[1]^2+2x[2], autonomous=true, variable=false)
julia> u([1, 0])
1
julia> t = 1
julia> v = Real[]
julia> u(t, [1, 0])
MethodError
julia> u([1, 0], v)
MethodError
julia> u(t, [1, 0], v)
1
julia> u = FeedbackControl((x, v) -> x[1]^2+2x[2]+v[3], autonomous=true, variable=true)
julia> u([1, 0], [1, 2, 3])
4
julia> u(t, [1, 0], [1, 2, 3])
4
julia> u = FeedbackControl((t, x) -> t+x[1]^2+2x[2], autonomous=false, variable=false)
julia> u(1, [1, 0])
2
julia> u(1, [1, 0], v)
2
julia> u = FeedbackControl((t, x, v) -> t+x[1]^2+2x[2]+v[3], autonomous=false, variable=true)
julia> u(1, [1, 0], [1, 2, 3])
5
source
CTBase.HamiltonianType
struct Hamiltonian{time_dependence, variable_dependence} <: AbstractHamiltonian{time_dependence, variable_dependence}

Fields

  • f::Function

The default values for time_dependence and variable_dependence are Autonomous and Fixed respectively.

Constructor

The constructor Hamiltonian returns a Hamiltonian of a function. The function must take 2 to 4 arguments, (x, p) to (t, x, p, v), if the function is variable or non autonomous, it must be specified. Dependencies are specified either with :

  • booleans, autonomous and variable, respectively true and false by default
  • DataType, Autonomous/NonAutonomous and NonFixed/Fixed, respectively Autonomous and Fixed by default.

Examples

julia> Hamiltonian((x, p) -> x + p, Int64)
IncorrectArgument 
julia> Hamiltonian((x, p) -> x + p, Int64)
IncorrectArgument
julia> H = Hamiltonian((x, p) -> x[1]^2+2p[2])
julia> H = Hamiltonian((t, x, p, v) -> [t+x[1]^2+2p[2]+v[3]], autonomous=false, variable=true)
julia> H = Hamiltonian((t, x, p, v) -> [t+x[1]^2+2p[2]+v[3]], NonAutonomous, NonFixed)
Warning

When the state and costate are of dimension 1, consider x and p as scalars.

Call

The call returns the evaluation of the Hamiltonian for given values.

Examples

julia> H = Hamiltonian((x, p) -> [x[1]^2+2p[2]]) # autonomous=true, variable=false
julia> H([1, 0], [0, 1])
MethodError # H must return a scalar
julia> H = Hamiltonian((x, p) -> x[1]^2+2p[2])
julia> H([1, 0], [0, 1])
3
julia> t = 1
julia> v = Real[]
julia> H(t, [1, 0], [0, 1])
MethodError
julia> H([1, 0], [0, 1], v)
MethodError 
julia> H(t, [1, 0], [0, 1], v)
3
julia> H = Hamiltonian((x, p, v) -> x[1]^2+2p[2]+v[3], variable=true)
julia> H([1, 0], [0, 1], [1, 2, 3])
6
julia> H(t, [1, 0], [0, 1], [1, 2, 3])
6
julia> H = Hamiltonian((t, x, p) -> t+x[1]^2+2p[2], autonomous=false)
julia> H(1, [1, 0], [0, 1])
4
julia> H(1, [1, 0], [0, 1], v)
4
julia> H = Hamiltonian((t, x, p, v) -> t+x[1]^2+2p[2]+v[3], autonomous=false, variable=true)
julia> H(1, [1, 0], [0, 1], [1, 2, 3])
7
source
CTBase.HamiltonianMethod
Hamiltonian(
    f::Function,
    dependencies::DataType...
) -> Hamiltonian{Autonomous, Fixed}

Return an Hamiltonian of a function. Dependencies are specified with DataType, Autonomous, NonAutonomous and Fixed, NonFixed.

julia> H = Hamiltonian((x, p) -> x[1]^2+2p[2])
julia> H = Hamiltonian((t, x, p, v) -> [t+x[1]^2+2p[2]+v[3]], NonAutonomous, NonFixed)
source
CTBase.HamiltonianMethod
Hamiltonian(
    f::Function;
    autonomous,
    variable
) -> Hamiltonian{Autonomous, Fixed}

Return an Hamiltonian of a function. Dependencies are specified with a boolean, variable, false by default, autonomous, true by default.

julia> H = Hamiltonian((x, p) -> x[1]^2+2p[2])
julia> H = Hamiltonian((t, x, p, v) -> [t+x[1]^2+2p[2]+v[3]], autonomous=false, variable=true)
source
CTBase.HamiltonianMethod

Return the value of the Hamiltonian.

julia> Hamiltonian((x, p) -> x + p, Int64)
IncorrectArgument 
julia> Hamiltonian((x, p) -> x + p, Int64)
IncorrectArgument
julia> H = Hamiltonian((x, p) -> [x[1]^2+2p[2]]) # autonomous=true, variable=false
julia> H([1, 0], [0, 1])
MethodError # H must return a scalar
julia> H = Hamiltonian((x, p) -> x[1]^2+2p[2])
julia> H([1, 0], [0, 1])
3
julia> t = 1
julia> v = Real[]
julia> H(t, [1, 0], [0, 1])
MethodError
julia> H([1, 0], [0, 1], v)
MethodError 
julia> H(t, [1, 0], [0, 1], v)
3
julia> H = Hamiltonian((x, p, v) -> x[1]^2+2p[2]+v[3], variable=true)
julia> H([1, 0], [0, 1], [1, 2, 3])
6
julia> H(t, [1, 0], [0, 1], [1, 2, 3])
6
julia> H = Hamiltonian((t, x, p) -> t+x[1]^2+2p[2], autonomous=false)
julia> H(1, [1, 0], [0, 1])
4
julia> H(1, [1, 0], [0, 1], v)
4
julia> H = Hamiltonian((t, x, p, v) -> t+x[1]^2+2p[2]+v[3], autonomous=false, variable=true)
julia> H(1, [1, 0], [0, 1], [1, 2, 3])
7
source
CTBase.HamiltonianLiftType
struct HamiltonianLift{time_dependence, variable_dependence} <: AbstractHamiltonian{time_dependence, variable_dependence}

Lifts

  • X::VectorField

The values for time_dependence and variable_dependence are deternimed by the values of those for the VectorField.

Constructor

The constructor HamiltonianLift returns a HamiltonianLift of a VectorField.

Examples

julia> H = HamiltonianLift(VectorField(x -> [x[1]^2, 2x[2]]))
julia> H = HamiltonianLift(VectorField((x, v) -> [x[1]^2, 2x[2]+v[3]], variable=true))
julia> H = HamiltonianLift(VectorField((t, x) -> [t+x[1]^2, 2x[2]], autonomous=false))
julia> H = HamiltonianLift(VectorField((t, x, v) -> [t+x[1]^2, 2x[2]+v[3]], autonomous=false, variable=true))
julia> H = HamiltonianLift(VectorField(x -> [x[1]^2, 2x[2]]))
julia> H = HamiltonianLift(VectorField((x, v) -> [x[1]^2, 2x[2]+v[3]], NonFixed))
julia> H = HamiltonianLift(VectorField((t, x) -> [t+x[1]^2, 2x[2]], NonAutonomous))
julia> H = HamiltonianLift(VectorField((t, x, v) -> [t+x[1]^2, 2x[2]+v[3]], NonAutonomous, NonFixed))
Warning

When the state and costate are of dimension 1, consider x and p as scalars.

Call

The call returns the evaluation of the HamiltonianLift for given values.

Examples

julia> H = HamiltonianLift(VectorField(x -> [x[1]^2, 2x[2]]))
julia> H([1, 2], [1, 1])
5
julia> t = 1
julia> v = Real[]
julia> H(t, [1, 0], [0, 1])
MethodError
julia> H([1, 0], [0, 1], v)
MethodError 
julia> H(t, [1, 0], [0, 1], v)
5
julia> H = HamiltonianLift(VectorField((x, v) -> [x[1]^2, 2x[2]+v[3]], variable=true))
julia> H([1, 0], [0, 1], [1, 2, 3])
3
julia> H(t, [1, 0], [0, 1], [1, 2, 3])
3
julia> H = HamiltonianLift(VectorField((t, x) -> [t+x[1]^2, 2x[2]], autonomous=false))
julia> H(1, [1, 2], [1, 1])
6
julia> H(1, [1, 0], [0, 1], v)
6
julia> H = HamiltonianLift(VectorField((t, x, v) -> [t+x[1]^2, 2x[2]+v[3]], autonomous=false, variable=true))
julia> H(1, [1, 0], [0, 1], [1, 2, 3])
3

Alternatively, it is possible to construct the HamiltonianLift from a Function being the VectorField.

julia> HL1 = HamiltonianLift((x, v) -> [x[1]^2,x[2]^2+v], autonomous=true, variable=true)
julia> HL2 = HamiltonianLift(VectorField((x, v) -> [x[1]^2,x[2]^2+v], autonomous=true, variable=true))
julia> HL1([1, 0], [0, 1], 1) == HL2([1, 0], [0, 1], 1)
true
source
CTBase.HamiltonianLiftMethod
HamiltonianLift(
    f::Function,
    dependences::DataType...
) -> HamiltonianLift

Return an HamiltonianLift of a function. Dependencies are specified with DataType, Autonomous, NonAutonomous and Fixed, NonFixed.

julia> HamiltonianLift(HamiltonianLift(VectorField(x -> [x[1]^2, 2x[2]], Int64))
IncorrectArgument 
julia> HL = HamiltonianLift(x -> [x[1]^2,x[2]^2], Autonomous, Fixed)
julia> HL = HamiltonianLift((x, v) -> [x[1]^2,x[2]^2+v], Autonomous, NonFixed)
julia> HL = HamiltonianLift((t, x) -> [t+x[1]^2,x[2]^2], NonAutonomous, Fixed)
julia> HL = HamiltonianLift((t, x, v) -> [t+x[1]^2,x[2]^2+v], NonAutonomous, NonFixed)
source
CTBase.HamiltonianLiftMethod
HamiltonianLift(
    f::Function;
    autonomous,
    variable
) -> HamiltonianLift

Return an HamiltonianLift of a function. Dependencies are specified with a boolean, variable, false by default, autonomous, true by default.

julia> HL = HamiltonianLift(x -> [x[1]^2,x[2]^2], autonomous=true, variable=false)
julia> HL = HamiltonianLift((x, v) -> [x[1]^2,x[2]^2+v], autonomous=true, variable=true)
julia> HL = HamiltonianLift((t, x) -> [t+x[1]^2,x[2]^2], autonomous=false, variable=false)
julia> HL = HamiltonianLift((t, x, v) -> [t+x[1]^2,x[2]^2+v], autonomous=false, variable=true)
source
CTBase.HamiltonianLiftMethod

Return the value of the HamiltonianLift.

Examples

julia> HamiltonianLift(HamiltonianLift(VectorField(x -> [x[1]^2, 2x[2]], Int64))
IncorrectArgument 
julia> H = HamiltonianLift(VectorField(x -> [x[1]^2, 2x[2]]))
julia> H([1, 2], [1, 1])
5
julia> t = 1
julia> v = Real[]
julia> H(t, [1, 0], [0, 1])
MethodError
julia> H([1, 0], [0, 1], v)
MethodError 
julia> H(t, [1, 0], [0, 1], v)
5
julia> H = HamiltonianLift(VectorField((x, v) -> [x[1]^2, 2x[2]+v[3]], variable=true))
julia> H([1, 0], [0, 1], [1, 2, 3])
3
julia> H(t, [1, 0], [0, 1], [1, 2, 3])
3
julia> H = HamiltonianLift(VectorField((t, x) -> [t+x[1]^2, 2x[2]], autonomous=false))
julia> H(1, [1, 2], [1, 1])
6
julia> H(1, [1, 0], [0, 1], v)
6
julia> H = HamiltonianLift(VectorField((t, x, v) -> [t+x[1]^2, 2x[2]+v[3]], autonomous=false, variable=true))
julia> H(1, [1, 0], [0, 1], [1, 2, 3])
3
source
CTBase.HamiltonianVectorFieldType
struct HamiltonianVectorField{time_dependence, variable_dependence} <: CTBase.AbstractVectorField{time_dependence, variable_dependence}

Fields

  • f::Function

The default values for time_dependence and variable_dependence are Autonomous and Fixed respectively.

Constructor

The constructor HamiltonianVectorField returns a HamiltonianVectorField of a function. The function must take 2 to 4 arguments, (x, p) to (t, x, p, v), if the function is variable or non autonomous, it must be specified. Dependencies are specified either with :

  • booleans, autonomous and variable, respectively true and false by default
  • DataType, Autonomous/NonAutonomous and NonFixed/Fixed, respectively Autonomous and Fixed by default.

Examples

julia> HamiltonianVectorField((x, p) -> [x[1]^2+2p[2], x[2]-3p[2]^2], Int64)
IncorrectArgument
julia> HamiltonianVectorField((x, p) -> [x[1]^2+2p[2], x[2]-3p[2]^2], Int64)
IncorrectArgument
julia> Hv = HamiltonianVectorField((x, p) -> [x[1]^2+2p[2], x[2]-3p[2]^2]) # autonomous=true, variable=false
julia> Hv = HamiltonianVectorField((x, p, v) -> [x[1]^2+2p[2]+v[3], x[2]-3p[2]^2+v[4]], variable=true)
julia> Hv = HamiltonianVectorField((t, x, p) -> [t+x[1]^2+2p[2], x[2]-3p[2]^2], autonomous=false)
julia> Hv = HamiltonianVectorField((t, x, p, v) -> [t+x[1]^2+2p[2]+v[3], x[2]-3p[2]^2+v[4]], autonomous=false, variable=true)
julia> Hv = HamiltonianVectorField((x, p, v) -> [x[1]^2+2p[2]+v[3], x[2]-3p[2]^2+v[4]], NonFixed)
julia> Hv = HamiltonianVectorField((t, x, p) -> [t+x[1]^2+2p[2], x[2]-3p[2]^2], NonAutonomous)
julia> Hv = HamiltonianVectorField((t, x, p, v) -> [t+x[1]^2+2p[2]+v[3], x[2]-3p[2]^2+v[4]], NonAutonomous, NonFixed)
Warning

When the state and costate are of dimension 1, consider x and p as scalars.

Call

The call returns the evaluation of the HamiltonianVectorField for given values.

Examples

julia> Hv = HamiltonianVectorField((x, p) -> [x[1]^2+2p[2], x[2]-3p[2]^2]) # autonomous=true, variable=false
julia> Hv([1, 0], [0, 1])
[3, -3]
julia> t = 1
julia> v = Real[]
julia> Hv(t, [1, 0], [0, 1])
MethodError
julia> Hv([1, 0], [0, 1], v)
MethodError
julia> Hv(t, [1, 0], [0, 1], v)
[3, -3]
julia> Hv = HamiltonianVectorField((x, p, v) -> [x[1]^2+2p[2]+v[3], x[2]-3p[2]^2+v[4]], variable=true)
julia> Hv([1, 0], [0, 1], [1, 2, 3, 4])
[6, -3]
julia> Hv(t, [1, 0], [0, 1], [1, 2, 3, 4])
[6, -3]
julia> Hv = HamiltonianVectorField((t, x, p) -> [t+x[1]^2+2p[2], x[2]-3p[2]^2], autonomous=false)
julia> Hv(1, [1, 0], [0, 1])
[4, -3]
julia> Hv(1, [1, 0], [0, 1], v)
[4, -3]
julia> Hv = HamiltonianVectorField((t, x, p, v) -> [t+x[1]^2+2p[2]+v[3], x[2]-3p[2]^2+v[4]], autonomous=false, variable=true)
julia> Hv(1, [1, 0], [0, 1], [1, 2, 3, 4])
[7, -3]
source
CTBase.HamiltonianVectorFieldMethod
HamiltonianVectorField(
    f::Function,
    dependencies::DataType...
) -> HamiltonianVectorField{Autonomous, Fixed}

Return an HamiltonianVectorField of a function. Dependencies are specified with DataType, Autonomous, NonAutonomous and Fixed, NonFixed.

julia> HamiltonianVectorField((x, p) -> [x[1]^2+2p[2], x[2]-3p[2]^2], Int64)
IncorrectArgument
julia> HamiltonianVectorField((x, p) -> [x[1]^2+2p[2], x[2]-3p[2]^2], Int64)
IncorrectArgument
julia> Hv = HamiltonianVectorField((x, p) -> [x[1]^2+2p[2], x[2]-3p[2]^2]) # autonomous=true, variable=false
julia> Hv = HamiltonianVectorField((x, p, v) -> [x[1]^2+2p[2]+v[3], x[2]-3p[2]^2+v[4]], NonFixed)
julia> Hv = HamiltonianVectorField((t, x, p) -> [t+x[1]^2+2p[2], x[2]-3p[2]^2], NonAutonomous)
julia> Hv = HamiltonianVectorField((t, x, p, v) -> [t+x[1]^2+2p[2]+v[3], x[2]-3p[2]^2+v[4]], NonAutonomous, NonFixed)
source
CTBase.HamiltonianVectorFieldMethod
HamiltonianVectorField(
    f::Function;
    autonomous,
    variable
) -> HamiltonianVectorField{Autonomous, Fixed}

Return an HamiltonianVectorField of a function. Dependencies are specified with a boolean, variable, false by default, autonomous, true by default.

julia> Hv = HamiltonianVectorField((x, p) -> [x[1]^2+2p[2], x[2]-3p[2]^2]) # autonomous=true, variable=false
julia> Hv = HamiltonianVectorField((x, p, v) -> [x[1]^2+2p[2]+v[3], x[2]-3p[2]^2+v[4]], variable=true)
julia> Hv = HamiltonianVectorField((t, x, p) -> [t+x[1]^2+2p[2], x[2]-3p[2]^2], autonomous=false)
julia> Hv = HamiltonianVectorField((t, x, p, v) -> [t+x[1]^2+2p[2]+v[3], x[2]-3p[2]^2+v[4]], autonomous=false, variable=true)
source
CTBase.HamiltonianVectorFieldMethod

Return the value of the HamiltonianVectorField.

Examples

julia> HamiltonianVectorField((x, p) -> [x[1]^2+2p[2], x[2]-3p[2]^2], Int64)
IncorrectArgument
julia> HamiltonianVectorField((x, p) -> [x[1]^2+2p[2], x[2]-3p[2]^2], Int64)
IncorrectArgument
julia> Hv = HamiltonianVectorField((x, p) -> [x[1]^2+2p[2], x[2]-3p[2]^2]) # autonomous=true, variable=false
julia> Hv([1, 0], [0, 1])
[3, -3]
julia> t = 1
julia> v = Real[]
julia> Hv(t, [1, 0], [0, 1])
MethodError
julia> Hv([1, 0], [0, 1], v)
MethodError
julia> Hv(t, [1, 0], [0, 1], v)
[3, -3]
julia> Hv = HamiltonianVectorField((x, p, v) -> [x[1]^2+2p[2]+v[3], x[2]-3p[2]^2+v[4]], variable=true)
julia> Hv([1, 0], [0, 1], [1, 2, 3, 4])
[6, -3]
julia> Hv(t, [1, 0], [0, 1], [1, 2, 3, 4])
[6, -3]
julia> Hv = HamiltonianVectorField((t, x, p) -> [t+x[1]^2+2p[2], x[2]-3p[2]^2], autonomous=false)
julia> Hv(1, [1, 0], [0, 1])
[4, -3]
julia> Hv(1, [1, 0], [0, 1], v)
[4, -3]
julia> Hv = HamiltonianVectorField((t, x, p, v) -> [t+x[1]^2+2p[2]+v[3], x[2]-3p[2]^2+v[4]], autonomous=false, variable=true)
julia> Hv(1, [1, 0], [0, 1], [1, 2, 3, 4])
[7, -3]
source
CTBase.LagrangeType
struct Lagrange{time_dependence, variable_dependence}

Fields

  • f::Function

The default value for time_dependence and variable_dependence are Autonomous and Fixed respectively.

Constructor

The constructor Lagrange returns a Lagrange cost of a function. The function must take 2 to 4 arguments, (x, u) to (t, x, u, v), if the function is variable or non autonomous, it must be specified. Dependencies are specified either with :

  • booleans, autonomous and variable, respectively true and false by default
  • DataType, Autonomous/NonAutonomous and NonFixed/Fixed, respectively Autonomous and Fixed by default.

Examples

julia> Lagrange((x, u) -> 2x[2]-u[1]^2, Int64)
IncorrectArgument
julia> Lagrange((x, u) -> 2x[2]-u[1]^2, Int64)
IncorrectArgument
julia> L = Lagrange((x, u) -> [2x[2]-u[1]^2], autonomous=true, variable=false)
julia> L = Lagrange((x, u) -> 2x[2]-u[1]^2, autonomous=true, variable=false)
julia> L = Lagrange((x, u, v) -> 2x[2]-u[1]^2+v[3], autonomous=true, variable=true)
julia> L = Lagrange((t, x, u) -> t+2x[2]-u[1]^2, autonomous=false, variable=false)
julia> L = Lagrange((t, x, u, v) -> t+2x[2]-u[1]^2+v[3], autonomous=false, variable=true)
julia> L = Lagrange((x, u) -> [2x[2]-u[1]^2], Autonomous, Fixed)
julia> L = Lagrange((x, u) -> 2x[2]-u[1]^2, Autonomous, Fixed)
julia> L = Lagrange((x, u, v) -> 2x[2]-u[1]^2+v[3], Autonomous, NonFixed)
julia> L = Lagrange((t, x, u) -> t+2x[2]-u[1]^2, autonomous=false, Fixed)
julia> L = Lagrange((t, x, u, v) -> t+2x[2]-u[1]^2+v[3], autonomous=false, NonFixed)
Warning

When the state is of dimension 1, consider x as a scalar. Same for the control.

Call

The call returns the evaluation of the Lagrange cost for given values.

Examples

julia> L = Lagrange((x, u) -> [2x[2]-u[1]^2], autonomous=true, variable=false)
julia> L([1, 0], [1])
MethodError
julia> L = Lagrange((x, u) -> 2x[2]-u[1]^2, autonomous=true, variable=false)
julia> L([1, 0], [1])
-1
julia> t = 1
julia> v = Real[]
julia> L(t, [1, 0], [1])
MethodError
julia> L([1, 0], [1], v)
MethodError
julia> L(t, [1, 0], [1], v)
-1
julia> L = Lagrange((x, u, v) -> 2x[2]-u[1]^2+v[3], autonomous=true, variable=true)
julia> L([1, 0], [1], [1, 2, 3])
2
julia> L(t, [1, 0], [1], [1, 2, 3])
2
julia> L = Lagrange((t, x, u) -> t+2x[2]-u[1]^2, autonomous=false, variable=false)
julia> L(1, [1, 0], [1])
0
julia> L(1, [1, 0], [1], v)
0
julia> L = Lagrange((t, x, u, v) -> t+2x[2]-u[1]^2+v[3], autonomous=false, variable=true)
julia> L(1, [1, 0], [1], [1, 2, 3])
3
source
CTBase.LagrangeMethod
Lagrange(
    f::Function,
    dependencies::DataType...
) -> Lagrange{Autonomous, Fixed}

Return a Lagrange cost of a function. Dependencies are specified with DataType, Autonomous, NonAutonomous and Fixed, NonFixed.

julia> Lagrange((x, u) -> 2x[2]-u[1]^2, Int64)
IncorrectArgument
julia> Lagrange((x, u) -> 2x[2]-u[1]^2, Int64)
IncorrectArgument
julia> L = Lagrange((x, u) -> [2x[2]-u[1]^2], autonomous=true, variable=false)
julia> L = Lagrange((x, u) -> 2x[2]-u[1]^2, autonomous=true, variable=false)
julia> L = Lagrange((x, u, v) -> 2x[2]-u[1]^2+v[3], autonomous=true, variable=true)
julia> L = Lagrange((t, x, u) -> t+2x[2]-u[1]^2, autonomous=false, variable=false)
julia> L = Lagrange((t, x, u, v) -> t+2x[2]-u[1]^2+v[3], autonomous=false, variable=true)
source
CTBase.LagrangeMethod
Lagrange(
    f::Function;
    autonomous,
    variable
) -> Lagrange{Autonomous, Fixed}

Return a Lagrange cost of a function. Dependencies are specified with a boolean, variable, false by default, autonomous, true by default.

julia> L = Lagrange((x, u) -> [2x[2]-u[1]^2], autonomous=true, variable=false)
julia> L = Lagrange((x, u) -> 2x[2]-u[1]^2, autonomous=true, variable=false)
julia> L = Lagrange((x, u, v) -> 2x[2]-u[1]^2+v[3], autonomous=true, variable=true)
julia> L = Lagrange((t, x, u) -> t+2x[2]-u[1]^2, autonomous=false, variable=false)
julia> L = Lagrange((t, x, u, v) -> t+2x[2]-u[1]^2+v[3], autonomous=false, variable=true)
source
CTBase.LagrangeMethod

Return the value of the Lagrange function.

Examples

julia> Lagrange((x, u) -> 2x[2]-u[1]^2, Int64)
IncorrectArgument
julia> Lagrange((x, u) -> 2x[2]-u[1]^2, Int64)
IncorrectArgument
julia> L = Lagrange((x, u) -> [2x[2]-u[1]^2], autonomous=true, variable=false)
julia> L([1, 0], [1])
MethodError
julia> L = Lagrange((x, u) -> 2x[2]-u[1]^2, autonomous=true, variable=false)
julia> L([1, 0], [1])
-1
julia> t = 1
julia> v = Real[]
julia> L(t, [1, 0], [1])
MethodError
julia> L([1, 0], [1], v)
MethodError
julia> L(t, [1, 0], [1], v)
-1
julia> L = Lagrange((x, u, v) -> 2x[2]-u[1]^2+v[3], autonomous=true, variable=true)
julia> L([1, 0], [1], [1, 2, 3])
2
julia> L(t, [1, 0], [1], [1, 2, 3])
2
julia> L = Lagrange((t, x, u) -> t+2x[2]-u[1]^2, autonomous=false, variable=false)
julia> L(1, [1, 0], [1])
0
julia> L(1, [1, 0], [1], v)
0
julia> L = Lagrange((t, x, u, v) -> t+2x[2]-u[1]^2+v[3], autonomous=false, variable=true)
julia> L(1, [1, 0], [1], [1, 2, 3])
3
source
CTBase.MayerType
struct Mayer{variable_dependence}

Fields

  • f::Function

The default value for variable_dependence is Fixed.

Constructor

The constructor Mayer returns a Mayer cost of a function. The function must take 2 or 3 arguments (x0, xf) or (x0, xf, v), if the function is variable, it must be specified. Dependencies are specified with a boolean, variable, false by default or with a DataType, NonFixed/Fixed, Fixed by default.

Examples

julia> G = Mayer((x0, xf) -> xf[2]-x0[1])
julia> G = Mayer((x0, xf, v) -> v[3]+xf[2]-x0[1], variable=true)
julia> G = Mayer((x0, xf, v) -> v[3]+xf[2]-x0[1], NonFixed)
Warning

When the state is of dimension 1, consider x0 and xf as a scalar.

Call

The call returns the evaluation of the Mayer cost for given values. If a variable is given for a non variable dependent Mayer cost, it will be ignored.

Examples

julia> G = Mayer((x0, xf) -> xf[2]-x0[1])
julia> G([0, 0], [1, 1])
1
julia> G = Mayer((x0, xf) -> xf[2]-x0[1])
julia> G([0, 0], [1, 1],Real[])
1
julia> G = Mayer((x0, xf, v) -> v[3]+xf[2]-x0[1], variable=true)
julia> G([0, 0], [1, 1], [1, 2, 3])
4
source
CTBase.MayerMethod
Mayer(
    f::Function,
    dependencies::DataType...
) -> Mayer{Fixed}

Return a Mayer cost of a function. Dependencies are specified with a DataType, NonFixed/Fixed, Fixed by default.

julia> G = Mayer((x0, xf) -> xf[2]-x0[1])
julia> G = Mayer((x0, xf, v) -> v[3]+xf[2]-x0[1], NonFixed)
source
CTBase.MayerMethod
Mayer(f::Function; variable) -> Mayer{Fixed}

Return a Mayer cost of a function. Dependencies are specified with a boolean, variable, false by default.

julia> G = Mayer((x0, xf) -> xf[2]-x0[1])
julia> G = Mayer((x0, xf, v) -> v[3]+xf[2]-x0[1], variable=true)
source
CTBase.MayerMethod

Return the evaluation of the Mayer cost.

julia> G = Mayer((x0, xf) -> xf[2]-x0[1])
julia> G([0, 0], [1, 1])
1
julia> G = Mayer((x0, xf) -> xf[2]-x0[1])
julia> G([0, 0], [1, 1], Real[])
1
julia> G = Mayer((x0, xf, v) -> v[3]+xf[2]-x0[1], variable=true)
julia> G([0, 0], [1, 1], [1, 2, 3])
4
source
CTBase.MixedConstraintType
struct MixedConstraint{time_dependence, variable_dependence}

Fields

  • f::Function

Similar to Lagrange in the usage, but the dimension of the output of the function f is arbitrary.

The default value for time_dependence and variable_dependence are Autonomous and Fixed respectively.

Constructor

The constructor MixedConstraint returns a MixedConstraint of a function. The function must take 2 to 4 arguments, (x, u) to (t, x, u, v), if the function is variable or non autonomous, it must be specified. Dependencies are specified either with :

  • booleans, autonomous and variable, respectively true and false by default
  • DataType, Autonomous/NonAutonomous and NonFixed/Fixed, respectively Autonomous and Fixed by default.

Examples

julia> MixedConstraint((x, u) -> [2x[2]-u^2, x[1]], Int64)
IncorrectArgument
julia> MixedConstraint((x, u) -> [2x[2]-u^2, x[1]], Int64)
IncorrectArgument
julia> M = MixedConstraint((x, u) -> [2x[2]-u^2, x[1]], Autonomous, Fixed)
julia> M = MixedConstraint((x, u, v) -> [2x[2]-u^2+v[3], x[1]], Autonomous, NonFixed)
julia> M = MixedConstraint((t, x, u) -> [t+2x[2]-u^2, x[1]], NonAutonomous, Fixed)
julia> M = MixedConstraint((t, x, u, v) -> [t+2x[2]-u^2+v[3], x[1]], NonAutonomous, NonFixed)
julia> M = MixedConstraint((x, u) -> [2x[2]-u^2, x[1]], autonomous=true, variable=false)
julia> M = MixedConstraint((x, u, v) -> [2x[2]-u^2+v[3], x[1]], autonomous=true, variable=true)
julia> M = MixedConstraint((t, x, u) -> [t+2x[2]-u^2, x[1]], autonomous=false, variable=false)
julia> M = MixedConstraint((t, x, u, v) -> [t+2x[2]-u^2+v[3], x[1]], autonomous=false, variable=true)
Warning

When the state is of dimension 1, consider x as a scalar. Same for the control.

Call

The call returns the evaluation of the MixedConstraint for given values.

Examples

julia> MixedConstraint((x, u) -> [2x[2]-u^2, x[1]], Int64)
IncorrectArgument
julia> MixedConstraint((x, u) -> [2x[2]-u^2, x[1]], Int64)
IncorrectArgument
julia> M = MixedConstraint((x, u) -> [2x[2]-u^2, x[1]], autonomous=true, variable=false)
julia> M([1, 0], 1)
[-1, 1]
julia> t = 1
julia> v = Real[]
julia> MethodError M(t, [1, 0], 1)
julia> MethodError M([1, 0], 1, v)
julia> M(t, [1, 0], 1, v)
[-1, 1]
julia> M = MixedConstraint((x, u, v) -> [2x[2]-u^2+v[3], x[1]], autonomous=true, variable=true)
julia> M([1, 0], 1, [1, 2, 3])
[2, 1]
julia> M(t, [1, 0], 1, [1, 2, 3])
[2, 1]
julia> M = MixedConstraint((t, x, u) -> [t+2x[2]-u^2, x[1]], autonomous=false, variable=false)
julia> M(1, [1, 0], 1)
[0, 1]
julia> M(1, [1, 0], 1, v)
[0, 1]
julia> M = MixedConstraint((t, x, u, v) -> [t+2x[2]-u^2+v[3], x[1]], autonomous=false, variable=true)
julia> M(1, [1, 0], 1, [1, 2, 3])
[3, 1]
source
CTBase.MixedConstraintMethod
MixedConstraint(
    f::Function,
    dependencies::DataType...
) -> MixedConstraint{Autonomous, Fixed}

Return the MixedConstraint of a function. Dependencies are specified with DataType, Autonomous, NonAutonomous and Fixed, NonFixed.

julia> MixedConstraint((x, u) -> [2x[2]-u^2, x[1]], Int64)
IncorrectArgument
julia> MixedConstraint((x, u) -> [2x[2]-u^2, x[1]], Int64)
IncorrectArgument
julia> M = MixedConstraint((x, u) -> [2x[2]-u^2, x[1]], Autonomous, Fixed)
julia> M = MixedConstraint((x, u, v) -> [2x[2]-u^2+v[3], x[1]], Autonomous, NonFixed)
julia> M = MixedConstraint((t, x, u) -> [t+2x[2]-u^2, x[1]], NonAutonomous, Fixed)
julia> M = MixedConstraint((t, x, u, v) -> [t+2x[2]-u^2+v[3], x[1]], NonAutonomous, NonFixed)
source
CTBase.MixedConstraintMethod
MixedConstraint(
    f::Function;
    autonomous,
    variable
) -> MixedConstraint{Autonomous, Fixed}

Return the MixedConstraint of a function. Dependencies are specified with a boolean, variable, false by default, autonomous, true by default.

julia> M = MixedConstraint((x, u) -> [2x[2]-u^2, x[1]], autonomous=true, variable=false)
julia> M = MixedConstraint((x, u, v) -> [2x[2]-u^2+v[3], x[1]], autonomous=true, variable=true)
julia> M = MixedConstraint((t, x, u) -> [t+2x[2]-u^2, x[1]], autonomous=false, variable=false)
julia> M = MixedConstraint((t, x, u, v) -> [t+2x[2]-u^2+v[3], x[1]], autonomous=false, variable=true)
source
CTBase.MixedConstraintMethod

Return the value of the MixedConstraint function.

julia> MixedConstraint((x, u) -> [2x[2]-u^2, x[1]], Int64)
IncorrectArgument
julia> MixedConstraint((x, u) -> [2x[2]-u^2, x[1]], Int64)
IncorrectArgument
julia> M = MixedConstraint((x, u) -> [2x[2]-u^2, x[1]], autonomous=true, variable=false)
julia> M([1, 0], 1)
[-1, 1]
julia> t = 1
julia> v = Real[]
julia> MethodError M(t, [1, 0], 1)
julia> MethodError M([1, 0], 1, v)
julia> M(t, [1, 0], 1, v)
[-1, 1]
julia> M = MixedConstraint((x, u, v) -> [2x[2]-u^2+v[3], x[1]], autonomous=true, variable=true)
julia> M([1, 0], 1, [1, 2, 3])
[2, 1]
julia> M(t, [1, 0], 1, [1, 2, 3])
[2, 1]
julia> M = MixedConstraint((t, x, u) -> [t+2x[2]-u^2, x[1]], autonomous=false, variable=false)
julia> M(1, [1, 0], 1)
[0, 1]
julia> M(1, [1, 0], 1, v)
[0, 1]
julia> M = MixedConstraint((t, x, u, v) -> [t+2x[2]-u^2+v[3], x[1]], autonomous=false, variable=true)
julia> M(1, [1, 0], 1, [1, 2, 3])
[3, 1]
source
CTBase.MultiplierType
struct Multiplier{time_dependence, variable_dependence}

Fields

  • f::Function

Similar to ControlLaw in the usage.

The default values for time_dependence and variable_dependence are Autonomous and Fixed respectively.

Constructor

The constructor Multiplier returns a Multiplier of a function. The function must take 2 to 4 arguments, (x, p) to (t, x, p, v), if the function is variable or non autonomous, it must be specified. Dependencies are specified either with :

  • booleans, autonomous and variable, respectively true and false by default
  • DataType, Autonomous/NonAutonomous and NonFixed/Fixed, respectively Autonomous and Fixed by default.

Examples

julia> Multiplier((x, p) -> x[1]^2+2p[2], Int64)
IncorrectArgument
julia> Multiplier((x, p) -> x[1]^2+2p[2], Int64)
IncorrectArgument
julia> μ = Multiplier((x, p) -> x[1]^2+2p[2], Autonomous, Fixed)
julia> μ = Multiplier((x, p, v) -> x[1]^2+2p[2]+v[3], Autonomous, NonFixed)
julia> μ = Multiplier((t, x, p) -> t+x[1]^2+2p[2], NonAutonomous, Fixed)
julia> μ = Multiplier((t, x, p, v) -> t+x[1]^2+2p[2]+v[3], NonAutonomous, NonFixed)
julia> μ = Multiplier((x, p) -> x[1]^2+2p[2], autonomous=true, variable=false)
julia> μ = Multiplier((x, p, v) -> x[1]^2+2p[2]+v[3], autonomous=true, variable=true)
julia> μ = Multiplier((t, x, p) -> t+x[1]^2+2p[2], autonomous=false, variable=false)
julia> μ = Multiplier((t, x, p, v) -> t+x[1]^2+2p[2]+v[3], autonomous=false, variable=true)
Warning

When the state and costate are of dimension 1, consider x and p as scalars.

Call

The call returns the evaluation of the Multiplier for given values.

Examples

julia> μ = Multiplier((x, p) -> x[1]^2+2p[2], autonomous=true, variable=false)
julia> μ([1, 0], [0, 1])
3
julia> t = 1
julia> v = Real[]
julia> μ(t, [1, 0], [0, 1])
MethodError
julia> μ([1, 0], [0, 1], v)
MethodError
julia> μ(t, [1, 0], [0, 1], v)
3
julia> μ = Multiplier((x, p, v) -> x[1]^2+2p[2]+v[3], autonomous=true, variable=true)
julia> μ([1, 0], [0, 1], [1, 2, 3])
6
julia> μ(t, [1, 0], [0, 1], [1, 2, 3])
6
julia> μ = Multiplier((t, x, p) -> t+x[1]^2+2p[2], autonomous=false, variable=false)
julia> μ(1, [1, 0], [0, 1])
4
julia> μ(1, [1, 0], [0, 1], v)
4
julia> μ = Multiplier((t, x, p, v) -> t+x[1]^2+2p[2]+v[3], autonomous=false, variable=true)
julia> μ(1, [1, 0], [0, 1], [1, 2, 3])
7
source
CTBase.MultiplierMethod
Multiplier(
    f::Function,
    dependencies::DataType...
) -> Multiplier{Autonomous, Fixed}

Return the Multiplier of a function. Dependencies are specified with DataType, Autonomous, NonAutonomous and Fixed, NonFixed.

julia> Multiplier((x, p) -> x[1]^2+2p[2], Int64)
IncorrectArgument
julia> Multiplier((x, p) -> x[1]^2+2p[2], Int64)
IncorrectArgument
julia> μ = Multiplier((x, p) -> x[1]^2+2p[2], Autonomous, Fixed)
julia> μ = Multiplier((x, p, v) -> x[1]^2+2p[2]+v[3], Autonomous, NonFixed)
julia> μ = Multiplier((t, x, p) -> t+x[1]^2+2p[2], NonAutonomous, Fixed)
julia> μ = Multiplier((t, x, p, v) -> t+x[1]^2+2p[2]+v[3], NonAutonomous, NonFixed)
source
CTBase.MultiplierMethod
Multiplier(
    f::Function;
    autonomous,
    variable
) -> Multiplier{Autonomous, Fixed}

Return the Multiplier of a function. Dependencies are specified with a boolean, variable, false by default, autonomous, true by default.

julia> μ = Multiplier((x, p) -> x[1]^2+2p[2], autonomous=true, variable=false)
julia> μ = Multiplier((x, p, v) -> x[1]^2+2p[2]+v[3], autonomous=true, variable=true)
julia> μ = Multiplier((t, x, p) -> t+x[1]^2+2p[2], autonomous=false, variable=false)
julia> μ = Multiplier((t, x, p, v) -> t+x[1]^2+2p[2]+v[3], autonomous=false, variable=true)
source
CTBase.MultiplierMethod

Return the value of the Multiplier function.

julia> Multiplier((x, p) -> x[1]^2+2p[2], Int64)
IncorrectArgument
julia> Multiplier((x, p) -> x[1]^2+2p[2], Int64)
IncorrectArgument
julia> μ = Multiplier((x, p) -> x[1]^2+2p[2], autonomous=true, variable=false)
julia> μ([1, 0], [0, 1])
3
julia> t = 1
julia> v = Real[]
julia> μ(t, [1, 0], [0, 1])
MethodError
julia> μ([1, 0], [0, 1], v)
MethodError
julia> μ(t, [1, 0], [0, 1], v)
3
julia> μ = Multiplier((x, p, v) -> x[1]^2+2p[2]+v[3], autonomous=true, variable=true)
julia> μ([1, 0], [0, 1], [1, 2, 3])
6
julia> μ(t, [1, 0], [0, 1], [1, 2, 3])
6
julia> μ = Multiplier((t, x, p) -> t+x[1]^2+2p[2], autonomous=false, variable=false)
julia> μ(1, [1, 0], [0, 1])
4
julia> μ(1, [1, 0], [0, 1], v)
4
julia> μ = Multiplier((t, x, p, v) -> t+x[1]^2+2p[2]+v[3], autonomous=false, variable=true)
julia> μ(1, [1, 0], [0, 1], [1, 2, 3])
7
source
CTBase.NotImplementedType
struct NotImplemented <: CTException

Exception thrown when a method is not implemented.

Fields

  • var::String
source
CTBase.OCPInitType

Initialization of the OCP solution that can be used when solving the discretized problem DOCP.

Constructors:

  • OCPInit(): default initialization
  • OCPInit(x_init, u_init, v_init): constant vector and/or function handles
  • OCPInit(sol): from existing solution

Examples

julia> init = OCPInit()
julia> init = OCPInit(x_init=[0.1, 0.2], u_init=0.3)
julia> init = OCPInit(x_init=[0.1, 0.2], u_init=0.3, v_init=0.5)
julia> init = OCPInit(x_init=[0.1, 0.2], u_init=t->sin(t), v_init=0.5)
julia> init = OCPInit(sol)
source
CTBase.OptimalControlModelType
mutable struct OptimalControlModel{time_dependence<:TimeDependence, variable_dependence<:VariableDependence} <: CTBase.AbstractOptimalControlModel

Fields

  • model_expression::Union{Nothing, Expr}: Default: nothing

  • initial_time::Union{Nothing, Index, Real}: Default: nothing

  • initial_time_name::Union{Nothing, String}: Default: nothing

  • final_time::Union{Nothing, Index, Real}: Default: nothing

  • final_time_name::Union{Nothing, String}: Default: nothing

  • time_name::Union{Nothing, String}: Default: nothing

  • control_dimension::Union{Nothing, Integer}: Default: nothing

  • control_components_names::Union{Nothing, Vector{String}}: Default: nothing

  • control_name::Union{Nothing, String}: Default: nothing

  • state_dimension::Union{Nothing, Integer}: Default: nothing

  • state_components_names::Union{Nothing, Vector{String}}: Default: nothing

  • state_name::Union{Nothing, String}: Default: nothing

  • variable_dimension::Union{Nothing, Integer}: Default: nothing

  • variable_components_names::Union{Nothing, Vector{String}}: Default: nothing

  • variable_name::Union{Nothing, String}: Default: nothing

  • lagrange::Union{Nothing, Lagrange}: Default: nothing

  • mayer::Union{Nothing, Mayer}: Default: nothing

  • criterion::Union{Nothing, Symbol}: Default: nothing

  • dynamics::Union{Nothing, Dynamics}: Default: nothing

  • constraints::Dict{Symbol, Tuple}: Default: Dict{Symbol, Tuple{Vararg{Any}}}()

source
CTBase.OptimalControlSolutionType
mutable struct OptimalControlSolution <: CTBase.AbstractOptimalControlSolution

Type of an optimal control solution.

Fields

  • times::Union{Nothing, StepRangeLen, AbstractVector{<:Real}}: Default: nothing

  • initial_time_name::Union{Nothing, String}: Default: nothing

  • final_time_name::Union{Nothing, String}: Default: nothing

  • time_name::Union{Nothing, String}: Default: nothing

  • control_dimension::Union{Nothing, Integer}: Default: nothing

  • control_components_names::Union{Nothing, Vector{String}}: Default: nothing

  • control_name::Union{Nothing, String}: Default: nothing

  • control::Union{Nothing, Function}: Default: nothing

  • state_dimension::Union{Nothing, Integer}: Default: nothing

  • state_components_names::Union{Nothing, Vector{String}}: Default: nothing

  • state_name::Union{Nothing, String}: Default: nothing

  • state::Union{Nothing, Function}: Default: nothing

  • variable_dimension::Union{Nothing, Integer}: Default: nothing

  • variable_components_names::Union{Nothing, Vector{String}}: Default: nothing

  • variable_name::Union{Nothing, String}: Default: nothing

  • variable::Union{Nothing, Real, AbstractVector{<:Real}}: Default: nothing

  • costate::Union{Nothing, Function}: Default: nothing

  • objective::Union{Nothing, Real}: Default: nothing

  • iterations::Union{Nothing, Integer}: Default: nothing

  • stopping::Union{Nothing, Symbol}: Default: nothing

  • message::Union{Nothing, String}: Default: nothing

  • success::Union{Nothing, Bool}: Default: nothing

  • infos::Dict{Symbol, Any}: Default: Dict{Symbol, Any}()

source
CTBase.ParsingErrorType
struct ParsingError <: CTException

Exception thrown for syntax error during abstract parsing.

Fields

  • var::String
source
CTBase.StateConstraintType
struct StateConstraint{time_dependence, variable_dependence}

Fields

  • f::Function

Similar to VectorField in the usage, but the dimension of the output of the function f is arbitrary.

The default values for time_dependence and variable_dependence are Autonomous and Fixed respectively.

Constructor

The constructor StateConstraint returns a StateConstraint of a function. The function must take 1 to 3 arguments, x to (t, x, v), if the function is variable or non autonomous, it must be specified. Dependencies are specified either with :

  • booleans, autonomous and variable, respectively true and false by default
  • DataType, Autonomous/NonAutonomous and NonFixed/Fixed, respectively Autonomous and Fixed by default.

Examples

julia> StateConstraint(x -> [x[1]^2, 2x[2]], Int64)
IncorrectArgument
julia> StateConstraint(x -> [x[1]^2, 2x[2]], Int64)
IncorrectArgument
julia> S = StateConstraint(x -> [x[1]^2, 2x[2]], Autonomous, Fixed)
julia> S = StateConstraint((x, v) -> [x[1]^2, 2x[2]+v[3]], Autonomous, NonFixed)
julia> S = StateConstraint((t, x) -> [t+x[1]^2, 2x[2]], NonAutonomous, Fixed)
julia> S = StateConstraint((t, x, v) -> [t+x[1]^2, 2x[2]+v[3]], NonAutonomous, NonFixed)
julia> S = StateConstraint(x -> [x[1]^2, 2x[2]], autonomous=true, variable=false)
julia> S = StateConstraint((x, v) -> [x[1]^2, 2x[2]+v[3]], autonomous=true, variable=true)
julia> S = StateConstraint((t, x) -> [t+x[1]^2, 2x[2]], autonomous=false, variable=false)
julia> S = StateConstraint((t, x, v) -> [t+x[1]^2, 2x[2]+v[3]], autonomous=false, variable=true)
Warning

When the state is of dimension 1, consider x as a scalar.

Call

The call returns the evaluation of the StateConstraint for given values.

Examples

julia> StateConstraint(x -> [x[1]^2, 2x[2]], Int64)
IncorrectArgument
julia> StateConstraint(x -> [x[1]^2, 2x[2]], Int64)
IncorrectArgument
julia> S = StateConstraint(x -> [x[1]^2, 2x[2]], autonomous=true, variable=false)
julia> S([1, -1])
[1, -2]
julia> t = 1
julia> v = Real[]
julia> S(t, [1, -1], v)
[1, -2]
julia> S = StateConstraint((x, v) -> [x[1]^2, 2x[2]+v[3]], autonomous=true, variable=true)
julia> S([1, -1], [1, 2, 3])
[1, 1]
julia> S(t, [1, -1], [1, 2, 3])
[1, 1]
julia> S = StateConstraint((t, x) -> [t+x[1]^2, 2x[2]], autonomous=false, variable=false)
julia>  S(1, [1, -1])
[2, -2]
julia>  S(1, [1, -1], v)
[2, -2]
julia> S = StateConstraint((t, x, v) -> [t+x[1]^2, 2x[2]+v[3]], autonomous=false, variable=true)
julia>  S(1, [1, -1], [1, 2, 3])
[2, 1]
source
CTBase.StateConstraintMethod
StateConstraint(
    f::Function,
    dependencies::DataType...
) -> StateConstraint{Autonomous, Fixed}

Return the StateConstraint of a function. Dependencies are specified with DataType, Autonomous, NonAutonomous and Fixed, NonFixed.

julia> StateConstraint(x -> [x[1]^2, 2x[2]], Int64)
IncorrectArgument
julia> StateConstraint(x -> [x[1]^2, 2x[2]], Int64)
IncorrectArgument
julia> S = StateConstraint(x -> [x[1]^2, 2x[2]], Autonomous, Fixed)
julia> S = StateConstraint((x, v) -> [x[1]^2, 2x[2]+v[3]], Autonomous, NonFixed)
julia> S = StateConstraint((t, x) -> [t+x[1]^2, 2x[2]], NonAutonomous, Fixed)
julia> S = StateConstraint((t, x, v) -> [t+x[1]^2, 2x[2]+v[3]], NonAutonomous, NonFixed)
source
CTBase.StateConstraintMethod
StateConstraint(
    f::Function;
    autonomous,
    variable
) -> StateConstraint{Autonomous, Fixed}

Return the StateConstraint of a function. Dependencies are specified with a boolean, variable, false by default, autonomous, true by default.

julia> S = StateConstraint(x -> [x[1]^2, 2x[2]], autonomous=true, variable=false)
julia> S = StateConstraint((x, v) -> [x[1]^2, 2x[2]+v[3]], autonomous=true, variable=true)
julia> S = StateConstraint((t, x) -> [t+x[1]^2, 2x[2]], autonomous=false, variable=false)
julia> S = StateConstraint((t, x, v) -> [t+x[1]^2, 2x[2]+v[3]], autonomous=false, variable=true)
source
CTBase.StateConstraintMethod

Return the value of the StateConstraint function.

julia> StateConstraint(x -> [x[1]^2, 2x[2]], Int64)
IncorrectArgument
julia> StateConstraint(x -> [x[1]^2, 2x[2]], Int64)
IncorrectArgument
julia> S = StateConstraint(x -> [x[1]^2, 2x[2]], autonomous=true, variable=false)
julia> S([1, -1])
[1, -2]
julia> t = 1
julia> v = Real[]
julia> S(t, [1, -1], v)
[1, -2]
julia> S = StateConstraint((x, v) -> [x[1]^2, 2x[2]+v[3]], autonomous=true, variable=true)
julia> S([1, -1], [1, 2, 3])
[1, 1]
julia> S(t, [1, -1], [1, 2, 3])
[1, 1]
julia> S = StateConstraint((t, x) -> [t+x[1]^2, 2x[2]], autonomous=false, variable=false)
julia>  S(1, [1, -1])
[2, -2]
julia>  S(1, [1, -1], v)
[2, -2]
julia> S = StateConstraint((t, x, v) -> [t+x[1]^2, 2x[2]+v[3]], autonomous=false, variable=true)
julia>  S(1, [1, -1], [1, 2, 3])
[2, 1]
source
CTBase.UnauthorizedCallType
struct UnauthorizedCall <: CTException

Exception thrown when a call to a function is not authorized.

Fields

  • var::String
source
CTBase.VariableConstraintType
struct VariableConstraint

Fields

  • f::Function

The default values for time_dependence and variable_dependence are Autonomous and Fixed respectively.

Constructor

The constructor VariableConstraint returns a VariableConstraint of a function. The function must take 1 argument, v.

Examples

julia> V = VariableConstraint(v -> [v[1]^2, 2v[2]])
Warning

When the variable is of dimension 1, consider v as a scalar.

Call

The call returns the evaluation of the VariableConstraint for given values.

Examples

julia> V = VariableConstraint(v -> [v[1]^2, 2v[2]])
julia> V([1, -1])
[1, -2]
source
CTBase.VariableConstraintMethod

Return the value of the VariableConstraint function.

julia> V = VariableConstraint(v -> [v[1]^2, 2v[2]])
julia> V([1, -1])
[1, -2]
source
CTBase.VectorFieldType
struct VectorField{time_dependence, variable_dependence} <: CTBase.AbstractVectorField{time_dependence, variable_dependence}

Fields

  • f::Function

The default values for time_dependence and variable_dependence are Autonomous and Fixed respectively.

Constructor

The constructor VectorField returns a VectorField of a function. The function must take 1 to 3 arguments, x to (t, x, v), if the function is variable or non autonomous, it must be specified. Dependencies are specified either with :

  • booleans, autonomous and variable, respectively true and false by default
  • DataType, Autonomous/NonAutonomous and NonFixed/Fixed, respectively Autonomous and Fixed by default.

Examples

julia> VectorField(x -> [x[1]^2, 2x[2]], Int64)
IncorrectArgument
julia> VectorField(x -> [x[1]^2, 2x[2]], Int64)
IncorrectArgument
julia> V = VectorField(x -> [x[1]^2, 2x[2]]) # autonomous=true, variable=false
julia> V = VectorField((x, v) -> [x[1]^2, 2x[2]+v[3]], variable=true)
julia> V = VectorField((t, x) -> [t+x[1]^2, 2x[2]], autonomous=false)
julia> V = VectorField((t, x, v) -> [t+x[1]^2, 2x[2]+v[3]], autonomous=false, variable=true)
julia> V = VectorField((x, v) -> [x[1]^2, 2x[2]+v[3]], NonFixed)
julia> V = VectorField((t, x) -> [t+x[1]^2, 2x[2]], NonAutonomous)
julia> V = VectorField((t, x, v) -> [t+x[1]^2, 2x[2]+v[3]], NonAutonomous, NonFixed)
Warning

When the state is of dimension 1, consider x as a scalar.

Call

The call returns the evaluation of the VectorField for given values.

Examples

julia> V = VectorField(x -> [x[1]^2, 2x[2]]) # autonomous=true, variable=false
julia> V([1, -1])
[1, -2]
julia> t = 1
julia> v = Real[]
julia> V(t, [1, -1])
MethodError
julia> V([1, -1], v)
MethodError
julia> V(t, [1, -1], v)
[1, -2]
julia> V = VectorField((x, v) -> [x[1]^2, 2x[2]+v[3]], variable=true)
julia> V([1, -1], [1, 2, 3])
[1, 1]
julia> V(t, [1, -1], [1, 2, 3])
[1, 1]
julia> V = VectorField((t, x) -> [t+x[1]^2, 2x[2]], autonomous=false)
julia> V(1, [1, -1])
[2, -2]
julia> V(1, [1, -1], v)
[2, -2]
julia> V = VectorField((t, x, v) -> [t+x[1]^2, 2x[2]+v[3]], autonomous=false, variable=true)
julia> V(1, [1, -1], [1, 2, 3])
[2, 1]
source
CTBase.VectorFieldMethod
VectorField(
    f::Function,
    dependencies::DataType...
) -> VectorField{Autonomous, Fixed}

Return a VectorField of a function. Dependencies are specified with DataType, Autonomous, NonAutonomous and Fixed, NonFixed.

julia> VectorField(x -> [x[1]^2, 2x[2]], Int64)
IncorrectArgument
julia> VectorField(x -> [x[1]^2, 2x[2]], Int64)
IncorrectArgument
julia> V = VectorField(x -> [x[1]^2, 2x[2]]) # autonomous=true, variable=false
julia> V = VectorField((x, v) -> [x[1]^2, 2x[2]+v[3]], NonFixed)
julia> V = VectorField((t, x) -> [t+x[1]^2, 2x[2]], NonAutonomous)
julia> V = VectorField((t, x, v) -> [t+x[1]^2, 2x[2]+v[3]], NonAutonomous, NonFixed)
source
CTBase.VectorFieldMethod
VectorField(
    f::Function;
    autonomous,
    variable
) -> VectorField{Autonomous, Fixed}

Return a VectorField of a function. Dependencies are specified with a boolean, variable, false by default, autonomous, true by default.

julia> V = VectorField(x -> [x[1]^2, 2x[2]]) # autonomous=true, variable=false
julia> V = VectorField((x, v) -> [x[1]^2, 2x[2]+v[3]], variable=true)
julia> V = VectorField((t, x) -> [t+x[1]^2, 2x[2]], autonomous=false)
julia> V = VectorField((t, x, v) -> [t+x[1]^2, 2x[2]+v[3]], autonomous=false, variable=true)
source
CTBase.VectorFieldMethod

Return the value of the VectorField.

Examples

julia> VectorField(x -> [x[1]^2, 2x[2]], Int64)
IncorrectArgument
julia> VectorField(x -> [x[1]^2, 2x[2]], Int64)
IncorrectArgument
julia> V = VectorField(x -> [x[1]^2, 2x[2]]) # autonomous=true, variable=false
julia> V([1, -1])
[1, -2]
julia> t = 1
julia> v = Real[]
julia> V(t, [1, -1])
MethodError
julia> V([1, -1], v)
MethodError
julia> V(t, [1, -1], v)
[1, -2]
julia> V = VectorField((x, v) -> [x[1]^2, 2x[2]+v[3]], variable=true)
julia> V([1, -1], [1, 2, 3])
[1, 1]
julia> V(t, [1, -1], [1, 2, 3])
[1, 1]
julia> V = VectorField((t, x) -> [t+x[1]^2, 2x[2]], autonomous=false)
julia> V(1, [1, -1])
[2, -2]
julia> V(1, [1, -1], v)
[2, -2]
julia> V = VectorField((t, x, v) -> [t+x[1]^2, 2x[2]+v[3]], autonomous=false, variable=true)
julia> V(1, [1, -1], [1, 2, 3])
[2, 1]
source
CTBase.:⋅Method
⋅(X::Function, f::Function) -> Function

Lie derivative of a scalar function along a function. In this case both functions will be considered autonomous and non-variable.

Example

julia> φ = x -> [x[2], -x[1]]
julia> f = x -> x[1]^2 + x[2]^2
julia> (φ⋅f)([1, 2])
0
julia> φ = (t, x, v) -> [t + x[2] + v[1], -x[1] + v[2]]
julia> f = (t, x, v) -> t + x[1]^2 + x[2]^2
julia> (φ⋅f)(1, [1, 2], [2, 1])
MethodError
source
CTBase.:⋅Method
⋅(
    X::VectorField{Autonomous, <:VariableDependence},
    f::Function
) -> CTBase.var"#106#108"{VectorField{Autonomous, var"#s97"}, <:Function} where var"#s97"<:VariableDependence

Lie derivative of a scalar function along a vector field : L_X(f) = X⋅f, in autonomous case

Example

julia> φ = x -> [x[2], -x[1]]
julia> X = VectorField(φ)
julia> f = x -> x[1]^2 + x[2]^2
julia> (X⋅f)([1, 2])
0
source
CTBase.:⋅Method
⋅(
    X::VectorField{NonAutonomous, <:VariableDependence},
    f::Function
) -> CTBase.var"#110#112"{VectorField{NonAutonomous, var"#s97"}, <:Function} where var"#s97"<:VariableDependence

Lie derivative of a scalar function along a vector field : L_X(f) = X⋅f, in nonautonomous case

Example

julia> φ = (t, x, v) -> [t + x[2] + v[1], -x[1] + v[2]]
julia> X = VectorField(φ, NonAutonomous, NonFixed)
julia> f = (t, x, v) -> t + x[1]^2 + x[2]^2
julia> (X⋅f)(1, [1, 2], [2, 1])
10
source
CTBase.LieMethod
Lie(
    X::Function,
    f::Function,
    dependences::DataType...
) -> Function

Lie derivative of a scalar function along a vector field or a function. Dependencies are specified with DataType : Autonomous, NonAutonomous and Fixed, NonFixed.

Example

julia> φ = x -> [x[2], -x[1]]
julia> f = x -> x[1]^2 + x[2]^2
julia> Lie(φ,f)([1, 2])
0
julia> φ = (t, x, v) -> [t + x[2] + v[1], -x[1] + v[2]]
julia> f = (t, x, v) -> t + x[1]^2 + x[2]^2
julia> Lie(φ, f, NonAutonomous, NonFixed)(1, [1, 2], [2, 1])
10
source
CTBase.LieMethod
Lie(
    X::Function,
    f::Function;
    autonomous,
    variable
) -> Function

Lie derivative of a scalar function along a function. Dependencies are specified with boolean : autonomous and variable.

Example

julia> φ = x -> [x[2], -x[1]]
julia> f = x -> x[1]^2 + x[2]^2
julia> Lie(φ,f)([1, 2])
0
julia> φ = (t, x, v) -> [t + x[2] + v[1], -x[1] + v[2]]
julia> f = (t, x, v) -> t + x[1]^2 + x[2]^2
julia> Lie(φ, f, autonomous=false, variable=true)(1, [1, 2], [2, 1])
10
source
CTBase.LieMethod
Lie(X::VectorField, f::Function) -> Function

Lie derivative of a scalar function along a vector field.

Example

julia> φ = x -> [x[2], -x[1]]
julia> X = VectorField(φ)
julia> f = x -> x[1]^2 + x[2]^2
julia> Lie(X,f)([1, 2])
0
julia> φ = (t, x, v) -> [t + x[2] + v[1], -x[1] + v[2]]
julia> X = VectorField(φ, NonAutonomous, NonFixed)
julia> f = (t, x, v) -> t + x[1]^2 + x[2]^2
julia> Lie(X, f)(1, [1, 2], [2, 1])
10
source
CTBase.LieMethod
Lie(
    X::VectorField{Autonomous, V<:VariableDependence},
    Y::VectorField{Autonomous, V<:VariableDependence}
) -> VectorField

Lie bracket of two vector fields: [X, Y] = Lie(X, Y), autonomous case

Example

julia> f = x -> [x[2], 2x[1]]
julia> g = x -> [3x[2], -x[1]]
julia> X = VectorField(f)
julia> Y = VectorField(g)
julia> Lie(X, Y)([1, 2])
[7, -14]
source
CTBase.LieMethod
Lie(
    X::VectorField{NonAutonomous, V<:VariableDependence},
    Y::VectorField{NonAutonomous, V<:VariableDependence}
) -> VectorField{NonAutonomous}

Lie bracket of two vector fields: [X, Y] = Lie(X, Y), nonautonomous case

Example

julia> f = (t, x, v) -> [t + x[2] + v, -2x[1] - v]
julia> g = (t, x, v) -> [t + 3x[2] + v, -x[1] - v]
julia> X = VectorField(f, NonAutonomous, NonFixed)
julia> Y = VectorField(g, NonAutonomous, NonFixed)
julia> Lie(X, Y)(1, [1, 2], 1)
[-7,12]
source
CTBase.LiftMethod
Lift(
    X::Function,
    dependences::DataType...
) -> HamiltonianLift

Return the HamiltonianLift of a VectorField or a function. Dependencies are specified with DataType : Autonomous, NonAutonomous and Fixed, NonFixed.

Example

julia> H = Lift(x -> 2x)
julia> H(1, 1)
2
julia> H = Lift((t, x, v) -> 2x + t - v, NonAutonomous, NonFixed)
julia> H(1, 1, 1, 1)
2
source
CTBase.LiftMethod
Lift(X::Function; autonomous, variable) -> HamiltonianLift

Return the HamiltonianLift of a function. Dependencies are specified with boolean : autonomous and variable.

Example

julia> H = Lift(x -> 2x)
julia> H(1, 1)
2
julia> H = Lift((t, x, v) -> 2x + t - v, autonomous=false, variable=true)
julia> H(1, 1, 1, 1)
2
source
CTBase.LiftMethod
Lift(X::VectorField) -> HamiltonianLift

Return the HamiltonianLift of a VectorField.

Example

julia> HL = Lift(VectorField(x -> [x[1]^2,x[2]^2], autonomous=true, variable=false))
julia> HL([1, 0], [0, 1])
0
julia> HL = Lift(VectorField((t, x, v) -> [t+x[1]^2,x[2]^2+v], autonomous=false, variable=true))
julia> HL(1, [1, 0], [0, 1], 1)
1
julia> H = Lift(x -> 2x)
julia> H(1, 1)
2
julia> H = Lift((t, x, v) -> 2x + t - v, autonomous=false, variable=true)
julia> H(1, 1, 1, 1)
2
julia> H = Lift((t, x, v) -> 2x + t - v, NonAutonomous, NonFixed)
julia> H(1, 1, 1, 1)
2
source
CTBase.ModelMethod
Model(
    dependencies::DataType...
) -> OptimalControlModel{Autonomous, Fixed}

Return a new OptimalControlModel instance, that is a model of an optimal control problem.

The model is defined by the following argument:

  • dependencies: either Autonomous or NonAutonomous. Default is Autonomous. And either NonFixed or Fixed. Default is Fixed.

Examples

julia> ocp = Model()
julia> ocp = Model(NonAutonomous)
julia> ocp = Model(Autonomous, NonFixed)
Note
  • If the time dependence of the model is defined as nonautonomous, then, the dynamics function, the lagrange cost and the path constraints must be defined as functions of time and state, and possibly control. If the model is defined as autonomous, then, the dynamics function, the lagrange cost and the path constraints must be defined as functions of state, and possibly control.
source
CTBase.ModelMethod
Model(
;
    autonomous,
    variable
) -> OptimalControlModel{Autonomous, Fixed}

Return a new OptimalControlModel instance, that is a model of an optimal control problem.

The model is defined by the following optional keyword argument:

  • autonomous: either true or false. Default is true.
  • variable: either true or false. Default is false.

Examples

julia> ocp = Model()
julia> ocp = Model(autonomous=false)
julia> ocp = Model(autonomous=false, variable=true)
Note
  • If the time dependence of the model is defined as nonautonomous, then, the dynamics function, the lagrange cost and the path constraints must be defined as functions of time and state, and possibly control. If the model is defined as autonomous, then, the dynamics function, the lagrange cost and the path constraints must be defined as functions of state, and possibly control.
source
CTBase.PoissonMethod
Poisson(
    f::Function,
    g::Function,
    dependences::DataType...
) -> Hamiltonian

Poisson bracket of two functions : {f, g} = Poisson(f, g) Dependencies are specified with DataType : Autonomous, NonAutonomous and Fixed, NonFixed.

Example

julia> f = (x, p) -> x[2]^2 + 2x[1]^2 + p[1]^2
julia> g = (x, p) -> 3x[2]^2 + -x[1]^2 + p[2]^2 + p[1]
julia> Poisson(f, g)([1, 2], [2, 1])
-20            
julia> f = (t, x, p, v) -> t*v[1]*x[2]^2 + 2x[1]^2 + p[1]^2 + v[2]
julia> g = (t, x, p, v) -> 3x[2]^2 + -x[1]^2 + p[2]^2 + p[1] + t - v[2]
julia> Poisson(f, g, NonAutonomous, NonFixed)(2, [1, 2], [2, 1], [4, 4])
-76
source
CTBase.PoissonMethod
Poisson(
    f::Function,
    g::Function;
    autonomous,
    variable
) -> Hamiltonian

Poisson bracket of two functions : {f, g} = Poisson(f, g) Dependencies are specified with boolean : autonomous and variable.

Example

julia> f = (x, p) -> x[2]^2 + 2x[1]^2 + p[1]^2
julia> g = (x, p) -> 3x[2]^2 + -x[1]^2 + p[2]^2 + p[1]
julia> Poisson(f, g)([1, 2], [2, 1])
-20            
julia> f = (t, x, p, v) -> t*v[1]*x[2]^2 + 2x[1]^2 + p[1]^2 + v[2]
julia> g = (t, x, p, v) -> 3x[2]^2 + -x[1]^2 + p[2]^2 + p[1] + t - v[2]
julia> Poisson(f, g, autonomous=false, variable=true)(2, [1, 2], [2, 1], [4, 4])
-76
source
CTBase.PoissonMethod
Poisson(
    f::AbstractHamiltonian{Autonomous, V<:VariableDependence},
    g::AbstractHamiltonian{Autonomous, V<:VariableDependence}
) -> HamiltonianLift

Poisson bracket of two Hamiltonian functions (subtype of AbstractHamiltonian) : {f, g} = Poisson(f, g), autonomous case

Example

julia> f = (x, p) -> x[2]^2 + 2x[1]^2 + p[1]^2
julia> g = (x, p) -> 3x[2]^2 + -x[1]^2 + p[2]^2 + p[1]
julia> F = Hamiltonian(f)
julia> G = Hamiltonian(g)
julia> Poisson(f, g)([1, 2], [2, 1])
-20            
julia> Poisson(f, G)([1, 2], [2, 1])
-20
julia> Poisson(F, g)([1, 2], [2, 1])
-20
source
CTBase.PoissonMethod
Poisson(
    f::AbstractHamiltonian{NonAutonomous, V<:VariableDependence},
    g::AbstractHamiltonian{NonAutonomous, V<:VariableDependence}
) -> HamiltonianLift

Poisson bracket of two Hamiltonian functions (subtype of AbstractHamiltonian) : {f, g} = Poisson(f, g), non autonomous case

Example

julia> f = (t, x, p, v) -> t*v[1]*x[2]^2 + 2x[1]^2 + p[1]^2 + v[2]
julia> g = (t, x, p, v) -> 3x[2]^2 + -x[1]^2 + p[2]^2 + p[1] + t - v[2]
julia> F = Hamiltonian(f, autonomous=false, variable=true)
julia> G = Hamiltonian(g, autonomous=false, variable=true)
julia> Poisson(F, G)(2, [1, 2], [2, 1], [4, 4])
-76
julia> Poisson(f, g, NonAutonomous, NonFixed)(2, [1, 2], [2, 1], [4, 4])
-76
source
CTBase.PoissonMethod
Poisson(
    f::AbstractHamiltonian{T<:TimeDependence, V<:VariableDependence},
    g::Function
) -> Hamiltonian

Poisson bracket of an Hamiltonian function (subtype of AbstractHamiltonian) and a function : {f, g} = Poisson(f, g), autonomous case

Example

julia> f = (x, p) -> x[2]^2 + 2x[1]^2 + p[1]^2
julia> g = (x, p) -> 3x[2]^2 + -x[1]^2 + p[2]^2 + p[1]
julia> F = Hamiltonian(f)
julia> Poisson(F, g)([1, 2], [2, 1])
-20
julia> f = (t, x, p, v) -> t*v[1]*x[2]^2 + 2x[1]^2 + p[1]^2 + v[2]
julia> g = (t, x, p, v) -> 3x[2]^2 + -x[1]^2 + p[2]^2 + p[1] + t - v[2]
julia> F = Hamiltonian(f, autonomous=false, variable=true)
julia> Poisson(F, g)(2, [1, 2], [2, 1], [4, 4])
-76
source
CTBase.PoissonMethod
Poisson(
    f::Function,
    g::AbstractHamiltonian{T<:TimeDependence, V<:VariableDependence}
) -> Hamiltonian

Poisson bracket of a function and an Hamiltonian function (subtype of AbstractHamiltonian) : {f, g} = Poisson(f, g)

Example

julia> f = (x, p) -> x[2]^2 + 2x[1]^2 + p[1]^2
julia> g = (x, p) -> 3x[2]^2 + -x[1]^2 + p[2]^2 + p[1]
julia> G = Hamiltonian(g)          
julia> Poisson(f, G)([1, 2], [2, 1])
-20
julia> f = (t, x, p, v) -> t*v[1]*x[2]^2 + 2x[1]^2 + p[1]^2 + v[2]
julia> g = (t, x, p, v) -> 3x[2]^2 + -x[1]^2 + p[2]^2 + p[1] + t - v[2]
julia> G = Hamiltonian(g, autonomous=false, variable=true)
julia> Poisson(f, G)(2, [1, 2], [2, 1], [4, 4])
-76
source
CTBase.PoissonMethod
Poisson(
    f::HamiltonianLift{T<:TimeDependence, V<:VariableDependence},
    g::HamiltonianLift{T<:TimeDependence, V<:VariableDependence}
) -> HamiltonianLift

Poisson bracket of two HamiltonianLift functions : {f, g} = Poisson(f, g)

Example

julia> f = x -> [x[1]^2+x[2]^2, 2x[1]^2]
julia> g = x -> [3x[2]^2, x[2]-x[1]^2]
julia> F = Lift(f)
julia> G = Lift(g)
julia> Poisson(F, G)([1, 2], [2, 1])
-64
julia> f = (t, x, v) -> [t*v[1]*x[2]^2, 2x[1]^2 + + v[2]]
julia> g = (t, x, v) -> [3x[2]^2 + -x[1]^2, t - v[2]]
julia> F = Lift(f, NonAutonomous, NonFixed)
julia> G = Lift(g, NonAutonomous, NonFixed)
julia> Poisson(F, G)(2, [1, 2], [2, 1], [4, 4])
100
source
CTBase.addMethod
add(
    x::Tuple{Vararg{Tuple{Vararg{Symbol}}}},
    y::Tuple{Vararg{Symbol}}
) -> Tuple{Tuple{Vararg{Symbol}}}

Concatenate the description y at the tuple of descriptions x if it is not already in the tuple x.

Example

julia> descriptions = ()
julia> descriptions = add(descriptions, (:a,))
((:a,),)
julia> descriptions = add(descriptions, (:b,))
((:a,), (:b,))
source
CTBase.addMethod
add(
    x::Tuple{},
    y::Tuple{Vararg{Symbol}}
) -> Tuple{Tuple{Vararg{Symbol}}}

Return a tuple containing only the description y.

Example

julia> descriptions = ()
julia> descriptions = add(descriptions, (:a,))
((:a,),)
julia> descriptions[1]
(:a,)
source
CTBase.constraint!Function
constraint!(
    ocp::OptimalControlModel,
    type::Symbol,
    lb::Union{Real, AbstractVector{<:Real}},
    ub::Union{Real, AbstractVector{<:Real}}
)
constraint!(
    ocp::OptimalControlModel,
    type::Symbol,
    lb::Union{Real, AbstractVector{<:Real}},
    ub::Union{Real, AbstractVector{<:Real}},
    label::Symbol
)

Add an :initial, :final, :control, :state or :variable box constraint (whole range).

Note
  • The state, control and variable dimensions must be set before. Use state!, control! and variable!.
  • The times must be set before. Use time!.
  • When an element is of dimension 1, consider it as a scalar.

Examples

julia> constraint!(ocp, :initial, [ 0, 0, 0 ], [ 1, 2, 1 ])
julia> constraint!(ocp, :final, [ 0, 0, 0 ], [ 1, 2, 1 ])
julia> constraint!(ocp, :control, [ 0, 0 ], [ 2, 3 ])
julia> constraint!(ocp, :state, [ 0, 0, 0 ], [ 1, 2, 1 ])
julia> constraint!(ocp, :variable, 0, 1) # the variable here is of dimension 1
source
CTBase.constraint!Function
constraint!(
    ocp::OptimalControlModel,
    type::Symbol,
    f::Function,
    val::Union{Real, AbstractVector{<:Real}}
)
constraint!(
    ocp::OptimalControlModel,
    type::Symbol,
    f::Function,
    val::Union{Real, AbstractVector{<:Real}},
    label::Symbol
)

Add a :boundary, :control, :state, :mixed or :variable value functional constraint.

Note
  • The state, control and variable dimensions must be set before. Use state!, control! and variable!.
  • The times must be set before. Use time!.
  • When an element is of dimension 1, consider it as a scalar.

Examples

# variable independent ocp
julia> constraint!(ocp, :boundary, (x0, xf) -> x0[3]+xf[2], 0)

# variable dependent ocp
julia> constraint!(ocp, :boundary, (x0, xf, v) -> x0[3]+xf[2]*v[1], 0)

# time independent and variable independent ocp
julia> constraint!(ocp, :control, u -> 2u, 1)
julia> constraint!(ocp, :state, x -> x-1, [ 0, 0, 0 ])
julia> constraint!(ocp, :mixed, (x, u) -> x[1]-u, 0)

# time dependent and variable independent ocp
julia> constraint!(ocp, :control, (t, u) -> 2u, 1)
julia> constraint!(ocp, :state, (t, x) -> x-t, [ 0, 0, 0 ])
julia> constraint!(ocp, :mixed, (t, x, u) -> x[1]-u, 0)

# time independent and variable dependent ocp
julia> constraint!(ocp, :control, (u, v) -> 2u*v[1], 1)
julia> constraint!(ocp, :state, (x, v) -> x-v[2], [ 0, 0, 0 ])
julia> constraint!(ocp, :mixed, (x, u) -> x[1]-u+v[1], 0)

# time dependent and variable dependent ocp
julia> constraint!(ocp, :control, (t, u, v) -> 2u-t*v[2], 1)
julia> constraint!(ocp, :state, (t, x, v) -> x-t+v[1], [ 0, 0, 0 ])
julia> constraint!(ocp, :mixed, (t, x, u, v) -> x[1]-u*v[1], 0)
source
CTBase.constraint!Function
constraint!(
    ocp::OptimalControlModel,
    type::Symbol,
    rg::Union{Index, OrdinalRange{<:Integer}},
    val::Union{Real, AbstractVector{<:Real}}
)
constraint!(
    ocp::OptimalControlModel,
    type::Symbol,
    rg::Union{Index, OrdinalRange{<:Integer}},
    val::Union{Real, AbstractVector{<:Real}},
    label::Symbol
)

Add an :initial or :final value constraint on a range of the state, or a value constraint on a range of the :variable.

Note
  • The range of the constraint must be contained in 1:n if the constraint is on the state, or 1:q if the constraint is on the variable.
  • The state, control and variable dimensions must be set before. Use state!, control! and variable!.
  • The times must be set before. Use time!.

Examples

julia> constraint!(ocp, :initial, 1:2:5, [ 0, 0, 0 ])
julia> constraint!(ocp, :initial, 2:3, [ 0, 0 ])
julia> constraint!(ocp, :final, Index(2), 0)
julia> constraint!(ocp, :variable, 2:3, [ 0, 3 ])
source
CTBase.constraint!Function
constraint!(
    ocp::OptimalControlModel,
    type::Symbol,
    val::Union{Real, AbstractVector{<:Real}}
)
constraint!(
    ocp::OptimalControlModel,
    type::Symbol,
    val::Union{Real, AbstractVector{<:Real}},
    label::Symbol
)

Add an :initial or :final value constraint on the state, or a :variable value. Can also be used with :state and :control.

Note
  • The state, control and variable dimensions must be set before. Use state!, control! and variable!.
  • The times must be set before. Use time!.
  • When an element is of dimension 1, consider it as a scalar.

Examples

julia> constraint!(ocp, :initial, [ 0, 0 ])
julia> constraint!(ocp, :final, 2) # if the state is of dimension 1
julia> constraint!(ocp, :variable, [ 3, 0, 1 ])
source
CTBase.constraint!Method
constraint!(
    ocp::OptimalControlModel,
    type::Symbol;
    rg,
    f,
    val,
    lb,
    ub,
    label
)

Add an :initial, :final, :control, :state or :variable box constraint on a range.

Note
  • The range of the constraint must be contained in 1:n if the constraint is on the state, or 1:m if the constraint is on the control, or 1:q if the constraint is on the variable.
  • The state, control and variable dimensions must be set before. Use state!, control! and variable!.
  • The times must be set before. Use time!.

Examples

julia> constraint!(ocp, :initial, rg=2:3, lb=[ 0, 0 ], ub=[ 1, 2 ])
julia> constraint!(ocp, :final, val=Index(1), lb=0, ub=2)
julia> constraint!(ocp, :control, val=Index(1), lb=0, ub=2)
julia> constraint!(ocp, :state, rg=2:3, lb=[ 0, 0 ], ub=[ 1, 2 ])
julia> constraint!(ocp, :initial, rg=1:2:5, lb=[ 0, 0, 0 ], ub=[ 1, 2, 1 ])
julia> constraint!(ocp, :variable, rg=1:2, lb=[ 0, 0 ], ub=[ 1, 2 ])
source
CTBase.constraint!Method
constraint!(
    ocp::OptimalControlModel{<:TimeDependence, V<:VariableDependence},
    type::Symbol,
    rg::Union{Index, OrdinalRange{<:Integer}},
    lb::Union{Real, AbstractVector{<:Real}},
    ub::Union{Real, AbstractVector{<:Real}}
)
constraint!(
    ocp::OptimalControlModel{<:TimeDependence, V<:VariableDependence},
    type::Symbol,
    rg::Union{Index, OrdinalRange{<:Integer}},
    lb::Union{Real, AbstractVector{<:Real}},
    ub::Union{Real, AbstractVector{<:Real}},
    label::Symbol
)

Add an :initial, :final, :control, :state or :variable box constraint on a range.

Note
  • The range of the constraint must be contained in 1:n if the constraint is on the state, or 1:m if the constraint is on the control, or 1:q if the constraint is on the variable.
  • The state, control and variable dimensions must be set before. Use state!, control! and variable!.
  • The times must be set before. Use time!.

Examples

julia> constraint!(ocp, :initial, 2:3, [ 0, 0 ], [ 1, 2 ])
julia> constraint!(ocp, :final, Index(1), 0, 2)
julia> constraint!(ocp, :control, Index(1), 0, 2)
julia> constraint!(ocp, :state, 2:3, [ 0, 0 ], [ 1, 2 ])
julia> constraint!(ocp, :initial, 1:2:5, [ 0, 0, 0 ], [ 1, 2, 1 ])
julia> constraint!(ocp, :variable, 1:2, [ 0, 0 ], [ 1, 2 ])
source
CTBase.constraint!Method
constraint!(
    ocp::OptimalControlModel{T, V},
    type::Symbol,
    f::Function,
    lb::Union{Real, AbstractVector{<:Real}},
    ub::Union{Real, AbstractVector{<:Real}}
)
constraint!(
    ocp::OptimalControlModel{T, V},
    type::Symbol,
    f::Function,
    lb::Union{Real, AbstractVector{<:Real}},
    ub::Union{Real, AbstractVector{<:Real}},
    label::Symbol
)

Add a :boundary, :control, :state, :mixed or :variable box functional constraint.

Note
  • The state, control and variable dimensions must be set before. Use state!, control! and variable!.
  • The times must be set before. Use time!.
  • When an element is of dimension 1, consider it as a scalar.

Examples

# variable independent ocp
julia> constraint!(ocp, :boundary, (x0, xf) -> x0[3]+xf[2], 0, 1)

# variable dependent ocp
julia> constraint!(ocp, :boundary, (x0, xf, v) -> x0[3]+xf[2]*v[1], 0, 1)

# time independent and variable independent ocp
julia> constraint!(ocp, :control, u -> 2u, 0, 1)
julia> constraint!(ocp, :state, x -> x-1, [ 0, 0, 0 ], [ 1, 2, 1 ])
julia> constraint!(ocp, :mixed, (x, u) -> x[1]-u, 0, 1)

# time dependent and variable independent ocp
julia> constraint!(ocp, :control, (t, u) -> 2u, 0, 1)
julia> constraint!(ocp, :state, (t, x) -> x-t, [ 0, 0, 0 ], [ 1, 2, 1 ])
julia> constraint!(ocp, :mixed, (t, x, u) -> x[1]-u, 0, 1)

# time independent and variable dependent ocp
julia> constraint!(ocp, :control, (u, v) -> 2u*v[1], 0, 1)
julia> constraint!(ocp, :state, (x, v) -> x-v[1], [ 0, 0, 0 ], [ 1, 2, 1 ])
julia> constraint!(ocp, :mixed, (x, u, v) -> x[1]-v[2]*u, 0, 1)

# time dependent and variable dependent ocp
julia> constraint!(ocp, :control, (t, u, v) -> 2u+v[2], 0, 1)
julia> constraint!(ocp, :state, (t, x, v) -> x-t*v[1], [ 0, 0, 0 ], [ 1, 2, 1 ])
julia> constraint!(ocp, :mixed, (t, x, u, v) -> x[1]*v[2]-u, 0, 1)
source
CTBase.constraintMethod
constraint(
    ocp::OptimalControlModel{T<:TimeDependence, V<:VariableDependence},
    label::Symbol
) -> Any

Retrieve a labeled constraint. The result is a function associated with the constraint computation (not taking into account provided value / bounds).

Example

julia> constraint!(ocp, :initial, 0, :c0)
julia> c = constraint(ocp, :c0)
julia> c(1)
1
source
CTBase.constraint_typeMethod
constraint_type(
    e,
    t,
    t0,
    tf,
    x,
    u,
    v
) -> Union{Symbol, Tuple{Symbol, Any}}

Return the type constraint among :initial, :final, :boundary, :control_range, :control_fun, :state_range, :state_fun, :mixed, :variable_range, :variable_fun (:other otherwise), together with the appropriate value (range, updated expression...)

Example

julia> t = :t; t0 = 0; tf = :tf; x = :x; u = :u; v = :v

julia> constraint_type(:( ẏ(t) ), t, t0, tf, x, u, v)
:other

julia> constraint_type(:( ẋ(s) ), t, t0, tf, x, u, v)
:other

julia> constraint_type(:( x(0)' ), t, t0, tf, x, u, v)
:boundary

julia> constraint_type(:( x(t)' ), t, t0, tf, x, u, v)
:state_fun

julia> constraint_type(:( x(0) ), t, t0, tf, x, u, v)
(:initial, nothing)

julia> constraint_type(:( x[1:2:5](0) ), t, t0, tf, x, u, v)
(:initial, 1:2:5)

julia> constraint_type(:( x[1:2](0) ), t, t0, tf, x, u, v)
(:initial, 1:2)

julia> constraint_type(:( x[1](0) ), t, t0, tf, x, u, v)
(:initial, Index(1))

julia> constraint_type(:( 2x[1](0)^2 ), t, t0, tf, x, u, v)
:boundary

julia> constraint_type(:( x(tf) ), t, t0, tf, x, u, v)
(:final, nothing)
j
julia> constraint_type(:( x[1:2:5](tf) ), t, t0, tf, x, u, v)
(:final, 1:2:5)

julia> constraint_type(:( x[1:2](tf) ), t, t0, tf, x, u, v)
(:final, 1:2)

julia> constraint_type(:( x[1](tf) ), t, t0, tf, x, u, v)
(:final, Index(1))

julia> constraint_type(:( 2x[1](tf)^2 ), t, t0, tf, x, u, v)
:boundary

julia> constraint_type(:( x[1](tf) - x[2](0) ), t, t0, tf, x, u, v)
:boundary

julia> constraint_type(:( u[1:2:5](t) ), t, t0, tf, x, u, v)
(:control_range, 1:2:5)

julia> constraint_type(:( u[1:2](t) ), t, t0, tf, x, u, v)
(:control_range, 1:2)

julia> constraint_type(:( u[1](t) ), t, t0, tf, x, u, v)
(:control_range, Index(1))

julia> constraint_type(:( u(t) ), t, t0, tf, x, u, v)
(:control_range, nothing)

julia> constraint_type(:( 2u[1](t)^2 ), t, t0, tf, x, u, v)
:control_fun

julia> constraint_type(:( x[1:2:5](t) ), t, t0, tf, x, u, v)
(:state_range, 1:2:5)

julia> constraint_type(:( x[1:2](t) ), t, t0, tf, x, u, v)
(:state_range, 1:2)

julia> constraint_type(:( x[1](t) ), t, t0, tf, x, u, v)
(:state_range, Index(1))

julia> constraint_type(:( x(t) ), t, t0, tf, x, u, v)
(:state_range, nothing)

julia> constraint_type(:( 2x[1](t)^2 ), t, t0, tf, x, u, v)
:state_fun

julia> constraint_type(:( 2u[1](t)^2 * x(t) ), t, t0, tf, x, u, v)
:mixed

julia> constraint_type(:( 2u[1](0)^2 * x(t) ), t, t0, tf, x, u, v)
:other

julia> constraint_type(:( 2u[1](0)^2 * x(t) ), t, t0, tf, x, u, v)
:other

julia> constraint_type(:( 2u[1](t)^2 * x(t) + v ), t, t0, tf, x, u, v)
:mixed

julia> constraint_type(:( v[1:2:10] ), t, t0, tf, x, u, v)
(:variable_range, 1:2:9)

julia> constraint_type(:( v[1:10] ), t, t0, tf, x, u, v)
(:variable_range, 1:10)

julia> constraint_type(:( v[2] ), t, t0, tf, x, u, v)
(:variable_range, Index(2))

julia> constraint_type(:( v ), t, t0, tf, x, u, v)
(:variable_range, nothing)

julia> constraint_type(:( v^2  + 1 ), t, t0, tf, x, u, v)
(:variable_fun, :(v ^ 2 + 1))

julia> constraint_type(:( v[2]^2 + 1 ), t, t0, tf, x, u, v)
(:variable_fun, :(v[2] ^ 2 + 1))
source
CTBase.constraints_labelsMethod
constraints_labels(
    ocp::OptimalControlModel
) -> Base.KeySet{Symbol, Dict{Symbol, Tuple}}

Return the labels of the constraints as a Base.keys.

Example

julia> constraints_labels(ocp)
source
CTBase.control!Function
control!(ocp::OptimalControlModel, m::Integer)
control!(ocp::OptimalControlModel, m::Integer, name::String)
control!(
    ocp::OptimalControlModel,
    m::Integer,
    name::String,
    components_names::Vector{String}
)

Define the control dimension and possibly the names of each coordinate.

Note

You must use control! only once to set the control dimension.

Examples

julia> control!(ocp, 1)
julia> ocp.control_dimension
1
julia> ocp.control_components_names
["u"]

julia> control!(ocp, 1, "v")
julia> ocp.control_dimension
1
julia> ocp.control_components_names
["v"]

julia> control!(ocp, 2)
julia> ocp.control_dimension
2
julia> ocp.control_components_names
["u₁", "u₂"]

julia> control!(ocp, 2, :v)
julia> ocp.control_dimension
2
julia> ocp.control_components_names
["v₁", "v₂"]

julia> control!(ocp, 2, "v")
julia> ocp.control_dimension
2
julia> ocp.control_components_names
["v₁", "v₂"]
source
CTBase.dynamics!Method
dynamics!(
    ocp::OptimalControlModel{T<:TimeDependence, V<:VariableDependence},
    f::Function
)

Set the dynamics.

Note

You can use dynamics! only once to define the dynamics.

  • The state, control and variable dimensions must be set before. Use state!, control! and variable!.
  • The times must be set before. Use time!.
  • When an element is of dimension 1, consider it as a scalar.

Example

julia> dynamics!(ocp, f)
source
CTBase.getFullDescriptionMethod
getFullDescription(
    desc::Tuple{Vararg{Symbol}},
    desc_list::Tuple{Vararg{Tuple{Vararg{Symbol}}}}
) -> Tuple{Vararg{Symbol}}

Return a complete description from an incomplete description desc and a list of complete descriptions desc_list. If several complete descriptions are possible, then the first one is returned.

Example

julia> desc_list = ((:a, :b), (:b, :c), (:a, :c))
((:a, :b), (:b, :c), (:a, :c))
julia> getFullDescription((:a,), desc_list)
(:a, :b)
source
CTBase.is_maxMethod
is_max(ocp::OptimalControlModel) -> Bool

Return true if the criterion type of ocp is :max.

source
CTBase.is_minMethod
is_min(ocp::OptimalControlModel) -> Bool

Return true if the criterion type of ocp is :min.

source
CTBase.is_time_dependentMethod
is_time_dependent(
    ocp::OptimalControlModel{NonAutonomous}
) -> Bool

Return true if the model has been defined as time dependent.

source
CTBase.is_variable_dependentMethod
is_variable_dependent(
    ocp::OptimalControlModel{<:TimeDependence, NonFixed}
) -> Bool

Return true if the model has been defined as variable dependent.

source
CTBase.nlp_constraintsMethod
nlp_constraints(
    ocp::OptimalControlModel
) -> Tuple{Tuple{Vector{Real}, CTBase.var"#ξ#100", Vector{Real}}, Tuple{Vector{Real}, CTBase.var"#η#101", Vector{Real}}, Tuple{Vector{Real}, CTBase.var"#ψ#102", Vector{Real}}, Tuple{Vector{Real}, CTBase.var"#ϕ#103", Vector{Real}}, Tuple{Vector{Real}, CTBase.var"#θ#104", Vector{Real}}, Tuple{Vector{Real}, Vector{Int64}, Vector{Real}}, Tuple{Vector{Real}, Vector{Int64}, Vector{Real}}, Tuple{Vector{Real}, Vector{Int64}, Vector{Real}}}

Return a 6-tuple of tuples:

  • (ξl, ξ, ξu) are control constraints
  • (ηl, η, ηu) are state constraints
  • (ψl, ψ, ψu) are mixed constraints
  • (ϕl, ϕ, ϕu) are boundary constraints
  • (θl, θ, θu) are variable constraints
  • (ul, uind, uu) are control linear constraints of a subset of indices
  • (xl, xind, xu) are state linear constraints of a subset of indices
  • (vl, vind, vu) are variable linear constraints of a subset of indices
Note
  • The dimensions of the state and control must be set before calling nlp_constraints.

Example

julia> (ξl, ξ, ξu), (ηl, η, ηu), (ψl, ψ, ψu), (ϕl, ϕ, ϕu), (θl, θ, θu),
    (ul, uind, uu), (xl, xind, xu), (vl, vind, vu) = nlp_constraints(ocp)
source
CTBase.objective!Method
objective!(
    ocp::OptimalControlModel{T<:TimeDependence, V<:VariableDependence},
    type::Symbol,
    g::Function,
    f⁰::Function
)
objective!(
    ocp::OptimalControlModel{T<:TimeDependence, V<:VariableDependence},
    type::Symbol,
    g::Function,
    f⁰::Function,
    criterion::Symbol
)

Set the criterion to the function g and f⁰. Type can be :bolza. Criterion is :min or :max.

Note

You can use objective! only once to define the objective.

  • The state, control and variable dimensions must be set before. Use state!, control! and variable!.
  • The times must be set before. Use time!.
  • When an element is of dimension 1, consider it as a scalar.

Example

julia> objective!(ocp, :bolza, (x0, xf) -> x0[1] + xf[2], (x, u) -> x[1]^2 + u^2) # the control is of dimension 1
source
CTBase.objective!Method
objective!(
    ocp::OptimalControlModel{T<:TimeDependence, V<:VariableDependence},
    type::Symbol,
    f::Function
)
objective!(
    ocp::OptimalControlModel{T<:TimeDependence, V<:VariableDependence},
    type::Symbol,
    f::Function,
    criterion::Symbol
)

Set the criterion to the function f. Type can be :mayer or :lagrange. Criterion is :min or :max.

Note

You can use objective! only once to define the objective.

  • The state, control and variable dimensions must be set before. Use state!, control! and variable!.
  • The times must be set before. Use time!.
  • When an element is of dimension 1, consider it as a scalar.

Examples

julia> objective!(ocp, :mayer, (x0, xf) -> x0[1] + xf[2])
julia> objective!(ocp, :lagrange, (x, u) -> x[1]^2 + u^2) # the control is of dimension 1
Warning

If you set twice the objective, only the last one will be taken into account.

source
CTBase.remove_constraint!Method
remove_constraint!(ocp::OptimalControlModel, label::Symbol)

Remove a labeled constraint.

Example

julia> remove_constraint!(ocp, :con)
source
CTBase.replace_callMethod
replace_call(e, x::Symbol, t, y) -> Any

Replace calls in e of the form (...x...)(t) by (...y...).

Example


julia> t = :t; t0 = 0; tf = :tf; x = :x; u = :u;

julia> e = :( x[1](0) * 2x(tf) - x[2](tf) * 2x(0) )
:((x[1])(0) * (2 * x(tf)) - (x[2])(tf) * (2 * x(0)))

julia> x0 = Symbol(x, 0); e = replace_call(e, x, t0, x0)
:(x0[1] * (2 * x(tf)) - (x[2])(tf) * (2x0))

julia> xf = Symbol(x, "f"); replace_call(ans, x, tf, xf)
:(x0[1] * (2xf) - xf[2] * (2x0))

julia> e = :( A*x(t) + B*u(t) ); replace_call(replace_call(e, x, t, x), u, t, u)
:(A * x + B * u)

julia> e = :( F0(x(t)) + u(t)*F1(x(t)) ); replace_call(replace_call(e, x, t, x), u, t, u)
:(F0(x) + u * F1(x))

julia> e = :( 0.5u(t)^2 ); replace_call(e, u, t, u)
:(0.5 * u ^ 2)
source
CTBase.replace_callMethod
replace_call(e, x::Vector{Symbol}, t, y) -> Any

Replace calls in e of the form (...x1...x2...)(t) by (...y1...y2...) for all symbols x1, x2... in the vector x.

Example


julia> t = :t; t0 = 0; tf = :tf; x = :x; u = :u;

julia> e = :( (x^2 + u[1])(t) ); replace_call(e, [ x, u ], t , [ :xx, :uu ])
:(xx ^ 2 + uu[1])

julia> e = :( ((x^2)(t) + u[1])(t) ); replace_call(e, [ x, u ], t , [ :xx, :uu ])
:(xx ^ 2 + uu[1])

julia> e = :( ((x^2)(t0) + u[1])(t) ); replace_call(e, [ x, u ], t , [ :xx, :uu ])
:((xx ^ 2)(t0) + uu[1])
source
CTBase.state!Function
state!(ocp::OptimalControlModel, n::Integer)
state!(ocp::OptimalControlModel, n::Integer, name::String)
state!(
    ocp::OptimalControlModel,
    n::Integer,
    name::String,
    components_names::Vector{String}
)

Define the state dimension and possibly the names of each component.

Note

You must use state! only once to set the state dimension.

Examples

julia> state!(ocp, 1)
julia> ocp.state_dimension
1
julia> ocp.state_components_names
["x"]

julia> state!(ocp, 1, "y")
julia> ocp.state_dimension
1
julia> ocp.state_components_names
["y"]

julia> state!(ocp, 2)
julia> ocp.state_dimension
2
julia> ocp.state_components_names
["x₁", "x₂"]

julia> state!(ocp, 2, :y)
julia> ocp.state_dimension
2
julia> ocp.state_components_names
["y₁", "y₂"]

julia> state!(ocp, 2, "y")
julia> ocp.state_dimension
2
julia> ocp.state_components_names
["y₁", "y₂"]
source
CTBase.time!Function
time!(ocp::OptimalControlModel, t0::Real, tf::Real)
time!(
    ocp::OptimalControlModel,
    t0::Real,
    tf::Real,
    name::String
)

Fix initial and final times to times[1] and times[2], respectively.

Examples

julia> time!(ocp, 0, 1)
julia> ocp.initial_time
0
julia> ocp.final_time
1
julia> ocp.time_name
"t"

julia> time!(ocp, 0, 1, "s")
julia> ocp.initial_time
0
julia> ocp.final_time
1
julia> ocp.time_name
"s"

julia> time!(ocp, 0, 1, :s)
julia> ocp.initial_time
0
julia> ocp.final_time
1
julia> ocp.time_name
"s"
source
CTBase.time!Function
time!(
    ocp::OptimalControlModel{<:TimeDependence, NonFixed},
    t0::Real,
    indf::Index
)
time!(
    ocp::OptimalControlModel{<:TimeDependence, NonFixed},
    t0::Real,
    indf::Index,
    name::String
)

Fix initial time, final time is free and given by the variable at the provided index.

Note

You must use time! only once to set either the initial or the final time, or both.

Examples

julia> time!(ocp, 0, Index(2), "t")
source
CTBase.time!Function
time!(
    ocp::OptimalControlModel{<:TimeDependence, NonFixed},
    ind0::Index,
    tf::Real
)
time!(
    ocp::OptimalControlModel{<:TimeDependence, NonFixed},
    ind0::Index,
    tf::Real,
    name::String
)

Fix final time, initial time is free and given by the variable at the provided index.

Examples

julia> time!(ocp, Index(2), 1, "t")
source
CTBase.time!Function
time!(
    ocp::OptimalControlModel{<:TimeDependence, NonFixed},
    ind0::Index,
    indf::Index
)
time!(
    ocp::OptimalControlModel{<:TimeDependence, NonFixed},
    ind0::Index,
    indf::Index,
    name::String
)

Initial and final times are free and given by the variable at the provided indices.

Examples

julia> time!(ocp, Index(2), Index(3), "t")
source
CTBase.time!Function
time!(
    ocp::OptimalControlModel,
    times::AbstractVector{<:Real}
) -> Any
time!(
    ocp::OptimalControlModel,
    times::AbstractVector{<:Real},
    name::String
) -> Any

Fix initial and final times to times[1] and times[2], respectively.

Examples

julia> time!(ocp, [ 0, 1 ])
julia> ocp.initial_time
0
julia> ocp.final_time
1
julia> ocp.time_name
"t"

julia> time!(ocp, [ 0, 1 ], "s")
julia> ocp.initial_time
0
julia> ocp.final_time
1
julia> ocp.time_name
"s"

julia> time!(ocp, [ 0, 1 ], :s)
julia> ocp.initial_time
0
julia> ocp.final_time
1
julia> ocp.time_name
"s"
source
CTBase.variable!Function
variable!(ocp::OptimalControlModel, q::Integer)
variable!(
    ocp::OptimalControlModel,
    q::Integer,
    name::String
)
variable!(
    ocp::OptimalControlModel,
    q::Integer,
    name::String,
    components_names::Vector{String}
)

Define the variable dimension and possibly the names of each component.

Note

You can use variable! once to set the variable dimension when the model is NonFixed.

Examples

julia> variable!(ocp, 1, "v")
julia> variable!(ocp, 2, "v", [ "v₁", "v₂" ])
source
CTBase.∂ₜMethod
∂ₜ(f) -> CTBase.var"#115#117"

Partial derivative wrt time of a function.

Example

julia> ∂ₜ((t,x) -> t*x)(0,8)
8
source
RecipesBase.plot!Method
plot!(
    p::Plots.Plot,
    sol::OptimalControlSolution;
    layout,
    control,
    time,
    state_style,
    control_style,
    costate_style,
    kwargs...
) -> Plots.Plot

Plot the optimal control solution sol using the layout layout.

Notes.

  • The argument layout can be :group or :split (default).
  • control can be :components, :norm or :all.
  • time can be :default or :normalized.
  • The keyword arguments state_style, control_style and costate_style are passed to the plot function of the Plots package. The state_style is passed to the plot of the state, the control_style is passed to the plot of the control and the costate_style is passed to the plot of the costate.
source
RecipesBase.plotMethod
plot(
    sol::OptimalControlSolution;
    layout,
    control,
    time,
    state_style,
    control_style,
    costate_style,
    kwargs...
) -> Any

Plot the optimal control solution sol using the layout layout.

Notes.

  • The argument layout can be :group or :split (default).
  • The keyword arguments state_style, control_style and costate_style are passed to the plot function of the Plots package. The state_style is passed to the plot of the state, the control_style is passed to the plot of the control and the costate_style is passed to the plot of the costate.
source
CTBase.@LieMacro

Macros for Lie and Poisson brackets

Example

julia> F0 = VectorField(x -> [x[1], x[2], (1-x[3])])
julia> F1 = VectorField(x -> [0, -x[3], x[2]])
julia> @Lie [F0, F1]([1, 2, 3])
[0, 5, 4]
julia> H0 = Hamiltonian((x, p) -> 0.5*(2x[1]^2+x[2]^2+p[1]^2))
julia> H1 = Hamiltonian((x, p) -> 0.5*(3x[1]^2+x[2]^2+p[2]^2))
julia> @Lie {H0, H1}([1, 2, 3], [1,0,7])
3.0
source
CTBase.@defMacro

Define an optimal control problem. One pass parsing of the definition.

Example

@def ocp begin
    tf ∈ R, variable
    t ∈ [ 0, tf ], time
    x ∈ R², state
    u ∈ R, control
    tf ≥ 0
    -1 ≤ u(t) ≤ 1
    q = x₁
    v = x₂
    q(0) == 1
    v(0) == 2
    q(tf) == 0
    v(tf) == 0
    0 ≤ q(t) ≤ 5,       (1)
    -2 ≤ v(t) ≤ 3,      (2)
    ẋ(t) == [ v(t), u(t) ]
    tf → min
end
source