-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathvector_field.jl
165 lines (121 loc) · 4.77 KB
/
vector_field.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# =============================
# Vector Field for continuous system
# =============================
"""
vector_field(system::ContinuousIdentitySystem, x::AbstractVector)
Return the vector field state of a `ContinuousIdentitySystem`.
### Input
- `system` -- `ContinuousIdentitySystem`
- `x` -- state (it should be any vector type)
### Output
A zeros vector of dimension `statedim`.
"""
function vector_field(system::ContinuousIdentitySystem, x::AbstractVector)
!_is_conformable_state(system, x) && _argument_error(:x)
return zeros(statedim(system))
end
"""
vector_field(system::ConstrainedContinuousIdentitySystem, x::AbstractVector;
[check_constraints]=true)
Return the vector field state of a `ConstrainedContinuousIdentitySystem`.
### Input
- `system` -- `ConstrainedContinuousIdentitySystem`
- `x` -- state (it should be any vector type)
- `check_constraints` -- (optional, default: `true`) check if the state belongs to
the state set
### Output
A zeros vector of dimension `statedim`.
"""
function vector_field(system::ConstrainedContinuousIdentitySystem, x::AbstractVector;
check_constraints::Bool=true)
!_is_conformable_state(system, x) && _argument_error(:x)
if check_constraints
!_in_stateset(system, x) && _argument_error(:x,:X)
end
return zeros(statedim(system))
end
"""
vector_field(system::AbstractContinuousSystem, x::AbstractVector;
[check_constraints]=true)
Return the vector field state of an `AbstractContinuousSystem`.
### Input
- `system` -- `AbstractContinuousSystem`
- `x` -- state (it should be any vector type)
- `check_constraints` -- (optional, default: `true`) check if the state belongs to
the state set
### Output
The vector field of the system at state `x`.
"""
vector_field(system::AbstractContinuousSystem, x::AbstractVector; kwargs...) =
_instantiate(system, x; kwargs...)
"""
vector_field(system::AbstractContinuousSystem, x::AbstractVector, u::AbstractVector;
[check_constraints]=true)
Return the vector field state of an `AbstractContinuousSystem`.
### Input
- `system` -- `AbstractContinuousSystem`
- `x` -- state (it should be any vector type)
- `u` -- input (it should be any vector type) or noise, if `system`
is not controlled
- `check_constraints` -- (optional, default: `true`) check if the state belongs to
the state set
### Output
The vector field of the system at state `x` and applying input `u`.
### Notes
If the system is not controlled but noisy, the input `u` is interpreted as noise.
"""
vector_field(system::AbstractContinuousSystem, x::AbstractVector, u::AbstractVector; kwargs...) =
_instantiate(system, x, u; kwargs...)
"""
vector_field(system::AbstractContinuousSystem,
x::AbstractVector, u::AbstractVector, w::AbstractVector; [check_constraints]=true)
Return the vector field state of an `AbstractContinuousSystem`.
### Input
- `system` -- `AbstractContinuousSystem`
- `x` -- state (it should be any vector type)
- `u` -- input (it should be any vector type)
- `w` -- noise (it should be any vector type)
- `check_constraints` -- (optional, default: `true`) check if the state belongs to
the state set
### Output
The vector field of the system at state `x` and applying input `u` and noise `w`.
"""
vector_field(system::AbstractContinuousSystem, x::AbstractVector, u::AbstractVector, w::AbstractVector; kwargs...) =
_instantiate(system, x, u, w; kwargs...)
# =============================
# VectorField type for continuous system
# =============================
"""
VectorField{T<:Function}
Type that computes the vector field of an `AbstractContinuousSystem`.
### Fields
- `field` -- function for calculating the vector field
"""
struct VectorField{T<:Function}
field::T
end
# function-like evaluation
@inline function (V::VectorField)(args...)
evaluate(V, args...)
end
function evaluate(V::VectorField, args...)
return V.field(args...)
end
"""
VectorField(sys::AbstractContinuousSystem)
Constructor for creating a `VectorField` from an `AbstractContinuousSystem`.
### Input
- `sys` -- `AbstractContinuousSystem`
### Ouptut
The `VectorField` for the continuous system `sys`.
"""
function VectorField(sys::AbstractContinuousSystem)
if inputdim(sys) == 0 && noisedim(sys) == 0
field = (x) -> vector_field(sys, x)
elseif inputdim(sys) == 0 || noisedim(sys) == 0
field = (x, u) -> vector_field(sys, x, u)
else
field = (x, u, w) -> vector_field(sys, x, u, w)
end
return VectorField(field)
end