|
![](/i/fill.gif) |
> The fact that you are even asking that question makes me think you are
> implementing RK4 incorrectly.
Well, considering I have no clue why RK4 even works in the first place,
that's hardly surprising. ;-)
> The whole point of RK4 is that it gives
> more accurate results when the forces depend on positions of other
> particles (eg springs, collisions etc).
Really? I was under the impression that RK4 works just like other
methods, but just gives superior numerical accuracy.
> I suspect you are trying to apply the whole RK4 algorithm to one
> particle, then the next, etc. This is wrong.
It works fine if you only *have* one particle. ;-)
Actually, the simulation I'm about to run only consists of one particle.
But in future I'd like to handle more.
Currently my code is structured the way you indicate. (Heck, you can go
*read* it if you like... it's in the other NG.) But that doesn't allow
more complex systems.
> You need to store the positions and velocities of all the particles
> together in one "state" object. Then you apply each step of RK4 on the
> whole state at once. If you need the positions of other particles when
> calculating the force, then of course you have all the position and
> velocity information available in the state local to the current RK4 step.
Right. So just make all functions apply to the entire system at once. I
think I can do that...
--
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*
Post a reply to this message
|
![](/i/fill.gif) |