You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/manual-flow-ocp.md
+83-1Lines changed: 83 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -462,7 +462,7 @@ where $ p^0 = -1 $ since we are in the normal case, and where $c(x) = x - l_b$.
462
462
u(x) = 0.
463
463
```
464
464
465
-
From the maximizing condition, along a boundary arc, we have $p(t) = 0$. Differentiating, we obtain $\dot{p}(t) = 2 x(t) - \mu(t) = 0$. Hence, along a boundary arc, the dual variable $\mu$ is given in feedback form by:
465
+
From the maximisation condition, along a boundary arc, we have $p(t) = 0$. Differentiating, we obtain $\dot{p}(t) = 2 x(t) - \mu(t) = 0$. Hence, along a boundary arc, the dual variable $\mu$ is given in feedback form by:
466
466
467
467
```math
468
468
\mu(x) = 2x.
@@ -503,3 +503,85 @@ p0 = -0.982237546583301
503
503
xf, pf = f(t0, x0, p0, tf)
504
504
xf
505
505
```
506
+
507
+
## Jump on the costate
508
+
509
+
Let consider the following problem:
510
+
511
+
```@example main
512
+
t0=0
513
+
tf=1
514
+
x0=[0, 1]
515
+
l = 1/9
516
+
@def ocp begin
517
+
t ∈ [ t0, tf ], time
518
+
x ∈ R², state
519
+
u ∈ R, control
520
+
x(t0) == x0
521
+
x(tf) == [0, -1]
522
+
x₁(t) ≤ l, (x_con)
523
+
ẋ(t) == [x₂(t), u(t)]
524
+
0.5∫(u(t)^2) → min
525
+
end
526
+
nothing # hide
527
+
```
528
+
529
+
The pseudo-Hamiltonian of this problem is
530
+
531
+
```math
532
+
H(x, p, u, \mu) = p_1\, x_2 + p_2\, u + 0.5\, p^0 u^2 + \mu\, c(x),
533
+
```
534
+
535
+
where $ p^0 = -1 $ since we are in the normal case, and where the constraint is $c(x) = l - x_1 \ge 0$. Along a boundary arc, when $c(x(t)) = 0$, we have $x_1(t) = l$, so $\dot{x}_1(t) = x_2(t) = 0$. Differentiating again, we obtain $\dot{x}_2(t) = u(t) = 0$ (the constraint is of order 2). Hence, along a boundary arc, the control in feedback form is:
536
+
537
+
538
+
```math
539
+
u(x, p) = 0.
540
+
```
541
+
542
+
From the maximisation condition, along a boundary arc, we have $p_2(t) = 0$. Differentiating, we obtain $\dot{p}_2(t) = -p_1(t) = 0$. Differentiating again, we obtain $\dot{p}_1(t) = \mu(t) = 0$. Hence, along a boundary arc, the Lagrange multiplier $\mu$ is given in feedback form by:
543
+
544
+
```math
545
+
\mu(x, p) = 0.
546
+
```
547
+
548
+
Outside a boundary arc, the maximisation condition gives $u(x, p) = p_2$. A deeper analysis of the problem shows that the optimal solution has 3 arcs, the first and the third ones are interior to the constraint. The second arc is a boundary arc, that is $x_1(t) = l$ along the second arc. We denote by $t_1$ and $t_2$ the two switching times. We have $t_1 = 3l = 1/3$ and $t_2 = 1 - 3l = 2/3$, since $l=1/9$. The initial costate solution is $p(0) = [-18, -6]$.
549
+
550
+
!!! danger "Important"
551
+
552
+
The costate is discontinuous at $t_1$ and $t_2$ with a jump of $18$.
553
+
554
+
Let us compute the solution concatenating the flows with the jumps.
555
+
556
+
```@example main
557
+
t1 = 3l
558
+
t2 = 1 - 3l
559
+
p0 = [-18, -6]
560
+
561
+
fs = Flow(ocp,
562
+
(x, p) -> p[2] # control along regular arc
563
+
)
564
+
fc = Flow(ocp,
565
+
(x, p) -> 0, # control along boundary arc
566
+
(x, u) -> l-x[1], # state constraint
567
+
(x, p) -> 0 # Lagrange multiplier
568
+
)
569
+
570
+
ν = 18 # jump value of p1 at t1 and t2
571
+
572
+
f = fs * (t1, [ν, 0], fc) * (t2, [ν, 0], fs)
573
+
574
+
xf, pf = f(t0, x0, p0, tf) # xf should be [0, -1]
575
+
```
576
+
577
+
Let us solve the problem with a direct method to compare with the solution from the flow.
0 commit comments