Skip to content

Commit d7bc10a

Browse files
committed
docs: add functional API documentation with mathematical formulation
1 parent 4c22d34 commit d7bc10a

6 files changed

Lines changed: 1003 additions & 1 deletion

File tree

docs/make.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,10 @@ with_api_reference(src_dir, ext_dir) do api_pages
213213
"State constraint" => "example-state-constraint.md",
214214
],
215215
"Manual" => [
216-
"Define a problem" => "manual-abstract.md",
216+
"Define a problem" => [
217+
"Abstract syntax (@def)" => "manual-abstract.md",
218+
"Functional API (macro-free)" => "manual-macro-free.md",
219+
],
217220
"Use AI" => "manual-ai-llm.md",
218221
"Problem characteristics" => "manual-model.md",
219222
"Set an initial guess" => "manual-initial-guess.md",

docs/src/assets/custom.css

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,43 @@
3333
.responsive-columns-left-priority > div:first-child {
3434
flex: 1 1 100%;
3535
}
36+
}
37+
38+
/* 30% / 70% two-column layout */
39+
.responsive-columns-30-70 {
40+
display: flex;
41+
gap: 1rem;
42+
align-items: flex-start;
43+
margin-bottom: 1em;
44+
}
45+
46+
.responsive-columns-30-70 > div:first-child {
47+
flex: 3;
48+
min-width: 0;
49+
transition: opacity 0.5s ease-in-out, flex 0.5s ease-in-out, max-width 0.5s ease-in-out, max-height 0.5s ease-in-out;
50+
}
51+
52+
.responsive-columns-30-70 > div:last-child {
53+
flex: 7;
54+
min-width: 0;
55+
opacity: 1;
56+
max-width: 100%;
57+
max-height: none;
58+
transition: opacity 0.5s ease-in-out, flex 0.5s ease-in-out, max-width 0.5s ease-in-out, max-height 0.5s ease-in-out;
59+
}
60+
61+
@media (max-width: 700px) {
62+
.responsive-columns-30-70 > div:last-child {
63+
opacity: 0;
64+
max-width: 0;
65+
max-height: 0;
66+
flex: 0 0 0;
67+
overflow: hidden;
68+
margin: 0;
69+
padding: 0;
70+
}
71+
72+
.responsive-columns-30-70 > div:first-child {
73+
flex: 1 1 100%;
74+
}
3675
}

docs/src/index.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,57 @@ plot(sol)
4343
- The [`solve`](@ref) function has many options. See the [solve tutorial](@ref manual-solve).
4444
- The [`plot`](@ref) function is flexible. See the [plot tutorial](@ref manual-plot).
4545

46+
## [Mathematical formulation](@id math-formulation)
47+
48+
An optimal control problem (OCP) with fixed initial and final times can be described as minimising the cost functional (in Bolza form)
49+
50+
```math
51+
J(x, u) = g(x(t_0), x(t_f)) + \int_{t_0}^{t_f} f^{0}(t, x(t), u(t))\,\mathrm{d}t
52+
```
53+
54+
where the state $x$ and the control $u$ are functions of time $t$, subject for $t \in [t_0, t_f]$ to the differential constraint
55+
56+
```math
57+
\dot{x}(t) = f(t, x(t), u(t))
58+
```
59+
60+
and other constraints such as
61+
62+
```math
63+
\begin{array}{llcll}
64+
x_{\mathrm{lower}} & \le & x(t) & \le & x_{\mathrm{upper}}, \\
65+
u_{\mathrm{lower}} & \le & u(t) & \le & u_{\mathrm{upper}}, \\
66+
c_{\mathrm{lower}} & \le & c(t, x(t), u(t)) & \le & c_{\mathrm{upper}}, \\
67+
b_{\mathrm{lower}} & \le & b(x(t_0), x(t_f)) & \le & b_{\mathrm{upper}}.
68+
\end{array}
69+
```
70+
71+
If $g = 0$, the cost is said to be in **Lagrange form**; if $f^0 = 0$, it is in **Mayer form**.
72+
73+
### Free times and extra variables
74+
75+
The initial time $t_0$ and the final time $t_f$ may also be free, that is part of the optimisation variables:
76+
77+
```math
78+
J(x, u, t_0, t_f) \to \min.
79+
```
80+
81+
More generally, a vector $v \in \mathbb{R}^k$ of $k$ additional variables can be introduced (it may contain $t_0$, $t_f$, or any other free parameter). The cost, dynamics, and constraints then all depend on $v$:
82+
83+
```math
84+
J(x, u, v) = g(x(t_0), x(t_f), v) + \int_{t_0}^{t_f} f^{0}(t, x(t), u(t), v)\,\mathrm{d}t \to \min,
85+
```
86+
87+
```math
88+
\dot{x}(t) = f(t, x(t), u(t), v),
89+
```
90+
91+
with, in addition, box constraints on $v$:
92+
93+
```math
94+
v_{\mathrm{lower}} \le v \le v_{\mathrm{upper}}.
95+
```
96+
4697
## Citing us
4798

4899
If you use OptimalControl.jl in your work, please cite us:

0 commit comments

Comments
 (0)