I wrote a Mathematica script, which calculates an integral value at a list of points and writes it to a file:

ϵ :=78.36;
z := 1;
bohr := 0.52917721;
boltzmann = 3.16681535*10^-6;
c := 10 * 6.02214129*10^23*1.0*10^-27*bohr^3;
κ := Sqrt[2.*4*π*c*z];
kBT := boltzmann * 300;

λ = κ/Sqrt[ϵ]*Sqrt[z/(kBT)]

funcin = 
  1/(ϵ*π)*Exp[-(2*r + λ*Sqrt[r^2 + ρ^2 - 2*r* ρ*Cos[θ]])]*
    r^2*Sin[θ]*1/Sqrt[ρ^2 + r^2 - 2*r*ρ*Cos[θ]]

intfuncinang = 
  Assuming[r > 0 && ρ > 0 && ϵ > 0 & &λ > 0, Integrate[funcin, {θ,0,π}, {ϕ,0, 2π}]]

Assuming[ρ > 0 && ϵ > 0 && λ > 0,
  funcins = 
    Integrate[intfuncinang, {r,0,ρ}] + Integrate[intfuncinang,{r, ρ, Infinity}]

dataimport = Import["inputfile.dat", "Table"];
datatoint = dataimport[[1 ;;, 1]]

int = Array[#&, Length[datatoint]];
Do[ρ = datatoint[[i]];
   int[[i]] = N[funcins];
   points = {datatoint[[i]], int[[i]]};
   points >>> "outputfile.dat"
   , {i, Length[datatoint]}]

I run this on the console with math -nopromt -run "<<script.m". This works always for some values, but crashes after some time. I am using Mathematica 8. Does anyone have an idea why I am getting crashes?

  • 1
    $\begingroup$ I'm afraid that we would need inputfile.dat to try your code :) $\endgroup$
    – Öskå
    May 14, 2014 at 9:24
  • 1
    $\begingroup$ Unrelated to your problem, but Array[#&,Length[datatoint]] is just Range[Length[datatoint]]. Perhaps points>>>"outputfile.dat" could use a ; to suppress output to the console (I can imagine that a large amount of that may choke the console). $\endgroup$ May 14, 2014 at 9:38
  • $\begingroup$ Another thing: your assignment of funcins within the Assuming/Simplify combo doesn't mean funcins contains the simplified result. You have to assign it to the result of the simplification (so outside of the call). $\endgroup$ May 14, 2014 at 9:44
  • 1
    $\begingroup$ That seems to lead to a .exe file. I'm sorry, but I'm not going to download that. Could you try pastebin.com? $\endgroup$ May 14, 2014 at 10:35
  • 1
    $\begingroup$ @SjoerdC.deVries, it leads to the right .dat file for me :) $\endgroup$
    – Öskå
    May 14, 2014 at 14:36

1 Answer 1


I have experienced kernel crashes like that of Mathematica 9.0.1 on OS X in scripts where there is a repeated output to text files during iterations over cycles. Curiously, same scripts run like a charm in Windows, so it is specifically the OS X issue.

Diagnosing this problem is hard, since the kernel just crashes, flushes all variables, and the only message appearing after choosing Why the Beep? from the Help menu is "kernel has quit during an evaluation". The crash is somewhat random, i.e. it does not happen at the same points in cycles or for the same data.

I managed to trace the problem (by naive Print debugging) to calls of Export. Specifically to the variant with Export["file.txt", data, "Table"]. Replacing this with Export["file.txt", data] fixes the problem. So it may be a bug in Export.

You get differently formatted output after the above mention change, with {} braces around lists - much like InputForm representation . When importing such files, you just do Import["file.txt", "List"] // ToExpression instead of Import["file.txt", "Table"].

I'm not sure what platform you working in, but if it is OS X you may be dealing with the same issue. Exporting with the file extension ".dat" produces "Table" format by default, I believe. Try using the extension ".txt" -- easiest of fixes, if it helps.

  • 1
    $\begingroup$ Maybe you can get more information by looking at the crash log, or at least sending it to Wolfram support. To find this file, next time a crash occurs open Utilities > Console and check the last couple of lines written there. That usually tells you the path and name of the crash log. $\endgroup$
    – Jens
    Aug 9, 2014 at 3:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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