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
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
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
+
266
298
### Relation to Hamiltonian vector fields
267
299
268
300
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