Hacker News new | ask | show | jobs
by Steuard 5025 days ago
But for physics, that result is great! An inaccuracy of just one part in 10^12 would be better than practically every physics experiment ever performed. That's like being off by the size of an atom when measuring the distance from LA to New York. (I'm speaking as a physicist rather than as a programmer here, mind you. But my limited experience programming physics would suggest that this is a perfectly acceptable level of error.)
2 comments

You're totally correct. And honestly, when you're doing numerical simulation like I am in the article, your error stems from the fact that you're only simulating 40 steps a second with only a first-degree solver.

Simulating physics for realsies takes a lot more than that.

The solver algorithm I used is called Euler's method, or ODE1 for short. It's the least accurate numerical ODE solver there is! When people do real physics simulations they use the Runge-Kutta (ODE45) or Adams-Bashforth-Moutlon (ODE113) solves, and they'll have 100,000 steps per second.

So while it's important to be cognizant of these things, it's also best not to stress to much about what's going on in the first of a series of educational articles :)

Unless you have a sensitivity to the initial conditions, hence you have a chaotic system. Which happens as fast as n body interactions in a gravitational field (but how many bodies/iterations do you need, which initial conditions makes the error a problem?)

But as I stated earlier, I think I have to check first because I am not that convinced any more on the performance point of view that JS has a problem, and float representation is not a JS problem, but a problem global to all CPUs.

Well it can be more than 10^-12 sometimes and the problem is not in physics but in trading when errors stack up. That's why I prefer when e-commerce solutions are based on fixed point arithmetic.

Even though canvases are still not homogeneous in terms of performance from browsers to browsers, some works fairly well.

Right, chaotic behavior is a valid issue. But in any realistic situation, you'll have lots of effects that inevitably get left out of simulations that contribute larger perturbations/errors than this rounding error would. (Heck, I suspect that even the thermal motion of the individual atoms in an object would have a larger effect.)

So no simulation will ever get exactly the "right" answer at that level. For practical purposes, all we care about is getting an answer that's within the ensemble of reasonable outcomes for initial conditions like ours.