N-body problem: Difference between revisions
Content deleted Content added
Add Swift |
Thundergnat (talk | contribs) Rename Perl 6 -> Raku, alphabetize, minor clean-up |
||
Line 428: | Line 428: | ||
===Further work=== |
===Further work=== |
||
And as in every experiment report/journal paper/whatever, time for some philosophizing, a more rigorous implementation will require the bodies to be realistic, this means they will not be point particles and hence the dynamics will be much more complex. Tidal effects, collisions, orbits will require much more computation. When I say realistic, I don't mean rigid bodies because even rigid bodies are an idealization of reality. And all of this, even with classical mechanics, employing the Newtonian version of Gravitation will be a worthy task for any competent Physicist, let alone a Programmer. Introduce the General Theory of Relativity and everything changes. I can go on and on, but this is a coding, not a rambling site. I will end by saying that the Inverse Square Law, a name often used for Newtonian Gravitation, is just one class of forces studied in Dynamics. The force relation can take any form, the N-body problem can therefore be solved in (countably/uncountably ?) infinite ways. |
And as in every experiment report/journal paper/whatever, time for some philosophizing, a more rigorous implementation will require the bodies to be realistic, this means they will not be point particles and hence the dynamics will be much more complex. Tidal effects, collisions, orbits will require much more computation. When I say realistic, I don't mean rigid bodies because even rigid bodies are an idealization of reality. And all of this, even with classical mechanics, employing the Newtonian version of Gravitation will be a worthy task for any competent Physicist, let alone a Programmer. Introduce the General Theory of Relativity and everything changes. I can go on and on, but this is a coding, not a rambling site. I will end by saying that the Inverse Square Law, a name often used for Newtonian Gravitation, is just one class of forces studied in Dynamics. The force relation can take any form, the N-body problem can therefore be solved in (countably/uncountably ?) infinite ways. |
||
=={{header|C sharp|C#}}== |
|||
{{trans|D}} |
|||
<lang csharp>using System; |
|||
using System.IO; |
|||
namespace NBodyProblem { |
|||
class Vector3D { |
|||
public Vector3D(double x, double y, double z) { |
|||
X = x; |
|||
Y = y; |
|||
Z = z; |
|||
} |
|||
public double X { get; } |
|||
public double Y { get; } |
|||
public double Z { get; } |
|||
public double Mod() { |
|||
return Math.Sqrt(X * X + Y * Y + Z * Z); |
|||
} |
|||
public static Vector3D operator +(Vector3D lhs, Vector3D rhs) { |
|||
return new Vector3D(lhs.X + rhs.X, lhs.Y + rhs.Y, lhs.Z + rhs.Z); |
|||
} |
|||
public static Vector3D operator -(Vector3D lhs, Vector3D rhs) { |
|||
return new Vector3D(lhs.X - rhs.X, lhs.Y - rhs.Y, lhs.Z - rhs.Z); |
|||
} |
|||
public static Vector3D operator *(Vector3D lhs, double rhs) { |
|||
return new Vector3D(lhs.X * rhs, lhs.Y * rhs, lhs.Z * rhs); |
|||
} |
|||
} |
|||
class NBody { |
|||
private readonly double gc; |
|||
private readonly int bodies; |
|||
private readonly int timeSteps; |
|||
private readonly double[] masses; |
|||
private readonly Vector3D[] positions; |
|||
private readonly Vector3D[] velocities; |
|||
private readonly Vector3D[] accelerations; |
|||
public NBody(string fileName) { |
|||
string[] lines = File.ReadAllLines(fileName); |
|||
string[] gbt = lines[0].Split(); |
|||
gc = double.Parse(gbt[0]); |
|||
bodies = int.Parse(gbt[1]); |
|||
timeSteps = int.Parse(gbt[2]); |
|||
masses = new double[bodies]; |
|||
positions = new Vector3D[bodies]; |
|||
velocities = new Vector3D[bodies]; |
|||
accelerations = new Vector3D[bodies]; |
|||
for (int i = 0; i < bodies; ++i) { |
|||
masses[i] = double.Parse(lines[i * 3 + 1]); |
|||
positions[i] = Decompose(lines[i * 3 + 2]); |
|||
velocities[i] = Decompose(lines[i * 3 + 3]); |
|||
} |
|||
Console.WriteLine("Contents of {0}", fileName); |
|||
foreach (string line in lines) { |
|||
Console.WriteLine(line); |
|||
} |
|||
Console.WriteLine(); |
|||
Console.Write("Body : x y z |"); |
|||
Console.WriteLine(" vx vy vz"); |
|||
} |
|||
public int GetTimeSteps() { |
|||
return timeSteps; |
|||
} |
|||
private Vector3D Decompose(string line) { |
|||
string[] xyz = line.Split(); |
|||
double x = double.Parse(xyz[0]); |
|||
double y = double.Parse(xyz[1]); |
|||
double z = double.Parse(xyz[2]); |
|||
return new Vector3D(x, y, z); |
|||
} |
|||
private void ComputeAccelerations() { |
|||
for (int i = 0; i < bodies; ++i) { |
|||
accelerations[i] = new Vector3D(0, 0, 0); |
|||
for (int j = 0; j < bodies; ++j) { |
|||
if (i != j) { |
|||
double temp = gc * masses[j] / Math.Pow((positions[i] - positions[j]).Mod(), 3); |
|||
accelerations[i] = accelerations[i] + (positions[j] - positions[i]) * temp; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
private void ComputeVelocities() { |
|||
for (int i = 0; i < bodies; ++i) { |
|||
velocities[i] = velocities[i] + accelerations[i]; |
|||
} |
|||
} |
|||
private void ComputePositions() { |
|||
for (int i = 0; i < bodies; ++i) { |
|||
positions[i] = positions[i] + velocities[i] + accelerations[i] * 0.5; |
|||
} |
|||
} |
|||
private void ResolveCollisions() { |
|||
for (int i = 0; i < bodies; ++i) { |
|||
for (int j = i + 1; j < bodies; ++j) { |
|||
if (positions[i].X == positions[j].X |
|||
&& positions[i].Y == positions[j].Y |
|||
&& positions[i].Z == positions[j].Z) { |
|||
Vector3D temp = velocities[i]; |
|||
velocities[i] = velocities[j]; |
|||
velocities[j] = temp; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
public void Simulate() { |
|||
ComputeAccelerations(); |
|||
ComputePositions(); |
|||
ComputeVelocities(); |
|||
ResolveCollisions(); |
|||
} |
|||
public void PrintResults() { |
|||
for (int i = 0; i < bodies; ++i) { |
|||
Console.WriteLine( |
|||
"Body {0} : {1,9:F6} {2,9:F6} {3,9:F6} | {4,9:F6} {5,9:F6} {6,9:F6}", |
|||
i + 1, |
|||
positions[i].X, positions[i].Y, positions[i].Z, |
|||
velocities[i].X, velocities[i].Y, velocities[i].Z |
|||
); |
|||
} |
|||
} |
|||
} |
|||
class Program { |
|||
static void Main(string[] args) { |
|||
NBody nb = new NBody("nbody.txt"); |
|||
for (int i = 0; i < nb.GetTimeSteps(); ++i) { |
|||
Console.WriteLine(); |
|||
Console.WriteLine("Cycle {0}", i + 1); |
|||
nb.Simulate(); |
|||
nb.PrintResults(); |
|||
} |
|||
} |
|||
} |
|||
}</lang> |
|||
{{out}} |
|||
<pre>Contents of nbody.txt |
|||
0.01 3 20 |
|||
1 |
|||
0 0 0 |
|||
0.01 0 0 |
|||
0.1 |
|||
1 1 0 |
|||
0 0 0.02 |
|||
0.001 |
|||
0 1 1 |
|||
0.01 -0.01 -0.01 |
|||
Body : x y z | vx vy vz |
|||
Cycle 1 |
|||
Body 1 : 0.010177 0.000179 0.000002 | 0.010354 0.000357 0.000004 |
|||
Body 2 : 0.998230 0.998232 0.020002 | -0.003539 -0.003536 0.020004 |
|||
Body 3 : 0.010177 0.988232 0.988055 | 0.010354 -0.013536 -0.013889 |
|||
Cycle 2 |
|||
Body 1 : 0.020709 0.000718 0.000011 | 0.010710 0.000721 0.000014 |
|||
Body 2 : 0.992907 0.992896 0.039971 | -0.007109 -0.007138 0.019935 |
|||
Body 3 : 0.020717 0.972888 0.972173 | 0.010727 -0.017153 -0.017876 |
|||
Cycle 3 |
|||
Body 1 : 0.031600 0.001625 0.000034 | 0.011072 0.001094 0.000033 |
|||
Body 2 : 0.983985 0.983910 0.059834 | -0.010735 -0.010835 0.019790 |
|||
Body 3 : 0.031643 0.953868 0.952235 | 0.011125 -0.020886 -0.021999 |
|||
Cycle 4 |
|||
Body 1 : 0.042858 0.002913 0.000081 | 0.011443 0.001481 0.000060 |
|||
Body 2 : 0.971393 0.971163 0.079509 | -0.014448 -0.014659 0.019561 |
|||
Body 3 : 0.042981 0.931039 0.928087 | 0.011552 -0.024772 -0.026299 |
|||
Cycle 5 |
|||
Body 1 : 0.054492 0.004595 0.000160 | 0.011826 0.001884 0.000097 |
|||
Body 2 : 0.955030 0.954509 0.098909 | -0.018278 -0.018649 0.019238 |
|||
Body 3 : 0.054766 0.904225 0.899522 | 0.012018 -0.028857 -0.030829 |
|||
Cycle 6 |
|||
Body 1 : 0.066517 0.006691 0.000281 | 0.012224 0.002308 0.000145 |
|||
Body 2 : 0.934759 0.933760 0.117931 | -0.022265 -0.022849 0.018806 |
|||
Body 3 : 0.067040 0.873197 0.866280 | 0.012530 -0.033199 -0.035655 |
|||
Cycle 7 |
|||
Body 1 : 0.078950 0.009225 0.000456 | 0.012642 0.002759 0.000206 |
|||
Body 2 : 0.910400 0.908677 0.136456 | -0.026454 -0.027316 0.018244 |
|||
Body 3 : 0.079856 0.837662 0.828023 | 0.013101 -0.037871 -0.040861 |
|||
Cycle 8 |
|||
Body 1 : 0.091815 0.012227 0.000702 | 0.013086 0.003245 0.000284 |
|||
Body 2 : 0.881722 0.878958 0.154340 | -0.030902 -0.032122 0.017523 |
|||
Body 3 : 0.093281 0.797239 0.784313 | 0.013749 -0.042975 -0.046559 |
|||
Cycle 9 |
|||
Body 1 : 0.105140 0.015737 0.001035 | 0.013564 0.003775 0.000383 |
|||
Body 2 : 0.848429 0.844216 0.171401 | -0.035684 -0.037362 0.016600 |
|||
Body 3 : 0.107405 0.751427 0.734579 | 0.014498 -0.048649 -0.052908 |
|||
Cycle 10 |
|||
Body 1 : 0.118964 0.019805 0.001481 | 0.014085 0.004362 0.000509 |
|||
Body 2 : 0.810137 0.803953 0.187408 | -0.040900 -0.043166 0.015414 |
|||
Body 3 : 0.122346 0.699554 0.678056 | 0.015384 -0.055097 -0.060138 |
|||
Cycle 11 |
|||
Body 1 : 0.133337 0.024498 0.002071 | 0.014662 0.005025 0.000672 |
|||
Body 2 : 0.766343 0.757509 0.202050 | -0.046687 -0.049720 0.013868 |
|||
Body 3 : 0.138268 0.640690 0.613685 | 0.016460 -0.062633 -0.068603 |
|||
Cycle 12 |
|||
Body 1 : 0.148327 0.029907 0.002851 | 0.015317 0.005792 0.000888 |
|||
Body 2 : 0.716377 0.703998 0.214889 | -0.053246 -0.057302 0.011810 |
|||
Body 3 : 0.155406 0.573482 0.539941 | 0.017816 -0.071782 -0.078886 |
|||
Cycle 13 |
|||
Body 1 : 0.164025 0.036157 0.003887 | 0.016079 0.006709 0.001184 |
|||
Body 2 : 0.659310 0.642172 0.225282 | -0.060887 -0.066351 0.008976 |
|||
Body 3 : 0.174112 0.495836 0.454475 | 0.019596 -0.083511 -0.092045 |
|||
Cycle 14 |
|||
Body 1 : 0.180564 0.043437 0.005286 | 0.017000 0.007852 0.001613 |
|||
Body 2 : 0.593807 0.570186 0.232208 | -0.070119 -0.077621 0.004875 |
|||
Body 3 : 0.194929 0.404136 0.353320 | 0.022038 -0.099890 -0.110265 |
|||
Cycle 15 |
|||
Body 1 : 0.198150 0.052049 0.007234 | 0.018171 0.009372 0.002283 |
|||
Body 2 : 0.517817 0.485100 0.233878 | -0.081861 -0.092550 -0.001535 |
|||
Body 3 : 0.218605 0.290860 0.228583 | 0.025314 -0.126661 -0.139210 |
|||
Cycle 16 |
|||
Body 1 : 0.217126 0.062542 0.010117 | 0.019781 0.011614 0.003484 |
|||
Body 2 : 0.427899 0.381659 0.226654 | -0.097974 -0.114332 -0.012913 |
|||
Body 3 : 0.244268 0.131956 0.057562 | 0.026013 -0.191148 -0.202831 |
|||
Cycle 17 |
|||
Body 1 : 0.238346 0.076539 0.015221 | 0.022658 0.016380 0.006723 |
|||
Body 2 : 0.317489 0.248502 0.200967 | -0.122846 -0.151982 -0.038461 |
|||
Body 3 : 0.075592 -0.559591 -0.487315 | -0.363366 -1.191945 -0.886924 |
|||
Cycle 18 |
|||
Body 1 : 0.263123 0.097523 0.026918 | 0.026898 0.025587 0.016672 |
|||
Body 2 : 0.173428 0.050424 0.112716 | -0.165275 -0.244174 -0.138041 |
|||
Body 3 : -0.286241 -1.745597 -1.369528 | -0.360299 -1.180066 -0.877501 |
|||
Cycle 19 |
|||
Body 1 : 0.270854 0.113045 0.061923 | -0.011436 0.005457 0.053339 |
|||
Body 2 : 0.199821 -0.093105 -0.208666 | 0.218061 -0.042882 -0.504723 |
|||
Body 3 : -0.646318 -2.924909 -2.246453 | -0.359856 -1.178559 -0.876350 |
|||
Cycle 20 |
|||
Body 1 : 0.258572 0.116046 0.112038 | -0.013129 0.000544 0.046890 |
|||
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|C++}}== |
=={{header|C++}}== |
||
Line 618: | Line 885: | ||
0.000000 1.000000 1.000000 |
0.000000 1.000000 1.000000 |
||
0.010000 -0.010000 -0.010000 |
0.010000 -0.010000 -0.010000 |
||
Body : x y z | vx vy vz |
|||
Cycle 1 |
|||
Body 1 : 0.010177 0.000179 0.000002 | 0.010354 0.000357 0.000004 |
|||
Body 2 : 0.998230 0.998232 0.020002 | -0.003539 -0.003536 0.020004 |
|||
Body 3 : 0.010177 0.988232 0.988055 | 0.010354 -0.013536 -0.013889 |
|||
Cycle 2 |
|||
Body 1 : 0.020709 0.000718 0.000011 | 0.010710 0.000721 0.000014 |
|||
Body 2 : 0.992907 0.992896 0.039971 | -0.007109 -0.007138 0.019935 |
|||
Body 3 : 0.020717 0.972888 0.972173 | 0.010727 -0.017153 -0.017876 |
|||
Cycle 3 |
|||
Body 1 : 0.031600 0.001625 0.000034 | 0.011072 0.001094 0.000033 |
|||
Body 2 : 0.983985 0.983910 0.059834 | -0.010735 -0.010835 0.019790 |
|||
Body 3 : 0.031643 0.953868 0.952235 | 0.011125 -0.020886 -0.021999 |
|||
Cycle 4 |
|||
Body 1 : 0.042858 0.002913 0.000081 | 0.011443 0.001481 0.000060 |
|||
Body 2 : 0.971393 0.971163 0.079509 | -0.014448 -0.014659 0.019561 |
|||
Body 3 : 0.042981 0.931039 0.928087 | 0.011552 -0.024772 -0.026299 |
|||
Cycle 5 |
|||
Body 1 : 0.054492 0.004595 0.000160 | 0.011826 0.001884 0.000097 |
|||
Body 2 : 0.955030 0.954509 0.098909 | -0.018278 -0.018649 0.019238 |
|||
Body 3 : 0.054766 0.904225 0.899522 | 0.012018 -0.028857 -0.030829 |
|||
Cycle 6 |
|||
Body 1 : 0.066517 0.006691 0.000281 | 0.012224 0.002308 0.000145 |
|||
Body 2 : 0.934759 0.933760 0.117931 | -0.022265 -0.022849 0.018806 |
|||
Body 3 : 0.067040 0.873197 0.866280 | 0.012530 -0.033199 -0.035655 |
|||
Cycle 7 |
|||
Body 1 : 0.078950 0.009225 0.000456 | 0.012642 0.002759 0.000206 |
|||
Body 2 : 0.910400 0.908677 0.136456 | -0.026454 -0.027316 0.018244 |
|||
Body 3 : 0.079856 0.837662 0.828023 | 0.013101 -0.037871 -0.040861 |
|||
Cycle 8 |
|||
Body 1 : 0.091815 0.012227 0.000702 | 0.013086 0.003245 0.000284 |
|||
Body 2 : 0.881722 0.878958 0.154340 | -0.030902 -0.032122 0.017523 |
|||
Body 3 : 0.093281 0.797239 0.784313 | 0.013749 -0.042975 -0.046559 |
|||
Cycle 9 |
|||
Body 1 : 0.105140 0.015737 0.001035 | 0.013564 0.003775 0.000383 |
|||
Body 2 : 0.848429 0.844216 0.171401 | -0.035684 -0.037362 0.016600 |
|||
Body 3 : 0.107405 0.751427 0.734579 | 0.014498 -0.048649 -0.052908 |
|||
Cycle 10 |
|||
Body 1 : 0.118964 0.019805 0.001481 | 0.014085 0.004362 0.000509 |
|||
Body 2 : 0.810137 0.803953 0.187408 | -0.040900 -0.043166 0.015414 |
|||
Body 3 : 0.122346 0.699554 0.678056 | 0.015384 -0.055097 -0.060138 |
|||
Cycle 11 |
|||
Body 1 : 0.133337 0.024498 0.002071 | 0.014662 0.005025 0.000672 |
|||
Body 2 : 0.766343 0.757509 0.202050 | -0.046687 -0.049720 0.013868 |
|||
Body 3 : 0.138268 0.640690 0.613685 | 0.016460 -0.062633 -0.068603 |
|||
Cycle 12 |
|||
Body 1 : 0.148327 0.029907 0.002851 | 0.015317 0.005792 0.000888 |
|||
Body 2 : 0.716377 0.703998 0.214889 | -0.053246 -0.057302 0.011810 |
|||
Body 3 : 0.155406 0.573482 0.539941 | 0.017816 -0.071782 -0.078886 |
|||
Cycle 13 |
|||
Body 1 : 0.164025 0.036157 0.003887 | 0.016079 0.006709 0.001184 |
|||
Body 2 : 0.659310 0.642172 0.225282 | -0.060887 -0.066351 0.008976 |
|||
Body 3 : 0.174112 0.495836 0.454475 | 0.019596 -0.083511 -0.092045 |
|||
Cycle 14 |
|||
Body 1 : 0.180564 0.043437 0.005286 | 0.017000 0.007852 0.001613 |
|||
Body 2 : 0.593807 0.570186 0.232208 | -0.070119 -0.077621 0.004875 |
|||
Body 3 : 0.194929 0.404136 0.353320 | 0.022038 -0.099890 -0.110265 |
|||
Cycle 15 |
|||
Body 1 : 0.198150 0.052049 0.007234 | 0.018171 0.009372 0.002283 |
|||
Body 2 : 0.517817 0.485100 0.233878 | -0.081861 -0.092550 -0.001535 |
|||
Body 3 : 0.218605 0.290860 0.228583 | 0.025314 -0.126661 -0.139210 |
|||
Cycle 16 |
|||
Body 1 : 0.217126 0.062542 0.010117 | 0.019781 0.011614 0.003484 |
|||
Body 2 : 0.427899 0.381659 0.226654 | -0.097974 -0.114332 -0.012913 |
|||
Body 3 : 0.244268 0.131956 0.057562 | 0.026013 -0.191148 -0.202831 |
|||
Cycle 17 |
|||
Body 1 : 0.238346 0.076539 0.015221 | 0.022658 0.016380 0.006723 |
|||
Body 2 : 0.317489 0.248502 0.200967 | -0.122846 -0.151982 -0.038461 |
|||
Body 3 : 0.075592 -0.559591 -0.487315 | -0.363366 -1.191945 -0.886924 |
|||
Cycle 18 |
|||
Body 1 : 0.263123 0.097523 0.026918 | 0.026898 0.025587 0.016672 |
|||
Body 2 : 0.173428 0.050424 0.112716 | -0.165275 -0.244174 -0.138041 |
|||
Body 3 : -0.286241 -1.745597 -1.369528 | -0.360299 -1.180066 -0.877501 |
|||
Cycle 19 |
|||
Body 1 : 0.270854 0.113045 0.061923 | -0.011436 0.005457 0.053339 |
|||
Body 2 : 0.199821 -0.093105 -0.208666 | 0.218061 -0.042882 -0.504723 |
|||
Body 3 : -0.646318 -2.924909 -2.246453 | -0.359856 -1.178559 -0.876350 |
|||
Cycle 20 |
|||
Body 1 : 0.258572 0.116046 0.112038 | -0.013129 0.000544 0.046890 |
|||
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|C#|C sharp}}== |
|||
{{trans|D}} |
|||
<lang csharp>using System; |
|||
using System.IO; |
|||
namespace NBodyProblem { |
|||
class Vector3D { |
|||
public Vector3D(double x, double y, double z) { |
|||
X = x; |
|||
Y = y; |
|||
Z = z; |
|||
} |
|||
public double X { get; } |
|||
public double Y { get; } |
|||
public double Z { get; } |
|||
public double Mod() { |
|||
return Math.Sqrt(X * X + Y * Y + Z * Z); |
|||
} |
|||
public static Vector3D operator +(Vector3D lhs, Vector3D rhs) { |
|||
return new Vector3D(lhs.X + rhs.X, lhs.Y + rhs.Y, lhs.Z + rhs.Z); |
|||
} |
|||
public static Vector3D operator -(Vector3D lhs, Vector3D rhs) { |
|||
return new Vector3D(lhs.X - rhs.X, lhs.Y - rhs.Y, lhs.Z - rhs.Z); |
|||
} |
|||
public static Vector3D operator *(Vector3D lhs, double rhs) { |
|||
return new Vector3D(lhs.X * rhs, lhs.Y * rhs, lhs.Z * rhs); |
|||
} |
|||
} |
|||
class NBody { |
|||
private readonly double gc; |
|||
private readonly int bodies; |
|||
private readonly int timeSteps; |
|||
private readonly double[] masses; |
|||
private readonly Vector3D[] positions; |
|||
private readonly Vector3D[] velocities; |
|||
private readonly Vector3D[] accelerations; |
|||
public NBody(string fileName) { |
|||
string[] lines = File.ReadAllLines(fileName); |
|||
string[] gbt = lines[0].Split(); |
|||
gc = double.Parse(gbt[0]); |
|||
bodies = int.Parse(gbt[1]); |
|||
timeSteps = int.Parse(gbt[2]); |
|||
masses = new double[bodies]; |
|||
positions = new Vector3D[bodies]; |
|||
velocities = new Vector3D[bodies]; |
|||
accelerations = new Vector3D[bodies]; |
|||
for (int i = 0; i < bodies; ++i) { |
|||
masses[i] = double.Parse(lines[i * 3 + 1]); |
|||
positions[i] = Decompose(lines[i * 3 + 2]); |
|||
velocities[i] = Decompose(lines[i * 3 + 3]); |
|||
} |
|||
Console.WriteLine("Contents of {0}", fileName); |
|||
foreach (string line in lines) { |
|||
Console.WriteLine(line); |
|||
} |
|||
Console.WriteLine(); |
|||
Console.Write("Body : x y z |"); |
|||
Console.WriteLine(" vx vy vz"); |
|||
} |
|||
public int GetTimeSteps() { |
|||
return timeSteps; |
|||
} |
|||
private Vector3D Decompose(string line) { |
|||
string[] xyz = line.Split(); |
|||
double x = double.Parse(xyz[0]); |
|||
double y = double.Parse(xyz[1]); |
|||
double z = double.Parse(xyz[2]); |
|||
return new Vector3D(x, y, z); |
|||
} |
|||
private void ComputeAccelerations() { |
|||
for (int i = 0; i < bodies; ++i) { |
|||
accelerations[i] = new Vector3D(0, 0, 0); |
|||
for (int j = 0; j < bodies; ++j) { |
|||
if (i != j) { |
|||
double temp = gc * masses[j] / Math.Pow((positions[i] - positions[j]).Mod(), 3); |
|||
accelerations[i] = accelerations[i] + (positions[j] - positions[i]) * temp; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
private void ComputeVelocities() { |
|||
for (int i = 0; i < bodies; ++i) { |
|||
velocities[i] = velocities[i] + accelerations[i]; |
|||
} |
|||
} |
|||
private void ComputePositions() { |
|||
for (int i = 0; i < bodies; ++i) { |
|||
positions[i] = positions[i] + velocities[i] + accelerations[i] * 0.5; |
|||
} |
|||
} |
|||
private void ResolveCollisions() { |
|||
for (int i = 0; i < bodies; ++i) { |
|||
for (int j = i + 1; j < bodies; ++j) { |
|||
if (positions[i].X == positions[j].X |
|||
&& positions[i].Y == positions[j].Y |
|||
&& positions[i].Z == positions[j].Z) { |
|||
Vector3D temp = velocities[i]; |
|||
velocities[i] = velocities[j]; |
|||
velocities[j] = temp; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
public void Simulate() { |
|||
ComputeAccelerations(); |
|||
ComputePositions(); |
|||
ComputeVelocities(); |
|||
ResolveCollisions(); |
|||
} |
|||
public void PrintResults() { |
|||
for (int i = 0; i < bodies; ++i) { |
|||
Console.WriteLine( |
|||
"Body {0} : {1,9:F6} {2,9:F6} {3,9:F6} | {4,9:F6} {5,9:F6} {6,9:F6}", |
|||
i + 1, |
|||
positions[i].X, positions[i].Y, positions[i].Z, |
|||
velocities[i].X, velocities[i].Y, velocities[i].Z |
|||
); |
|||
} |
|||
} |
|||
} |
|||
class Program { |
|||
static void Main(string[] args) { |
|||
NBody nb = new NBody("nbody.txt"); |
|||
for (int i = 0; i < nb.GetTimeSteps(); ++i) { |
|||
Console.WriteLine(); |
|||
Console.WriteLine("Cycle {0}", i + 1); |
|||
nb.Simulate(); |
|||
nb.PrintResults(); |
|||
} |
|||
} |
|||
} |
|||
}</lang> |
|||
{{out}} |
|||
<pre>Contents of nbody.txt |
|||
0.01 3 20 |
|||
1 |
|||
0 0 0 |
|||
0.01 0 0 |
|||
0.1 |
|||
1 1 0 |
|||
0 0 0.02 |
|||
0.001 |
|||
0 1 1 |
|||
0.01 -0.01 -0.01 |
|||
Body : x y z | vx vy vz |
Body : x y z | vx vy vz |
||
Line 4,635: | Line 4,635: | ||
16000 -4.70 2.63 -9.52 -1.06 1.54 -19.34 9.51 -28.67 |
16000 -4.70 2.63 -9.52 -1.06 1.54 -19.34 9.51 -28.67 |
||
16567 3.45 -3.74 -3.24 -9.52 9.24 -17.42 15.38 -25.92</pre> |
16567 3.45 -3.74 -3.24 -9.52 9.24 -17.42 15.38 -25.92</pre> |
||
=={{header|Perl 6}}== |
|||
We'll try to simulate the Sun+Earth+Moon system, with plausible astronomical values. |
|||
We use a 18-dimension vector <math>ABC</math>. The first nine dimensions are the positions of the three bodies. The other nine are the velocities. This allows us to write the dynamics as a first-temporal derivative equation, since |
|||
<math>\frac{d\mathrm{position}}{dt} = \mathrm{speed}</math> |
|||
and thus |
|||
<math>\frac{dABC_{1..9}}{dt} = ABC_{10..18}</math> |
|||
To keep things compact, we'll only display the first 20 lines of output. |
|||
<lang perl6># Simple Vector implementation |
|||
multi infix:<+>(@a, @b) { @a Z+ @b } |
|||
multi infix:<->(@a, @b) { @a Z- @b } |
|||
multi infix:<*>($r, @a) { $r X* @a } |
|||
multi infix:</>(@a, $r) { @a X/ $r } |
|||
sub norm { sqrt [+] @_ X** 2 } |
|||
# Runge-Kutta stuff |
|||
sub runge-kutta(&yp) { |
|||
return -> \t, \y, \δt { |
|||
my $a = δt * yp( t, y ); |
|||
my $b = δt * yp( t + δt/2, y + $a/2 ); |
|||
my $c = δt * yp( t + δt/2, y + $b/2 ); |
|||
my $d = δt * yp( t + δt, y + $c ); |
|||
($a + 2*($b + $c) + $d) / 6; |
|||
} |
|||
} |
|||
# gravitational constant |
|||
constant G = 6.674e-11; |
|||
# astronomical unit |
|||
constant au = 150e9; |
|||
# time constants in seconds |
|||
constant year = 365.25*24*60*60; |
|||
constant month = 21*24*60*60; |
|||
# masses in kg |
|||
constant $ma = 2e30; # Sun |
|||
constant $mb = 6e24; # Earth |
|||
constant $mc = 7.34e22; # Moon |
|||
my &dABC = runge-kutta my &f = sub ( $t, @ABC ) { |
|||
my @a = @ABC[0..2]; |
|||
my @b = @ABC[3..5]; |
|||
my @c = @ABC[6..8]; |
|||
my $ab = norm(@a - @b); |
|||
my $ac = norm(@a - @c); |
|||
my $bc = norm(@b - @c); |
|||
return [ |
|||
flat |
|||
@ABC[@(9..17)], |
|||
map G * *, |
|||
$mb/$ab**3 * (@b - @a) + $mc/$ac**3 * (@c - @a), |
|||
$ma/$ab**3 * (@a - @b) + $mc/$bc**3 * (@c - @b), |
|||
$ma/$ac**3 * (@a - @c) + $mb/$bc**3 * (@b - @c); |
|||
]; |
|||
} |
|||
loop ( |
|||
my ($t, @ABC) = 0, |
|||
0, 0, 0, # Sun position |
|||
au, 0, 0, # Earth position |
|||
0.998*au, 0, 0, # Moon position |
|||
0, 0, 0, # Sun speed |
|||
0, 2*pi*au/year, 0, # Earth speed |
|||
0, 2*pi*(au/year + 0.002*au/month), 0 # Moon speed |
|||
; |
|||
$t < .2; |
|||
($t, @ABC) »+=« (.01, dABC($t, @ABC, .01)) |
|||
) { |
|||
printf "t = %.02f : %s\n", $t, @ABC.fmt("%+.3e"); |
|||
}</lang> |
|||
{{out}} |
|||
<pre>t = 0.00 : +0.000e+00 +0.000e+00 +0.000e+00 +1.500e+11 +0.000e+00 +0.000e+00 +1.497e+11 +0.000e+00 +0.000e+00 +0.000e+00 +0.000e+00 +0.000e+00 +0.000e+00 +2.987e+04 +0.000e+00 +0.000e+00 +3.090e+04 +0.000e+00 |
|||
t = 0.01 : +9.008e-13 +5.981e-22 +0.000e+00 +1.500e+11 +2.987e+02 +0.000e+00 +1.497e+11 +3.090e+02 +0.000e+00 +1.802e-10 +1.794e-19 +0.000e+00 -5.987e-05 +2.987e+04 +0.000e+00 -1.507e-05 +3.090e+04 +0.000e+00 |
|||
t = 0.02 : +3.603e-12 +4.785e-21 +0.000e+00 +1.500e+11 +5.973e+02 +0.000e+00 +1.497e+11 +6.181e+02 +0.000e+00 +3.603e-10 +7.177e-19 +0.000e+00 -1.197e-04 +2.987e+04 +0.000e+00 -3.014e-05 +3.090e+04 +0.000e+00 |
|||
t = 0.03 : +8.107e-12 +1.615e-20 +0.000e+00 +1.500e+11 +8.960e+02 +0.000e+00 +1.497e+11 +9.271e+02 +0.000e+00 +5.405e-10 +1.615e-18 +0.000e+00 -1.796e-04 +2.987e+04 +0.000e+00 -4.521e-05 +3.090e+04 +0.000e+00 |
|||
t = 0.04 : +1.441e-11 +3.828e-20 +0.000e+00 +1.500e+11 +1.195e+03 +0.000e+00 +1.497e+11 +1.236e+03 +0.000e+00 +7.206e-10 +2.871e-18 +0.000e+00 -2.395e-04 +2.987e+04 +0.000e+00 -6.028e-05 +3.090e+04 +0.000e+00 |
|||
t = 0.05 : +2.252e-11 +7.476e-20 +0.000e+00 +1.500e+11 +1.493e+03 +0.000e+00 +1.497e+11 +1.545e+03 +0.000e+00 +9.008e-10 +4.486e-18 +0.000e+00 -2.993e-04 +2.987e+04 +0.000e+00 -7.535e-05 +3.090e+04 +0.000e+00 |
|||
t = 0.06 : +3.243e-11 +1.292e-19 +0.000e+00 +1.500e+11 +1.792e+03 +0.000e+00 +1.497e+11 +1.854e+03 +0.000e+00 +1.081e-09 +6.460e-18 +0.000e+00 -3.592e-04 +2.987e+04 +0.000e+00 -9.041e-05 +3.090e+04 +0.000e+00 |
|||
t = 0.07 : +4.414e-11 +2.051e-19 +0.000e+00 +1.500e+11 +2.091e+03 +0.000e+00 +1.497e+11 +2.163e+03 +0.000e+00 +1.261e-09 +8.792e-18 +0.000e+00 -4.191e-04 +2.987e+04 +0.000e+00 -1.055e-04 +3.090e+04 +0.000e+00 |
|||
t = 0.08 : +5.765e-11 +3.062e-19 +0.000e+00 +1.500e+11 +2.389e+03 +0.000e+00 +1.497e+11 +2.472e+03 +0.000e+00 +1.441e-09 +1.148e-17 +0.000e+00 -4.789e-04 +2.987e+04 +0.000e+00 -1.206e-04 +3.090e+04 +0.000e+00 |
|||
t = 0.09 : +7.296e-11 +4.360e-19 +0.000e+00 +1.500e+11 +2.688e+03 +0.000e+00 +1.497e+11 +2.781e+03 +0.000e+00 +1.621e-09 +1.453e-17 +0.000e+00 -5.388e-04 +2.987e+04 +0.000e+00 -1.356e-04 +3.090e+04 +0.000e+00 |
|||
t = 0.10 : +9.008e-11 +5.981e-19 +0.000e+00 +1.500e+11 +2.987e+03 +0.000e+00 +1.497e+11 +3.090e+03 +0.000e+00 +1.802e-09 +1.794e-17 +0.000e+00 -5.987e-04 +2.987e+04 +0.000e+00 -1.507e-04 +3.090e+04 +0.000e+00 |
|||
t = 0.11 : +1.090e-10 +7.961e-19 +0.000e+00 +1.500e+11 +3.285e+03 +0.000e+00 +1.497e+11 +3.399e+03 +0.000e+00 +1.982e-09 +2.171e-17 +0.000e+00 -6.586e-04 +2.987e+04 +0.000e+00 -1.658e-04 +3.090e+04 +0.000e+00 |
|||
t = 0.12 : +1.297e-10 +1.034e-18 +0.000e+00 +1.500e+11 +3.584e+03 +0.000e+00 +1.497e+11 +3.709e+03 +0.000e+00 +2.162e-09 +2.584e-17 +0.000e+00 -7.184e-04 +2.987e+04 +0.000e+00 -1.808e-04 +3.090e+04 +0.000e+00 |
|||
t = 0.13 : +1.522e-10 +1.314e-18 +0.000e+00 +1.500e+11 +3.882e+03 +0.000e+00 +1.497e+11 +4.018e+03 +0.000e+00 +2.342e-09 +3.032e-17 +0.000e+00 -7.783e-04 +2.987e+04 +0.000e+00 -1.959e-04 +3.090e+04 +0.000e+00 |
|||
t = 0.14 : +1.766e-10 +1.641e-18 +0.000e+00 +1.500e+11 +4.181e+03 +0.000e+00 +1.497e+11 +4.327e+03 +0.000e+00 +2.522e-09 +3.517e-17 +0.000e+00 -8.382e-04 +2.987e+04 +0.000e+00 -2.110e-04 +3.090e+04 +0.000e+00 |
|||
t = 0.15 : +2.027e-10 +2.019e-18 +0.000e+00 +1.500e+11 +4.480e+03 +0.000e+00 +1.497e+11 +4.636e+03 +0.000e+00 +2.702e-09 +4.037e-17 +0.000e+00 -8.980e-04 +2.987e+04 +0.000e+00 -2.260e-04 +3.090e+04 +0.000e+00 |
|||
t = 0.16 : +2.306e-10 +2.450e-18 +0.000e+00 +1.500e+11 +4.778e+03 +0.000e+00 +1.497e+11 +4.945e+03 +0.000e+00 +2.883e-09 +4.593e-17 +0.000e+00 -9.579e-04 +2.987e+04 +0.000e+00 -2.411e-04 +3.090e+04 +0.000e+00 |
|||
t = 0.17 : +2.603e-10 +2.938e-18 +0.000e+00 +1.500e+11 +5.077e+03 +0.000e+00 +1.497e+11 +5.254e+03 +0.000e+00 +3.063e-09 +5.186e-17 +0.000e+00 -1.018e-03 +2.987e+04 +0.000e+00 -2.562e-04 +3.090e+04 +0.000e+00 |
|||
t = 0.18 : +2.919e-10 +3.488e-18 +0.000e+00 +1.500e+11 +5.376e+03 +0.000e+00 +1.497e+11 +5.563e+03 +0.000e+00 +3.243e-09 +5.814e-17 +0.000e+00 -1.078e-03 +2.987e+04 +0.000e+00 -2.712e-04 +3.090e+04 +0.000e+00 |
|||
t = 0.19 : +3.252e-10 +4.102e-18 +0.000e+00 +1.500e+11 +5.674e+03 +0.000e+00 +1.497e+11 +5.872e+03 +0.000e+00 +3.423e-09 +6.477e-17 +0.000e+00 -1.138e-03 +2.987e+04 +0.000e+00 -2.863e-04 +3.090e+04 +0.000e+00</pre> |
|||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
Line 5,048: | Line 4,947: | ||
Body 2 : 0.426346 -0.111425 -0.681150 | 0.234987 0.006241 -0.440245 |
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> |
Body 3 : -1.006089 -4.103186 -3.122591 | -0.359686 -1.177995 -0.875924</pre> |
||
=={{header|Raku}}== |
|||
(formerly Perl 6) |
|||
We'll try to simulate the Sun+Earth+Moon system, with plausible astronomical values. |
|||
We use a 18-dimension vector <math>ABC</math>. The first nine dimensions are the positions of the three bodies. The other nine are the velocities. This allows us to write the dynamics as a first-temporal derivative equation, since |
|||
<math>\frac{d\mathrm{position}}{dt} = \mathrm{speed}</math> |
|||
and thus |
|||
<math>\frac{dABC_{1..9}}{dt} = ABC_{10..18}</math> |
|||
To keep things compact, we'll only display the first 20 lines of output. |
|||
<lang perl6># Simple Vector implementation |
|||
multi infix:<+>(@a, @b) { @a Z+ @b } |
|||
multi infix:<->(@a, @b) { @a Z- @b } |
|||
multi infix:<*>($r, @a) { $r X* @a } |
|||
multi infix:</>(@a, $r) { @a X/ $r } |
|||
sub norm { sqrt [+] @_ X** 2 } |
|||
# Runge-Kutta stuff |
|||
sub runge-kutta(&yp) { |
|||
return -> \t, \y, \δt { |
|||
my $a = δt * yp( t, y ); |
|||
my $b = δt * yp( t + δt/2, y + $a/2 ); |
|||
my $c = δt * yp( t + δt/2, y + $b/2 ); |
|||
my $d = δt * yp( t + δt, y + $c ); |
|||
($a + 2*($b + $c) + $d) / 6; |
|||
} |
|||
} |
|||
# gravitational constant |
|||
constant G = 6.674e-11; |
|||
# astronomical unit |
|||
constant au = 150e9; |
|||
# time constants in seconds |
|||
constant year = 365.25*24*60*60; |
|||
constant month = 21*24*60*60; |
|||
# masses in kg |
|||
constant $ma = 2e30; # Sun |
|||
constant $mb = 6e24; # Earth |
|||
constant $mc = 7.34e22; # Moon |
|||
my &dABC = runge-kutta my &f = sub ( $t, @ABC ) { |
|||
my @a = @ABC[0..2]; |
|||
my @b = @ABC[3..5]; |
|||
my @c = @ABC[6..8]; |
|||
my $ab = norm(@a - @b); |
|||
my $ac = norm(@a - @c); |
|||
my $bc = norm(@b - @c); |
|||
return [ |
|||
flat |
|||
@ABC[@(9..17)], |
|||
map G * *, |
|||
$mb/$ab**3 * (@b - @a) + $mc/$ac**3 * (@c - @a), |
|||
$ma/$ab**3 * (@a - @b) + $mc/$bc**3 * (@c - @b), |
|||
$ma/$ac**3 * (@a - @c) + $mb/$bc**3 * (@b - @c); |
|||
]; |
|||
} |
|||
loop ( |
|||
my ($t, @ABC) = 0, |
|||
0, 0, 0, # Sun position |
|||
au, 0, 0, # Earth position |
|||
0.998*au, 0, 0, # Moon position |
|||
0, 0, 0, # Sun speed |
|||
0, 2*pi*au/year, 0, # Earth speed |
|||
0, 2*pi*(au/year + 0.002*au/month), 0 # Moon speed |
|||
; |
|||
$t < .2; |
|||
($t, @ABC) »+=« (.01, dABC($t, @ABC, .01)) |
|||
) { |
|||
printf "t = %.02f : %s\n", $t, @ABC.fmt("%+.3e"); |
|||
}</lang> |
|||
{{out}} |
|||
<pre>t = 0.00 : +0.000e+00 +0.000e+00 +0.000e+00 +1.500e+11 +0.000e+00 +0.000e+00 +1.497e+11 +0.000e+00 +0.000e+00 +0.000e+00 +0.000e+00 +0.000e+00 +0.000e+00 +2.987e+04 +0.000e+00 +0.000e+00 +3.090e+04 +0.000e+00 |
|||
t = 0.01 : +9.008e-13 +5.981e-22 +0.000e+00 +1.500e+11 +2.987e+02 +0.000e+00 +1.497e+11 +3.090e+02 +0.000e+00 +1.802e-10 +1.794e-19 +0.000e+00 -5.987e-05 +2.987e+04 +0.000e+00 -1.507e-05 +3.090e+04 +0.000e+00 |
|||
t = 0.02 : +3.603e-12 +4.785e-21 +0.000e+00 +1.500e+11 +5.973e+02 +0.000e+00 +1.497e+11 +6.181e+02 +0.000e+00 +3.603e-10 +7.177e-19 +0.000e+00 -1.197e-04 +2.987e+04 +0.000e+00 -3.014e-05 +3.090e+04 +0.000e+00 |
|||
t = 0.03 : +8.107e-12 +1.615e-20 +0.000e+00 +1.500e+11 +8.960e+02 +0.000e+00 +1.497e+11 +9.271e+02 +0.000e+00 +5.405e-10 +1.615e-18 +0.000e+00 -1.796e-04 +2.987e+04 +0.000e+00 -4.521e-05 +3.090e+04 +0.000e+00 |
|||
t = 0.04 : +1.441e-11 +3.828e-20 +0.000e+00 +1.500e+11 +1.195e+03 +0.000e+00 +1.497e+11 +1.236e+03 +0.000e+00 +7.206e-10 +2.871e-18 +0.000e+00 -2.395e-04 +2.987e+04 +0.000e+00 -6.028e-05 +3.090e+04 +0.000e+00 |
|||
t = 0.05 : +2.252e-11 +7.476e-20 +0.000e+00 +1.500e+11 +1.493e+03 +0.000e+00 +1.497e+11 +1.545e+03 +0.000e+00 +9.008e-10 +4.486e-18 +0.000e+00 -2.993e-04 +2.987e+04 +0.000e+00 -7.535e-05 +3.090e+04 +0.000e+00 |
|||
t = 0.06 : +3.243e-11 +1.292e-19 +0.000e+00 +1.500e+11 +1.792e+03 +0.000e+00 +1.497e+11 +1.854e+03 +0.000e+00 +1.081e-09 +6.460e-18 +0.000e+00 -3.592e-04 +2.987e+04 +0.000e+00 -9.041e-05 +3.090e+04 +0.000e+00 |
|||
t = 0.07 : +4.414e-11 +2.051e-19 +0.000e+00 +1.500e+11 +2.091e+03 +0.000e+00 +1.497e+11 +2.163e+03 +0.000e+00 +1.261e-09 +8.792e-18 +0.000e+00 -4.191e-04 +2.987e+04 +0.000e+00 -1.055e-04 +3.090e+04 +0.000e+00 |
|||
t = 0.08 : +5.765e-11 +3.062e-19 +0.000e+00 +1.500e+11 +2.389e+03 +0.000e+00 +1.497e+11 +2.472e+03 +0.000e+00 +1.441e-09 +1.148e-17 +0.000e+00 -4.789e-04 +2.987e+04 +0.000e+00 -1.206e-04 +3.090e+04 +0.000e+00 |
|||
t = 0.09 : +7.296e-11 +4.360e-19 +0.000e+00 +1.500e+11 +2.688e+03 +0.000e+00 +1.497e+11 +2.781e+03 +0.000e+00 +1.621e-09 +1.453e-17 +0.000e+00 -5.388e-04 +2.987e+04 +0.000e+00 -1.356e-04 +3.090e+04 +0.000e+00 |
|||
t = 0.10 : +9.008e-11 +5.981e-19 +0.000e+00 +1.500e+11 +2.987e+03 +0.000e+00 +1.497e+11 +3.090e+03 +0.000e+00 +1.802e-09 +1.794e-17 +0.000e+00 -5.987e-04 +2.987e+04 +0.000e+00 -1.507e-04 +3.090e+04 +0.000e+00 |
|||
t = 0.11 : +1.090e-10 +7.961e-19 +0.000e+00 +1.500e+11 +3.285e+03 +0.000e+00 +1.497e+11 +3.399e+03 +0.000e+00 +1.982e-09 +2.171e-17 +0.000e+00 -6.586e-04 +2.987e+04 +0.000e+00 -1.658e-04 +3.090e+04 +0.000e+00 |
|||
t = 0.12 : +1.297e-10 +1.034e-18 +0.000e+00 +1.500e+11 +3.584e+03 +0.000e+00 +1.497e+11 +3.709e+03 +0.000e+00 +2.162e-09 +2.584e-17 +0.000e+00 -7.184e-04 +2.987e+04 +0.000e+00 -1.808e-04 +3.090e+04 +0.000e+00 |
|||
t = 0.13 : +1.522e-10 +1.314e-18 +0.000e+00 +1.500e+11 +3.882e+03 +0.000e+00 +1.497e+11 +4.018e+03 +0.000e+00 +2.342e-09 +3.032e-17 +0.000e+00 -7.783e-04 +2.987e+04 +0.000e+00 -1.959e-04 +3.090e+04 +0.000e+00 |
|||
t = 0.14 : +1.766e-10 +1.641e-18 +0.000e+00 +1.500e+11 +4.181e+03 +0.000e+00 +1.497e+11 +4.327e+03 +0.000e+00 +2.522e-09 +3.517e-17 +0.000e+00 -8.382e-04 +2.987e+04 +0.000e+00 -2.110e-04 +3.090e+04 +0.000e+00 |
|||
t = 0.15 : +2.027e-10 +2.019e-18 +0.000e+00 +1.500e+11 +4.480e+03 +0.000e+00 +1.497e+11 +4.636e+03 +0.000e+00 +2.702e-09 +4.037e-17 +0.000e+00 -8.980e-04 +2.987e+04 +0.000e+00 -2.260e-04 +3.090e+04 +0.000e+00 |
|||
t = 0.16 : +2.306e-10 +2.450e-18 +0.000e+00 +1.500e+11 +4.778e+03 +0.000e+00 +1.497e+11 +4.945e+03 +0.000e+00 +2.883e-09 +4.593e-17 +0.000e+00 -9.579e-04 +2.987e+04 +0.000e+00 -2.411e-04 +3.090e+04 +0.000e+00 |
|||
t = 0.17 : +2.603e-10 +2.938e-18 +0.000e+00 +1.500e+11 +5.077e+03 +0.000e+00 +1.497e+11 +5.254e+03 +0.000e+00 +3.063e-09 +5.186e-17 +0.000e+00 -1.018e-03 +2.987e+04 +0.000e+00 -2.562e-04 +3.090e+04 +0.000e+00 |
|||
t = 0.18 : +2.919e-10 +3.488e-18 +0.000e+00 +1.500e+11 +5.376e+03 +0.000e+00 +1.497e+11 +5.563e+03 +0.000e+00 +3.243e-09 +5.814e-17 +0.000e+00 -1.078e-03 +2.987e+04 +0.000e+00 -2.712e-04 +3.090e+04 +0.000e+00 |
|||
t = 0.19 : +3.252e-10 +4.102e-18 +0.000e+00 +1.500e+11 +5.674e+03 +0.000e+00 +1.497e+11 +5.872e+03 +0.000e+00 +3.423e-09 +6.477e-17 +0.000e+00 -1.138e-03 +2.987e+04 +0.000e+00 -2.863e-04 +3.090e+04 +0.000e+00</pre> |
|||
=={{header|Swift}}== |
=={{header|Swift}}== |