# N-Body Simulation using symplectic integrators

• A

## Summary:

Need help on algorithm clarification

## Main Question or Discussion Point

Hi,
I hope I am in the right section of the forum. I was trying to understand the following algorithm:

https://benchmarksgame-team.pages.debian.net/benchmarksgame/program/nbody-python3-1.html
and particulary this part:
Python:
def advance(dt, n, bodies=SYSTEM, pairs=PAIRS):

for i in range(n):
for (([x1, y1, z1], v1, m1),
([x2, y2, z2], v2, m2)) in pairs:
dx = x1 - x2
dy = y1 - y2
dz = z1 - z2
mag = dt * ((dx * dx + dy * dy + dz * dz) ** (-1.5))
b1m = m1 * mag
b2m = m2 * mag
v1 -= dx * b2m
v1 -= dy * b2m
v1 -= dz * b2m
v2 += dx * b1m
v2 += dy * b1m
v2 += dz * b1m
for (r, [vx, vy, vz], m) in bodies:
r += dt * vx
r += dt * vy
r += dt * vz
What are the mag and b1m variables? would be very thankful for any explanations or resources that derives this algorithm.

Related Classical Physics News on Phys.org
Ibix
Can you write it out as a formula? It may be better to go straight to the change in $v_x$.
Hint: $$\cos\theta=\frac{\Delta x}{\sqrt{\Delta x^2+\Delta y^2+\Delta z^2}}$$