Export to text file [duplicate]

I would like to export a long Table of (complex) numbers to a text file using Export["file.txt",%];

A sample line from the obtained file looks like this:

{0.1128837891684689055999999999918.05263157894737, {{1.6974001229071336*^-12, -5.163757820258834*^-15 + 1.9829374389565386*^-13*I}, {-5.163757820258834*^-15 - 1.9829374389565386*^-13*I, 3.1517458450250055*^-13}}}


First, I do not understand where the 18.05263157894737 comes from. It does not appear in the Mathematica file. How can I get rid of it? Then I would prefer a formatting of the number s like 1.6974001229071336e12 instead of 1.6974001229071336*^-12. The ultimate purpose is import in Maple. So if there is such an export feature it would be welcome too. Note that I need at least 18 digits precision.

The 18.0526315789473 indicates that the preceding number is an arbitrary precision (versus machine precision) number with a precision of 18.0526315789473. To get rid of it, you can convert your data to machine precision with N.

Borrowing from the answers linked to by R.M., you might be looking for something like this:

data = {0.1128837891684689055999999999918.05263157894737, \
{{1.6974001229071336*^-12, -5.163757820258834*^-15 +
1.9829374389565386*^-13*I}, {-5.163757820258834*^-15 -
1.9829374389565386*^-13*I, 3.1517458450250055*^-13}}};

newdata =
FlattenAt[
Map[ToString@
ScientificForm[#, Round@MachinePrecision,
NumberFormat -> (#1 <> "e" <> #3 &)] &, N@data, {-1}], 2]

(* Out:
{"1.128837891684689e-1", {"1.697400122907133e-12",
"-5.163757820258832e-15 + 1.982937438956539e-13 I"}, \
{"-5.163757820258832e-15 - 1.982937438956539e-13 I",
"3.151745845025005e-13"}}
*)

Export["file.txt", newdata, "Table"];
FilePrint@%

(* Out:
1.128837891684689e-1
1.697400122907133e-12   -5.163757820258832e-15 + 1.982937438956539e-13 I
-5.163757820258832e-15 - 1.982937438956539e-13 I    3.151745845025005e-13
*)


I'm assuming that you were looking for a true plain-text tabular format (i.e. without the curly brackets in your question's example). I'm not sure what Maple needs for acceptable input, so you might want to modify this.

Maybe you could map FortranForm to the numbers of the list:

Clear[trans]
trans[x_?NumericQ] := FortranForm[x]
trans[x_] := x

list = {0.1128837891684689055999999999918.05263157894737, \
{{1.6974001229071336*^-12, -5.163757820258834*^-15 +
1.9829374389565386*^-13*I}, {-5.163757820258834*^-15 -
1.9829374389565386*^-13*I, 3.1517458450250055*^-13}}};

export=trans//@list

Export["file.txt, export]


then the exported file looks like this (copied from »less«):

0.112883789168468906 {{1.6974001229071336e-12, (-5.163757820258834e-15,1.9829374389565386e-13)}, {(-5.163757820258834e-15,-1.9829374389565386e-13), 3.1517458450250055e-13}}

These are two rows in the original file.

You can use Chop to reformat this data for Export. Mathematica is showing the full accuracy of the number, which is probably beyond what you expect.

 in(3)= pts = Chop[{0.1128837891684689055999999999918.05263157894737, \
{{1.6974001229071336*^-12, -5.163757820258834*^-15 +
1.9829374389565386*^-13*I}, {-5.163757820258834*^-15 -
1.9829374389565386*^-13*I, 3.1517458450250055*^-13}}}]

out(3)= {0.112883789168468906, {{0, 0}, {0, 0}}}

• Thanks, but no, thats not what I want! I like to have the full precission (or at least 18 digits) in all numbers but I do not want the `18.05263157894737 and the ^ because Maple does not understand what it means. – highsciguy Jun 3 '12 at 20:45
• Why don't you do all the calculations in Maple? – rm -rf Jun 3 '12 at 20:46
• Hard to believe, but sometimes Mathematica is the better tool:) I take the best from both worlds... – highsciguy Jun 3 '12 at 21:18