DiffEqPhysics.jl icon indicating copy to clipboard operation
DiffEqPhysics.jl copied to clipboard

Harmonic oscillator mass ignored

Open jw3126 opened this issue 4 years ago • 1 comments

While playing with a harmonic oscillator, I encountered the following interesting behaviour. Somehow DPRKN6 ignores my hard coded mass in the hamiltonian and gives a solution as if the mass was one:

using OrdinaryDiffEq
using DiffEqPhysics
using Plots

function H(p,q, param) 
    m = 1000 # very heavy object, should oscillate slowly
    k = 1.0
    1/2*p^2/m + 1/2*k*q^2
end

p0 = 0.0
q0 = 1.0
tspan = (0, 2pi)
prob = HamiltonianProblem(H, p0, q0, tspan)
alg = McAte5() # works
alg = Tsit5()  # works
alg = DPRKN6()
sol = solve(prob, alg)
plot(sol, fmt=:png)

image

jw3126 avatar Jun 22 '21 11:06 jw3126

I think DPRKNX might require that the system is a second order ODE, so we should throw an error if it's that's not held.

ChrisRackauckas avatar Jun 23 '21 15:06 ChrisRackauckas