! set up arrays of particles Xi and particles Xj
-
Xi = spread (X, dim =3, ncopies = N )
-
Xj = spread (X, dim = 2, ncopies = N )
-
Ms = spread (M, dim=2, ncopies = N )
|
! displacements and Euclidean distance
-
D = Xj - Xi
-
R = sqrt (spread ( sum ( D*D, dim=1), dim =1, ncopies=3)))
|
! calculate accelerations for all pairs except on main diagonal
-
where (diag)
-
elsewhere
-
end where
-
Grav = sum (A, dim=3)
|
end function Grav
|