N-body problem: Difference between revisions

julia example
(julia example)
Line 3,046:
Body 2 : 0.426346 -0.111425 -0.681150 | 0.234987 0.006241 -0.440245
Body 3 : -1.006089 -4.103186 -3.122591 | -0.359686 -1.177995 -0.875924</pre>
 
=={{header|Julia}}==
Uses the NBodySimulator module.
<lang julia>using StaticArrays, Plots, NBodySimulator
 
const bodies = [
MassBody(SVector(0.0, 1.0, 0.0), SVector( 5.775e-6, 0.0, 0.0), 2.0),
MassBody(SVector(0.0,-1.0, 0.0), SVector(-5.775e-6, 0.0, 0.0), 2.0),
MassBody(SVector(1.0, 0.5, 0.5), SVector(-2.5e-6, 1.5e-7, 1.5e7), 2.0)
]
 
const G = 6.673e-11 # m^3/kg/s^2
const timespan = (0.0, 1111150.0)
 
function nbodysim(nbodies, tspan)
system = GravitationalSystem(nbodies, G)
simulation = NBodySimulation(system, tspan)
run_simulation(simulation)
end
 
simresult = nbodysim(bodies, timespan)
plot(simresult)
</lang>
 
 
=={{header|K}}==
4,105

edits