Skip to content

Commit e6db092

Browse files
authored
Merge pull request #480 from control-toolbox/478-dev-scalar-vs-dim-one
abstract doc update
2 parents bfaa0e9 + 53bf52b commit e6db092

File tree

3 files changed

+48
-9
lines changed

3 files changed

+48
-9
lines changed

docs/src/tutorial-abstract.md

+39
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ As before, there are automatic aliases (`u₁` and `u1` for `u[1]`, *etc.*) and
137137
end
138138
```
139139

140+
!!! note
141+
One dimensional variable, state or control are treated as scalars (`Real`), not vectors (`Vector`). In Julia, for `x::Real`, it is possible to write `x[1]` (and `x[1][1]`...) so it is OK (though useless) to write `x₁`, `x1` or `x[1]` instead of simply `x` to access the corresponding value. Conversely it is *not* OK to use such an `x` as a vector, for instance as in `...f(x)...` where `f(x::Vector{T}) where {T <: Real}`.
142+
140143
## [Dynamics](@id tutorial-abstract-dynamics)
141144

142145
```julia
@@ -299,6 +302,38 @@ using OptimalControl
299302
end
300303
```
301304

305+
!!! caveat
306+
Constraint bounds must be *effective*, that is must not depend on a variable. For instance, instead of
307+
```julia
308+
o = @def begin
309+
v R, variable
310+
t [0, 1], time
311+
x R², state
312+
u R, control
313+
-1 v 1
314+
x₁(0) == -1
315+
x₂(0) == v # wrong: the bound is not effective (as it depends on the variable)
316+
x(1) == [0, 0]
317+
(t) == [x₂(t), u(t)]
318+
( 0.5u(t)^2 ) min
319+
end
320+
```
321+
write
322+
```julia
323+
o = @def begin
324+
v R, variable
325+
t [0, 1], time
326+
x R², state
327+
u R, control
328+
-1 v 1
329+
x₁(0) == -1
330+
x₂(0) - v == 0 # OK: the boundary contraint may involve the variable
331+
x(1) == [0, 0]
332+
(t) == [x₂(t), u(t)]
333+
( 0.5u(t)^2 ) min
334+
end
335+
```
336+
302337
## [Mayer cost](@id tutorial-abstract-mayer)
303338

304339
```julia
@@ -506,3 +541,7 @@ end
506541

507542
- Parsing errors should be explicit enough (with line number in the `@def` `begin ... end` block indicated) 🤞🏾
508543
- Check tutorials and applications in the documentation for further use.
544+
545+
## Known issues
546+
547+
- [Constants and (reverse over forward) AD](https://github.com/JuliaSmoothOptimizers/ADNLPModels.jl/issues/346)

docs/src/tutorial-double-integrator-energy.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ ocp = @def begin
4141
t ∈ [0, 1], time
4242
x ∈ R², state
4343
u ∈ R, control
44-
x(0) == [ -1, 0 ]
45-
x(1) == [ 0, 0 ]
46-
ẋ(t) == [ x₂(t), u(t) ]
44+
x(0) == [-1, 0]
45+
x(1) == [0, 0]
46+
ẋ(t) == [x₂(t), u(t)]
4747
∫( 0.5u(t)^2 ) → min
4848
end
4949
nothing # hide
@@ -91,10 +91,10 @@ ocp = @def begin
9191
9292
x₂(t) ≤ 1.2
9393
94-
x(0) == [ -1, 0 ]
95-
x(1) == [ 0, 0 ]
94+
x(0) == [-1, 0]
95+
x(1) == [0, 0]
9696
97-
ẋ(t) == [ x₂(t), u(t) ]
97+
ẋ(t) == [x₂(t), u(t)]
9898
9999
∫( 0.5u(t)^2 ) → min
100100

docs/src/tutorial-double-integrator-time.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Let us define the problem
3737
ocp = @def begin
3838
3939
tf ∈ R, variable
40-
t ∈ [ 0, tf ], time
40+
t ∈ [0, tf], time
4141
x = (q, v) ∈ R², state
4242
u ∈ R, control
4343
@@ -52,7 +52,7 @@ ocp = @def begin
5252
-5 ≤ q(t) ≤ 5, (1)
5353
-3 ≤ v(t) ≤ 3, (2)
5454
55-
ẋ(t) == [ v(t), u(t) ]
55+
ẋ(t) == [v(t), u(t)]
5656
5757
tf → min
5858
@@ -65,7 +65,7 @@ nothing # hide
6565
In order to ensure convergence of the direct solver, we have added the state constraints labelled (1) and (2):
6666

6767
```math
68-
-5 \leq q(t) \leq 5,\quad -3 \leq v(t) \leq 3,\quad t \in [ 0, t_f ].
68+
-5 \leq q(t) \leq 5,\quad -3 \leq v(t) \leq 3,\quad t \in [0, t_f].
6969
```
7070

7171
!!! note "Nota bene"

0 commit comments

Comments
 (0)