0
$\begingroup$

recently I have been trying to calculate the following numerical integral

\begin{equation} \frac{4 t}{\text{DD}}\frac{1}{2 \pi } \int_{0}^{\infty} dx \int_{0}^{\infty} d\epsilon \frac{\left(\frac{\sin \left(\frac{x}{2}\right)}{x}\right)^2 \left(\left(\epsilon ^3 \exp (-2 \epsilon )\right) \left(\frac{\text{DD} t}{d^2}\right)^2\right)}{\left(\text{DD} x^2\right) \left(\frac{\epsilon ^4 \left(\frac{\text{DD} t}{d^2}\right)^2}{x^2}+1\right)}. \end{equation}

which in Mathematica reads

exponent[(t_)?NumericQ, (DD_)?NumericQ, (d_)?NumericQ] := ((4*t)/DD)*(1/(2*Pi))*NIntegrate[(Sin[x/2]/x)^2*(((t*(DD/d^2))^2/(DD*x^2))*((\[Epsilon]^3*Exp[-2*\[Epsilon]])/(1 + ((DD/d^2)*t)^2*(\[Epsilon]^4/x^2)))), {x, zero, inf}, {\[Epsilon], zero, inf}]

Unfortunately, when I plot something like

plotexact = LogLogPlot[{exponent[1, 1, d], exponent[.1, 1, d], exponent[10, 1, d]}, {d, 10^-3, 10^3}, PlotLegends -> "Expressions", PlotPoints -> 10]

The Mathematica does not give me any plot after hours. I have tried to change the integral do main from $10^{-n}$ to $10^n$ with $n\approx5$ but that did not help at all. Any thoughts?

Thanks!

$\endgroup$

1 Answer 1

5
$\begingroup$

The integral just takes a while, particularly for small values of $d$. For example, for $t = 1$, $DD = 1$, and $d = 10^{-3}$, my computer (which is admittedly not terribly fast) takes about 25 seconds to evaluate exponent. And by default, Mathematica will sample the curve many, many times to ensure that it has captured all of the nuances of the graph.

You can force LogLogPlot to create a "cruder" graph by using the PlotPoints and MaxRecursion options. PlotPoints is the number of points that Mathematica samples the curve at initially; MaxRecursion is the maximum number of times that Mathematica will sub-divide this initial graph to capture more variation in the curve. The smaller both numbers are, the less sampling Mathematica will do, and the faster it will output a graph.

For example, the command

LogLogPlot[exponent[1, 1, d], {d, 10^-3, 10^3},
           PlotPoints -> 10, MaxRecursion -> 0, Mesh -> All]

returns the following graph after about 5–10 minutes on my computer:

enter image description here

(The Mesh -> All option shows you where Mathematica actually evaluated the function; you can see that it is just linearly interpolating between these points.)

$\endgroup$

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.