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}]
]//Simplify
dataimport = Import["inputfile.dat", "Table"];
datatoint = dataimport[[1 ;;, 1]]
Print[Length[datatoint]]
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?
inputfile.dat
to try your code :) $\endgroup$Array[#&,Length[datatoint]]
is justRange[Length[datatoint]]
. Perhapspoints>>>"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$funcins
within theAssuming/Simplify
combo doesn't meanfuncins
contains the simplified result. You have to assign it to the result of the simplification (so outside of the call). $\endgroup$.dat
file for me :) $\endgroup$