Dear friends. I have a hamiltonian for the cart and pole system which is a standard problem in RL. Lagrangian version shown here, I just legendre transformed it.
I don’t need a full solution. I just want to step it forward in time in a symplectic, energy preserving way. Here’s what I got so far
using DiffEqPhysics
using DifferentialEquations
function cart_hamiltonian(q, p; g = 9.8, m1 = 2.0 , m2 = 1.0, L = 0.5)
(x, θ) = q
(p_x, p_θ) = p
h = g * L * m2 * cos(θ) +
(L^2 * m2 * p_x^2 + (m1 + m2)* p_θ^2 -
2 *L * m2 * p_x * p_θ * cos(θ) ) /
( 2 * L^2*m2*(m1 + m2 * sin(θ)^2))
return h
end
a = HamiltonianProblem(cart_hamiltonian,[0,0.3],[0,.1],[0,.2]) # gives me ODE problem?
sol = init(a, Tsit5())
which yields
MethodError: no method matching cart_hamiltonian(::Vector{Float64}, ::Vector{ForwardDiff.Dual{ForwardDiff.Tag{DiffEqPhysics.PhysicsTag, Float64}, Float64, 2}}, ::Nothing)
when cart_hamiltonian sees dual numbers.
ultimately I just want a function
function step(p,q,δt)
return (p_new, q_new) #new p q at slightly later time
I could write an euler integrator, but I feel like I’m close. I see step!
in the documentation. Part of the problem with Julia is that it’s so easy to write blazing fast integrators I never needed to learn the details. But autodiffed hamiltonians would be so freaking awesome. Thanks