Skip to content

Commit e011b1d

Browse files
committed
Add Hamiltonian examples with keywords to Poisson bracket section
- Show how to create Hamiltonian objects with autonomous/variable keywords - Explain that both Hamiltonians must have same dependencies - Add non-autonomous and variable examples
1 parent d12a623 commit e011b1d

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

docs/src/manual-differential-geometry.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,38 @@ Hfg = Poisson(f, g; autonomous=false)
263263
Hfg(1, [1, 2], [3, 4])
264264
```
265265

266+
### With Hamiltonian type and keywords
267+
268+
You can also create Hamiltonian objects explicitly with keywords, then use them without keywords in the Poisson function. **Important**: both Hamiltonians must have the same time and variable dependencies:
269+
270+
```@example main-10
271+
using OptimalControl # hide
272+
# Non-autonomous Hamiltonians created with keywords
273+
f_na(t, x, p) = t + p[1] * x[2] + p[2] * x[1]
274+
g_na(t, x, p) = t^2 + x[1]^2 + p[2]^2
275+
276+
F = OptimalControl.Hamiltonian(f_na; autonomous=false)
277+
G = OptimalControl.Hamiltonian(g_na; autonomous=false)
278+
279+
# No keywords needed here - both Hamiltonians are already non-autonomous
280+
Hfg = Poisson(F, G)
281+
Hfg(1, [1, 2], [3, 4])
282+
```
283+
284+
```@example main-11
285+
using OptimalControl # hide
286+
# Variable Hamiltonians created with keywords
287+
f_var(x, p, v) = x[1]^2 + p[2]^2 + v
288+
g_var(x, p, v) = x[2]^2 + p[1]^2 + 2*v
289+
290+
F = OptimalControl.Hamiltonian(f_var; variable=true)
291+
G = OptimalControl.Hamiltonian(g_var; variable=true)
292+
293+
# Both are variable, so the Poisson bracket is also variable
294+
Hfg = Poisson(F, G)
295+
Hfg([1, 2], [3, 4], 1)
296+
```
297+
266298
### Relation to Hamiltonian vector fields
267299

268300
The Poisson bracket is closely related to the Lie derivative. If $\vec{H} = (\nabla_p H, -\nabla_x H)$ denotes the Hamiltonian vector field associated to $H$, then

0 commit comments

Comments
 (0)