headmyshoulder / odeint-v2

odeint - solving ordinary differential equations in c++ v2
http://headmyshoulder.github.com/odeint-v2/
Other
337 stars 102 forks source link

Integration values incorrect #197

Closed armstrongc93 closed 5 years ago

armstrongc93 commented 7 years ago

For a vehicle vibration analysis, I am implementing runge_kutta_dopri5 to evaluate the motions of a vehicle using C++ (code can be seen here). However, I am unable to get correct results.

Changing the time step or error values dramatically changes the solution; at 0.1 timestep the solution is incorrect but the general shape is close to the correct answer. If that value is reduced at all (or increased) the solution is entirely incorrect. The equations are correct, so I can only assume there is some kind of bug within odeint's stepper.

mariomulansky commented 7 years ago

To get a more accurate solution, you should be decreasing the tolerance (both absolute and relative, try 1E-8 for example). For the Dopri5, the timestep is only relevant for the first step, 0.1 looks like a reasonable choice.

armstrongc93 commented 7 years ago

I have adjusted the tolerance consistently and it has had no impact other than to make the solution worse. I switched in the Burlisch-Stoer stepper in for dopri5 and it works perfectly now. Could the micro-oscillation over the course of the response be affecting dopri5's error calculations?

mariomulansky commented 7 years ago

This is strange, Dopri5 should work perfectly fine if the tolerances are reasonably small... Can you provide a reduced example (with all parameters pre-defined), so I can easily verify your observation?

armstrongc93 commented 7 years ago

Sure, I'll define the parameters and required functions then upload the file here

mariomulansky commented 5 years ago

I'll assume this is resolved...