I am wanting to pull multiple pieces of data from a while loop and put it in a list. The example I have added below is a table with inputted data that I found. Im pretty sure the syntax is unrelated to Mathematica, but it gives you an idea of how I want to display it once I run all of my simulations. For mine I want it to display the following along the top similar to the example.
- Planet
- Mass
- Perihelion (Distance/ Velocity)
- Aphelion (Distance/Velocity)
- Semimajor Axis
- Sidereal Orbit period
- Orbit eccentricity
- Mean orbital velocity
From my simulation, I am obtaining the distance and velocity of the aphelion and the sidereal period from the While loop and I want to extract that data so that I can insert it into a table.
I didn't know how to give just example to where it made sense, but I have uploaded my mathematica sheet as a pdf here and the notebook here.
EDIT
Clear["Global`*"];
mSun = 1.98855*10^30; (* Mass of Sun, kg *)
G = 6.67384*10^-11; (*Universal Gravitational Constant,N m^2 kg^-2*)
(* Create list of planet names *)
planets = {"Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune"};
(* Create list of planet masses *)
mass = {0.3301, 4.8676, 5.9726, 0.64174, 1898.3, 568.36, 86.816, 102.42};
mass = 10^24*mass;
Print["EARTH"]; (* EARTH *)
vini = {0., 30.29*10^3}; (* Initial Velocity of Earth{x, y} , m/s *)
Print["vini= " , vini];
rini = {147.09*10^9, 0.}; (* Initial Position of Earth {x, y}, m *)
Print["rini= " , rini]; (* copy rini \[Rule] rc, vini \[Rule] vc, where 'c' means "current" *)
rc = rini; vc = vini;
(* time in s *)
\[CapitalDelta]t = 60.;
t = 0;
f = 0;
i = 0;
KeepGoing = True;
nsp = 10000;
While[KeepGoing,
{
t = t + \[CapitalDelta]t;
i = i + 1;
fold = f;
If[Mod[i, nsp] == 0,
Print["\nstep = ", i, ", time = ", t, " s = ", t/60., " min = ", t/
3600., " h = ", t/86400., " days"]];
(* update rn, where 'n' means "new" *)
rn = rc + vc*\[CapitalDelta]t;
If[Mod[i, nsp] == 0, Print["\trn = ", rn, ", |rn| = ", Norm[rn]]];
(* update v *)
vn = vc - (G*mSun)/Norm[rc]^3*rc*\[CapitalDelta]t;
(* print *)
If[Mod[i, nsp] == 0, Print["\tvn = ", vn, " |vMn| = ", Norm[vn]]];
(* copy vn \[Rule] vc and rn \[Rule] rc *)
rc = rn; vc = vn;
(* calculate true anomaly *)
polar = ToPolarCoordinates[rc];
f = polar[[2]]/Degree;
If[Mod[i, nsp] == 0, Print["\tf (true anomaly) = ", f, "\[Degree]"]];
If[fold < 0 && f >= 0, {KeepGoing = False;
Print["\nNOW WILL STOP - f changed from - to +"]}];
If[Abs[Abs[f] - 180.] <= 0.005 || ! KeepGoing,
{
Print[
"\n\tTrue anomaly is close to 180\[Degree] or completed full \
orbit, f = ", f, "\[Degree]"];
Print["\tstep = ", i, ", time = ", t, " s = ", t/60., " min = ",
t/3600., " h = ", t/86400., " days"];
Print["\trn = ", rn, ", |rMn| = ", Norm[rn]*10^-3*10^-6,
"\[Times]\!\(\*SuperscriptBox[\(10\), \(6\)]\) km"];
Print["\tvn = ", vn, " |vMn| = ", Norm[vn]*10^-3, " km/s"]
}];
}
]

Sow/Reap. Thanks for providing a background but could you create a toy example to mimic your procedure and the result you would like to get? – Kuba Apr 17 '18 at 07:55