4
$\begingroup$

I want to write the numerical results of a computation to a file which is to be read in Fortran. The data looks like:

oswf0={1/(E^(25/2) \[Pi]^(1/4)), 1/(E^(81/8) \[Pi]^(1/4)), 1/( E^8 \[Pi]^(1/4)), 1/(E^(49/8) \[Pi]^(1/4)), 1/(E^(9/2) \[Pi]^(1/4))}

and I write it out with

Export["oscillatorwf_n0.dat", N[oswf0, 50]]

but the ouput file looks like

2.79918439290959673893721788332716676696872559106e-6
0.000030094068318430211211425128144825612558205505948023
0.00025197454903091461102445530088385078965019945670456
0.0016430804571573454314321054224416885379324057884235
0.008344251073246413703289360250294637268362678784284

All of them have clearly different precisions (>50). Why is mathematica not consistent here? What am I overlooking? How can I get 50 digits of precision consistently?

Thanks a lot

$\endgroup$
3
$\begingroup$

If I understand your question correct, you actually want to have an Accuracy of 50 and not a Precision of 50.
If you use

Export["oscillatorwf_n0.dat", N[oswf0, {Infinity, 51}]]

the exported numbers will have a precision of 50 or less. (Less, if they end with zeros.)

2.79918439290959673893721788332716676696872559e-6
0.00003009406831843021121142512814482561255820550595
0.0002519745490309146110244553008838507896501994567
0.00164308045715734543143210542244168853793240578842
0.00834425107324641370328936025029463726836267878428
$\endgroup$
2
  • $\begingroup$ exactly, thank you! I always confuse the two! $\endgroup$ – ftiaronsem Sep 4 '14 at 22:13
  • $\begingroup$ @ftiaronsem I would encourage you to edit your question to clarify what is the output that you seek. $\endgroup$ – Michael E2 Sep 4 '14 at 22:27
3
$\begingroup$

If I understand what you want, the trouble is that final zeros are truncated. Using NumberForm can fix that.

oswf0 = {1/(E^(25/2) π^(1/4)), 1/(E^(81/8) π^(1/4)), 
  1/(E^8 π^(1/4)), 1/(E^(49/8) π^(1/4)), 1/(E^(9/2) π^(1/4))}

ExportString[
 NumberForm[#, Round@Precision[#], 
    NumberFormat -> (Row[{#1, If[#3 == "", "", "e"], #3}] &)] & /@ 
  N[oswf0, 50], "Table"]
(*
"2.7991843929095967389372178833271667669687255910600e-6
0.000030094068318430211211425128144825612558205505948023
0.00025197454903091461102445530088385078965019945670456
0.0016430804571573454314321054224416885379324057884235
0.0083442510732464137032893602502946372683626787842840"
*)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.