NBodySimulation

NBodySimulation[law,{state1,,staten},t]

generates a simulation of the motion of a system of n bodies with initial states statei, governed by the specified potential or force law, over a length of time t.

NBodySimulation[law,<|body1state1,,bodynstaten|>,t]

generates a simulation of the motion of a system of n bodies with names bodyi.

Details and Options

  • NBodySimulation gives an NBodySimulationData object as a result.
  • NBodySimulation by default solves classical nonrelativistic equations of motion.
  • The states statei are given as associations containing the following elements:
  • "Mass"mass
    "Position"position
    "Velocity"velocity
    "Charge"electrical charge (optional)
  • Additional elements used by particular potential or force laws can also be included.
  • Potential or force laws can be given as:
  • "name"named law
    <|"prop1"f1,|>law with specified properties
    funpairwise potential function
  • Possible named laws include:
  • "InverseSquare"unitless inverse square law
    "Harmonic"unitless harmonic potential
    {"Harmonic",params}unitless harmonic potential with parameters
    "Newtonian"Newtonian gravity with physical units
    "Coulomb"Coulomb's law with physical units
  • By default, "Harmonic" uses spring constant 1, equilibrium length 1.
  • {"Harmonic",<|"SpringConstant"->k,"EquilibriumLength"->len|>} uses spring constant k and equilibrium length len.
  • The following keys can be used when giving a law as an association:
  • "PairwisePotential"pairwise potential function between any two bodies
    "PairwiseForce"pairwise force function between any two bodies
    "ExternalPotential"additional potential function applied to each body
    "ExternalForce"additional force function applied to each body
    "Region"region confining the bodies
  • A pairwise potential or force function f is applied for all pairs of bodies i and j in the form f[statei,statej].
  • The values in the initial states specified for each body can be given as quantities with units.

Examples

open all close all

Basic Examples  (2)

Simulate two masses attached by a spring:

In[13]:=
Click for copyable input
Out[13]=
In[14]:=
Click for copyable input
Out[14]=

Simulate a three-body problem in two dimensions:

In[1]:=
Click for copyable input
Out[1]=

Get the state for the bodies at time t=4:

In[2]:=
Click for copyable input
Out[2]=

Plot the positions of the bodies:

In[3]:=
Click for copyable input
Out[3]=

Scope  (6)

Applications  (1)

Introduced in 2019
(12.0)