-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathdiscrete.jl
175 lines (148 loc) · 4.72 KB
/
discrete.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
166
167
168
169
170
171
172
173
174
175
"""
DiscreteIdentitySystem <: AbstractDiscreteSystem
Trivial identity discrete-time system of the form
```math
x_{k+1} = x_k.
```
"""
struct DiscreteIdentitySystem <: AbstractDiscreteSystem
statedim::Int
end
statedim(s::DiscreteIdentitySystem) = s.statedim
inputdim(s::DiscreteIdentitySystem) = 0
"""
ConstrainedDiscreteIdentitySystem <: AbstractDiscreteSystem
Trivial identity discrete-time system with state constraints of the form
```math
x_{k+1} = x_k, x_k ∈ \\mathcal{X}.
```
"""
struct ConstrainedDiscreteIdentitySystem{ST} <: AbstractDiscreteSystem
statedim::Int
X::ST
end
statedim(s::ConstrainedDiscreteIdentitySystem) = s.statedim
stateset(s::ConstrainedDiscreteIdentitySystem) = s.X
inputdim(s::ConstrainedDiscreteIdentitySystem) = 0
"""
LinearDiscreteSystem
Discrete-time linear system of the form
```math
x_{k+1} = A x_k.
```
### Fields
- `A` -- square matrix
"""
struct LinearDiscreteSystem{T, MT <: AbstractMatrix{T}} <: AbstractDiscreteSystem
A::MT
end
LinearDiscreteSystem{T, MT <: AbstractMatrix{T}}(A::MT) = LinearDiscreteSystem{T, MT}(A)
statedim(s::LinearDiscreteSystem) = Base.LinAlg.checksquare(s.A)
inputdim(s::LinearDiscreteSystem) = 0
"""
LinearControlDiscreteSystem
Discrete-time linear control system of the form
```math
x_{k+1} = A x_k + B u_k.
```
### Fields
- `A` -- square matrix
- `B` -- matrix
"""
struct LinearControlDiscreteSystem{T, MT <: AbstractMatrix{T}} <: AbstractDiscreteSystem
A::MT
B::MT
end
function LinearControlDiscreteSystem{T, MT <: AbstractMatrix{T}}(A::MT, B::MT)
@assert Base.LinAlg.checksquare(A) == size(B, 1)
return LinearControlDiscreteSystem{T, MT}(A, B)
end
statedim(s::LinearControlDiscreteSystem) = Base.LinAlg.checksquare(s.A)
inputdim(s::LinearControlDiscreteSystem) = size(s.B, 2)
"""
ConstrainedLinearDiscreteSystem
Discrete-time linear system with state constraints of the form
```math
x_{k+1} = A x_k, x_k ∈ \\mathcal{X}.
```
### Fields
- `A` -- square matrix
- `X` -- state constraints
"""
struct ConstrainedLinearDiscreteSystem{T, MT <: AbstractMatrix{T}, ST} <: AbstractDiscreteSystem
A::MT
X::ST
end
ConstrainedLinearDiscreteSystem{T, MT <: AbstractMatrix{T}, ST}(A::MT, X::ST) = ConstrainedLinearDiscreteSystem{T, MT, ST}(A, X)
statedim(s::ConstrainedLinearDiscreteSystem) = Base.LinAlg.checksquare(s.A)
stateset(s::ConstrainedLinearDiscreteSystem) = s.X
inputdim(s::ConstrainedLinearDiscreteSystem) = 0
"""
ConstrainedLinearControlDiscreteSystem
Discrete-time linear control system with state constraints of the form
```math
x_{k+1} = A x_k + B u_k, x_k ∈ \\mathcal{X}, u_k ∈ \\mathcal{U} \\text{ for all } k.
```
### Fields
- `A` -- square matrix
- `B` -- matrix
- `X` -- state constraints
- `U` -- input constraints
"""
struct ConstrainedLinearControlDiscreteSystem{T, MT <: AbstractMatrix{T}, ST, UT} <: AbstractDiscreteSystem
A::MT
B::MT
X::ST
U::UT
end
function ConstrainedLinearControlDiscreteSystem{T, MT <: AbstractMatrix{T}, ST, UT}(A::MT, B::MT, X::ST, U::UT)
@assert Base.LinAlg.checksquare(A) == size(B, 1)
return ConstrainedLinearControlDiscreteSystem{T, MT, ST, UT}(A, B, X, U)
end
statedim(s::ConstrainedLinearControlDiscreteSystem) = Base.LinAlg.checksquare(s.A)
stateset(s::ConstrainedLinearControlDiscreteSystem) = s.X
inputdim(s::ConstrainedLinearControlDiscreteSystem) = size(s.B, 2)
inputset(s::ConstrainedLinearControlDiscreteSystem) = s.U
"""
LinearAlgebraicDiscreteSystem
Discrete-time linear algebraic system of the form
```math
E x_{k+1} = A x_k.
```
### Fields
- `A` -- matrix
- `E` -- matrix, same size as `A`
"""
struct LinearAlgebraicDiscreteSystem{T, MT <: AbstractMatrix{T}} <: AbstractDiscreteSystem
A::MT
E::MT
end
function LinearAlgebraicDiscreteSystem{T, MT <: AbstractMatrix{T}}(A::MT, E::MT)
@assert size(A) == size(E)
return LinearAlgebraicDiscreteSystem{T, MT}(A, E)
end
statedim(s::LinearAlgebraicDiscreteSystem) = size(s.A, 1)
inputdim(s::LinearAlgebraicDiscreteSystem) = 0
"""
ConstrainedLinearAlgebraicDiscreteSystem
Discrete-time linear system with state constraints of the form
```math
E x_{k+1} = A x_k, x_k ∈ \\mathcal{X}.
```
### Fields
- `A` -- matrix
- `E` -- matrix, same size as `A`
- `X` -- state constraints
"""
struct ConstrainedLinearAlgebraicDiscreteSystem{T, MT <: AbstractMatrix{T}, ST} <: AbstractDiscreteSystem
A::MT
E::MT
X::ST
end
function ConstrainedLinearAlgebraicDiscreteSystem{T, MT <: AbstractMatrix{T}, ST}(A::MT, E::MT, X::ST)
@assert size(A) == size(E)
return ConstrainedLinearAlgebraicDiscreteSystem{T, MT, ST}(A, E, X)
end
statedim(s::ConstrainedLinearAlgebraicDiscreteSystem) = size(s.A, 1)
stateset(s::ConstrainedLinearAlgebraicDiscreteSystem) = s.X
inputdim(s::ConstrainedLinearAlgebraicDiscreteSystem) = 0