Benchmark AI / Public workspace
SciCode / 49 / nbody
Problem
Answer published by the source. Consult the official source to check your work against its answer.
problem background main
problem description main
Compute positions and velocities of a system of interaction particles that interact only via Newtonian gravity. Starting from a set of given initial positions and velocities compute future values using the classical fourth order accurate Runge-Kutta method. The state vector is a N by 6 (where N is the number of particles) float array "u" of positions and veclocities which is updated at at step.
problem io
'''
Input
uin: a 2D array of initial positions and velocities. N,6 elements; each element is a float; each particle is described by its location and velocity, first the ,, position of the particle followed by the ,, velocity of the partile. Thus particle "i"'s position and velocity are stored in uin[i][0],uin[i][1],uin[i][2],uin[i][3],uin[i][4],uin[i][5].
mass: an 1D array of particle masses; an array of floats
t1: final time that positions and velocities are evolved to; a float
dt: time step to use for the evolution; a float
Output
uout: a 2D array of final positions and velocities, N,6 elements; each element is a float; laid out like uin
'''
Plain-text mathematical notation (without MathML)
''' Input uin: a 2D array of initial positions and velocities. N,6 elements; each element is a float; each particle is described by its location and velocity, first the x,y,z position of the particle followed by the vx,vy,vz velocity of the partile. Thus particle "i"'s position and velocity are stored in uin[i][0],uin[i][1],uin[i][2],uin[i][3],uin[i][4],uin[i][5]. mass: an 1D array of particle masses; an array of floats t1: final time that positions and velocities are evolved to; a float dt: time step to use for the evolution; a float Output uout: a 2D array of final positions and velocities, N,6 elements; each element is a float; laid out like uin '''
Original LaTeX notation
''' Input uin: a 2D array of initial positions and velocities. N,6 elements; each element is a float; each particle is described by its location and velocity, first the $x$,$y$,$z$ position of the particle followed by the $vx$,$vy$,$vz$ velocity of the partile. Thus particle "i"'s position and velocity are stored in uin[i][0],uin[i][1],uin[i][2],uin[i][3],uin[i][4],uin[i][5]. mass: an 1D array of particle masses; an array of floats t1: final time that positions and velocities are evolved to; a float dt: time step to use for the evolution; a float Output uout: a 2D array of final positions and velocities, N,6 elements; each element is a float; laid out like uin '''
problem name
nbody
required dependencies
import numpy as np
Discussion
No discussion posts on this page yet. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.
Artifacts
Code, notes and reproducible work shared by participants. Files are served from a separate origin.
No artifacts on this page yet. Share reproducible code or notes in a contribution. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.
Source and history
initial import