Types
This section describes systems types implemented in MathematicalSystems.jl
.
Abstract Systems
AbstractSystem
Abstract supertype for all system types.
AbstractContinuousSystem
Abstract supertype for all continuous system types.
AbstractDiscreteSystem
Abstract supertype for all discrete system types.
Continuous Systems
ContinuousIdentitySystem <: AbstractContinuousSystem
Trivial identity continuous-time system of the form:
Fields
statedim
– number of state variables
ConstrainedContinuousIdentitySystem <: AbstractContinuousSystem
Trivial identity continuous-time system with state constraints of the form:
Fields
statedim
– number of state variablesX
– state constraints
LinearContinuousSystem
Continuous-time linear system of the form:
Fields
A
– square matrix
AffineContinuousSystem
Continuous-time affine system of the form:
Fields
A
– square matrixb
– vector
LinearControlContinuousSystem
Continuous-time linear control system of the form:
Fields
A
– square matrixB
– matrix
ConstrainedLinearContinuousSystem
Continuous-time linear system with state constraints of the form:
Fields
A
– square matrixX
– state constraints
ConstrainedAffineContinuousSystem
Continuous-time affine system with state constraints of the form:
Fields
A
– square matrixb
– vectorX
– state constraints
ConstrainedAffineControlContinuousSystem
Continuous-time affine control system with state constraints of the form:
and $c$ a vector.
Fields
A
– square matrixB
– matrixc
– vectorX
– state constraintsU
– input constraints
ConstrainedLinearControlContinuousSystem
Continuous-time linear control system with state constraints of the form:
Fields
A
– square matrixB
– matrixX
– state constraintsU
– input constraints
LinearAlgebraicContinuousSystem
Continuous-time linear algebraic system of the form:
Fields
A
– matrixE
– matrix, same size asA
ConstrainedLinearAlgebraicContinuousSystem
Continuous-time linear system with state constraints of the form:
Fields
A
– matrixE
– matrix, same size asA
X
– state constraints
PolynomialContinuousSystem
Continuous-time polynomial system of the form:
Fields
p
– polynomial vector fieldstatedim
– number of state variables
ConstrainedPolynomialContinuousSystem
Continuous-time polynomial system with state constraints:
Fields
p
– polynomial vector fieldX
– constraint setstatedim
– number of state variables
BlackBoxContinuousSystem <: AbstractContinuousSystem
Continuous-time system defined by a right-hand side of the form:
Fields
f
– function that holds the right-hand sidestatedim
– number of state variables
ConstrainedBlackBoxContinuousSystem <: AbstractContinuousSystem
Continuous-time system defined by a right-hand side with state constraints of the form:
Fields
f
– function that holds the right-hand sidestatedim
– number of state variablesX
– state constraints
ConstrainedBlackBoxControlContinuousSystem <: AbstractContinuousSystem
Continuous-time control system defined by a right-hand side with state constraints of the form:
Fields
f
– function that holds the right-hand sidestatedim
– number of state variablesinputdim
– number of input variablesX
– state constraintsU
– input constraints
Discrete Systems
DiscreteIdentitySystem <: AbstractDiscreteSystem
Trivial identity discrete-time system of the form:
Fields
statedim
– number of state variables
ConstrainedDiscreteIdentitySystem <: AbstractDiscreteSystem
Trivial identity discrete-time system with state constraints of the form:
Fields
statedim
– number of state variablesX
– state constraints
LinearDiscreteSystem
Discrete-time linear system of the form:
Fields
A
– square matrix
AffineDiscreteSystem
Discrete-time affine system of the form:
Fields
A
– square matrixb
– vector
LinearControlDiscreteSystem
Discrete-time linear control system of the form:
Fields
A
– square matrixB
– matrix
ConstrainedLinearDiscreteSystem
Discrete-time linear system with state constraints of the form:
Fields
A
– square matrixX
– state constraints
ConstrainedAffineDiscreteSystem
Discrete-time affine system with state constraints of the form:
Fields
A
– square matrixb
– vectorX
– state constraints
ConstrainedLinearControlDiscreteSystem
Discrete-time linear control system with state constraints of the form:
Fields
A
– square matrixB
– matrixX
– state constraintsU
– input constraints
ConstrainedAffineControlDiscreteSystem
Continuous-time affine control system with state constraints of the form:
and $c$ a vector.
Fields
A
– square matrixB
– matrixc
– vectorX
– state constraintsU
– input constraints
LinearAlgebraicDiscreteSystem
Discrete-time linear algebraic system of the form:
Fields
A
– matrixE
– matrix, same size asA
ConstrainedLinearAlgebraicDiscreteSystem
Discrete-time linear system with state constraints of the form:
Fields
A
– matrixE
– matrix, same size asA
X
– state constraints
PolynomialDiscreteSystem
Discrete-time polynomial system of the form:
Fields
p
– polynomial vector fieldstatedim
– number of state variables
ConstrainedPolynomialDiscreteSystem
Discrete-time polynomial system with state constraints:
Fields
p
– polynomialX
– constraint setstatedim
– number of state variables
BlackBoxDiscreteSystem <: AbstractDiscreteSystem
Discrete-time system defined by a right-hand side of the form:
Fields
f
– function that holds the right-hand sidestatedim
– number of state variables
ConstrainedBlackBoxDiscreteSystem <: AbstractDiscreteSystem
Discrete-time system defined by a right-hand side with state constraints of the form:
Fields
f
– function that holds the right-hand sidestatedim
– number of state variablesX
– state constraints
ConstrainedBlackBoxControlDiscreteSystem <: AbstractDiscreteSystem
Discrete-time control system defined by a right-hand side with state constraints of the form:
Fields
f
– function that holds the right-hand sidestatedim
– number of state variablesinputdim
– number of input variablesX
– state constraintsU
– input constraints
Identity operator
IdentityMultiple{T} < AbstractMatrix{T} where T
A scalar multiple of the identity matrix of given order and numeric type.
Fields
M
– uniform scaling operator of typeT
n
– size of the identity matrix
Notes
This type can be used to create multiples of the identity of given size. Since only the multiple and the order are stored, the allocations are minimal.
Internally, the type wraps Julia's lazy multiple of the identity operator, UniformScaling
. IdentityMultiple
subtypes AbstractMatix
, hence it can be used in usual matrix arithmetic and for dispatch on AbstractMatrix
.
The difference between UniformScaling
and IdentityMultiple
is that while the size of the former is generic, the size of the latter is fixed.
Examples
The easiest way to create an identity multiple is to use the callable version of LinearAlgebra.I
:
julia> using MathematicalSystems: IdentityMultiple
julia> I2 = I(2)
IdentityMultiple{Float64} of value 1.0 and order 2
julia> I2 + I2
IdentityMultiple{Float64} of value 2.0 and order 2
julia> 4*I2
IdentityMultiple{Float64} of value 4.0 and order 2
The numeric type (default Float64
) can be passed as a second argument:
julia> I2r = I(2, Rational{Int})
IdentityMultiple{Rational{Int64}} of value 1//1 and order 2
julia> I2r + I2r
IdentityMultiple{Rational{Int64}} of value 2//1 and order 2
julia> 4*I2r
IdentityMultiple{Rational{Int64}} of value 4//1 and order 2
To create the matrix with a value different from the default (1.0
), there are two ways. Either pass the value through the callable I
, as in
julia> I2 = I(2.0, 2)
IdentityMultiple{Float64} of value 2.0 and order 2
julia> I2r = I(2//1, 2)
IdentityMultiple{Rational{Int64}} of value 2//1 and order 2
Or use the lower level constructor passing the UniformScaling
(I
):
julia> I2 = IdentityMultiple(2.0*I, 2)
IdentityMultiple{Float64} of value 2.0 and order 2
julia> I2r = IdentityMultiple(2//1*I, 2)
IdentityMultiple{Rational{Int64}} of value 2//1 and order 2
Initial Value Problems
InitialValueProblem
Parametric composite type for initial value problems. It is parameterized in the system's type.
Fields
s
– systemx0
– initial state
Examples
The linear system $x' = -x$ with initial condition $x_0 = [-1/2, 1/2]$:
julia> p = InitialValueProblem(LinearContinuousSystem([-1.0 0.0; 0.0 -1.0]), [-1/2, 1/2]);
julia> p.x0
2-element Array{Float64,1}:
-0.5
0.5
julia> statedim(p)
2
julia> inputdim(p)
0
MathematicalSystems.IVP
— Type.IVP
IVP
is an alias for InitialValueProblem
.
Input Types
AbstractInput
Abstract supertype for all input types.
Notes
The input types defined here implement an iterator interface, such that other methods can build upon the behavior of inputs which are either constant or varying.
Iteration is supported with an index number called iterator state. The iteration function Base.iterate
takes and returns a tuple (input
, state
), where input
represents the value of the input, and state
is an index which counts the number of times this iterator was called.
A convenience function nextinput(input, n)
is also provided and it returns the first n
elements of input
.
ConstantInput{UT} <: AbstractInput
Type representing an input that remains constant in time.
Fields
U
– input set
Examples
The constant input holds a single element and its length is infinite. To access the field U
, you can use Base's iterate
given a state, or the method nextinput
given the number of desired input elements:
julia> c = ConstantInput(-1//2)
ConstantInput{Rational{Int64}}(-1//2)
julia> iterate(c, 1)
(-1//2, nothing)
julia> iterate(c, 2)
(-1//2, nothing)
julia> collect(nextinput(c, 4))
4-element Array{Rational{Int64},1}:
-1//2
-1//2
-1//2
-1//2
The elements of this input are rational numbers:
julia> eltype(c)
Rational{Int64}
To transform a constant input, you can use map
as in:
julia> map(x->2*x, c)
ConstantInput{Rational{Int64}}(-1//1)
MathematicalSystems.VaryingInput
— Type.VaryingInput{UT, VUT<:AbstractVector{UT}} <: AbstractInput
Type representing an input that may vary with time.
Fields
U
– vector of input sets
Examples
The varying input holds a vector and its length equals the number of elements in the vector. Consider an input given by a vector of rational numbers:
julia> v = VaryingInput([-1//2, 1//2])
VaryingInput{Rational{Int64},Array{Rational{Int64},1}}(Rational{Int64}[-1//2, 1//2])
julia> length(v)
2
julia> eltype(v)
Rational{Int64}
Base's iterate
method receives the input and an integer state and returns the input element and the next iteration state:
julia> iterate(v, 1)
(-1//2, 2)
julia> iterate(v, 2)
(1//2, 3)
The method nextinput
receives a varying input and an integer n
and returns an iterator over the first n
elements of this input (where n=1
by default):
julia> typeof(nextinput(v))
Base.Iterators.Take{VaryingInput{Rational{Int64},Array{Rational{Int64},1}}}
julia> collect(nextinput(v, 1))
1-element Array{Rational{Int64},1}:
-1//2
julia> collect(nextinput(v, 2))
2-element Array{Rational{Int64},1}:
-1//2
1//2
You can collect the inputs in an array, or equivalently use list comprehension, (or use a for
loop):
julia> collect(v)
2-element Array{Rational{Int64},1}:
-1//2
1//2
julia> [2*vi for vi in v]
2-element Array{Rational{Int64},1}:
-1//1
1//1
Since this input type is finite, querying more elements than its length returns the full vector:
julia> collect(nextinput(v, 4))
2-element Array{Rational{Int64},1}:
-1//2
1//2
To transform a varying input, you can use map
as in:
julia> map(x->2*x, v)
VaryingInput{Rational{Int64},Array{Rational{Int64},1}}(Rational{Int64}[-1//1, 1//1])
Maps
MathematicalSystems.AbstractMap
— Type.AbstractMap
Abstract supertype for all map types.
MathematicalSystems.IdentityMap
— Type.IdentityMap
An identity map,
Fields
dim
– dimension
ConstrainedIdentityMap
An identity map with state constraints of the form:
Fields
dim
– dimensionX
– state constraints
MathematicalSystems.LinearMap
— Type.LinearMap
A linear map,
Fields
A
– matrix
ConstrainedLinearMap
A linear map with state constraints of the form:
Fields
A
– matrixX
– state constraints
MathematicalSystems.AffineMap
— Type.AffineMap
An affine map,
Fields
A
– matrixb
– vector
ConstrainedAffineMap
An affine map with state constraints of the form:
Fields
A
– matrixb
– vectorX
– state constraints
LinearControlMap
A linear control map,
Fields
A
– matrixB
– matrix
ConstrainedLinearControlMap
A linear control map with state and input constraints,
Fields
A
– matrixB
– matrixX
– state constraintsU
– input constraints
AffineControlMap
An affine control map,
Fields
A
– matrixB
– matrixc
– vector
ConstrainedAffineControlMap
An affine control map with state and input constraints,
Fields
A
– matrixB
– matrixc
– vectorX
– state constraintsU
– input constraints
MathematicalSystems.ResetMap
— Type.ResetMap
A reset map,
such that a subset of the variables is given a specified value, and the rest are unchanged.
Fields
dim
– dimensiondict
– dictionary whose keys are the indices of the variables that are reset, and whose values are the new values
ConstrainedResetMap
A reset map with state constraints of the form:
such that the specified variables are assigned a given value, and the remaining variables are unchanged.
Fields
dim
– dimensionX
– state constraintsdict
– dictionary whose keys are the indices of the variables that are reset, and whose values are the new values
Macros
MathematicalSystems.@map
— Macro.map(ex, args)
Returns an instance of the map type corresponding to the given expression.
Input
ex
– an expression defining the map, in the form of an anonymous functionargs
– additional optional arguments
Output
A map that best matches the given expression.
Examples
Let us first create a linear map using this macro:
julia> @map x -> [1 0; 0 0]*x
LinearMap{Int64,Array{Int64,2}}([1 0; 0 0])
We can create an affine system as well:
julia> @map x -> [1 0; 0 0]*x + [2, 0]
AffineMap{Int64,Array{Int64,2},Array{Int64,1}}([1 0; 0 0], [2, 0])
Additional arguments can be passed to @map
using the function-call form, i.e. separating the arguments by commas, and using parentheses around the macro call. For exmple, an identity map of dimension 5 can be defined as:
julia> @map(x -> x, dim=5)
IdentityMap(5)
An identity map can alternatively be created by giving a the size of the identity matrix as I(n)
, for example:
julia> @map x -> I(5)*x
IdentityMap(5)
Systems with output
SystemWithOutput{ST<:AbstractSystem, MT<:AbstractMap}
Parametric composite type for systems with outputs. It is parameterized in the system's type (ST
) and in the map's type (MT
).
Fields
s
– system of typeST
outputmap
– output map of typeMT
MathematicalSystems.LinearTimeInvariantSystem
— Function.LinearTimeInvariantSystem(A, B, C, D)
A linear time-invariant system with of the form
Input
A
– matrixB
– matrixC
– matrixD
– matrix
Output
A system with output such that the system is a linear control continuous system and the output map is a linear control map.
LinearTimeInvariantSystem(A, B, C, D, X, U)
A linear time-invariant system with state and input constraints of the form
where $x(t) ∈ X$ and $u(t) ∈ U$ for all $t$.
Input
A
– matrixB
– matrixC
– matrixD
– matrixX
– state constraintsU
– input constraints
Output
A system with output such that the system is a constrained linear control continuous system and the output map is a constrained linear control map.
MathematicalSystems.LTISystem
— Function.LTISystem
LTISystem
is an alias for LinearTimeInvariantSystem
.