I have written a program in C which solves a particular 2-body problem and then saves the results in two separate .txt files, “results1.txt” and “results2.txt”. The results in each file are rows of four numbers, where the first number of each row represents an instant of time and has the same value in both .txt’s, while the rest three numbers are the spatial coordinates. I want to import those results in Mathematica and make an animated 3D-plot of the motion.
What is a good format for the data written to the files? I want Mathematica to recognize them as arrays of numbers. For the moment, each row has the form {t, x, y, z}, where t, x, y, z are floating-point numbers.
How should I write the call to
Import
in order to be able to get the results in Mathematica? I triedImport[“results1.txt”, ”List”]
and I could extract each one of the rows using
Part
, but then I cannot extract the numbers of each array.Here is what I want to do, For each imported row, to combine them into list with three elements, where the first is the time and the other two are three-number lists, representing the position of each particle.
For example, I want to take
{t, x1, y1, z1}
(imported from results1.txt) and{t, x2, y2, z2}
(imported from results2.txt) and turn them to an list of the form{t, {x1, y1, x1}, {x2, y2, z2}}
.When I have a list of all those
{t, {x1, y1, x1}, {x2, y2, z2}}
, how can I make an animated 3-D plot which, for each t, show the position of both particles?
"Table"
inImport
. Tab-separated?"TSV"
. Comma-separated?"CSV"
. These are useful formats supported by many systems, not just Mathematica. $\endgroup${1.2e5, 2.3}
isn't valid Mathematica code, but1.25e5 2.3
can be imported as"Table"
. $\endgroup$Manipulate
(cf. manipulate)? Or just useAnimate
orListAnimate
, or export a GIF? $\endgroup$