Ok, so I did some investigation on my code, with these initial values, that looks like this, I calculated the net linear momentum of the system and plotted it like so, seem's like momentum is conserved? how's this possible?
EDIT: time of simulation 1000 sec and time-step dt=0.01 sec
Hmm interesting. Nice work on testing it! In the time you plotted, do the orbits close? It's possible you didn't plot long enough to see a failure.
You can also make the time step bigger to make the effect more obvious. (Although if you make the time step too big, other things will go wrong.) You can also zoom further in on that line to see how varies on even smaller scales.
Euler's method for sure doesn't conserve momentum. That explanation is definitely correct.
As for why you're not seeing it, I'm not sure. I'd have to play with it myself. If you make the time step big enough that orbits start to precess, I'm pretty sure you'll find that that line it's not straight.
That said, Python's print statement might be lying to you. Try with a format statement. Like:
print("{.14e}".format(P_all[-1]))
It definitely won't be exactly zero. If it is, your not setting it correctly. There should at the very least be roundoff error.
1
u/[deleted] Oct 05 '19 edited Oct 05 '19
Ok, so I did some investigation on my code, with these initial values, that looks like this, I calculated the net linear momentum of the system and plotted it like so, seem's like momentum is conserved? how's this possible?
EDIT: time of simulation 1000 sec and time-step dt=0.01 sec