# How to improve resolution of plot with underflow and overflow?

I am working with a function that has the form

Exp[-a^2](Erfi[a]-Log[-1/a]-Log[a])/a


where a is complex number. When I tried to plot it, my expression yields underflow and overflow. Here, you can see that my blue plot is oscillating because of this problem. I want to make a nice and clean plot! PlotPoints will make it little better, but there still is a missing region. Any help?

Here is a sample function (It might take a few seconds)

f[d_]:=(1/(2 Sqrt[(-2562890621 -
112500 I) π]))(-((2 - 28125 I) +
Sqrt[-2562890621 - 112500 I] + 4500 I Sqrt[70]) E^(-(1/
16) ((-2 + 50629 I) + Sqrt[-2562890621 - 112500 I] -
4 d)^2) (π Erfi[
1/4 ((-2 + 50629 I) + Sqrt[-2562890621 - 112500 I] - 4 d)] -
Log[(-2 + 50629 I) + Sqrt[-2562890621 - 112500 I] - 4 d] -
Log[1/((2 - 50629 I) - Sqrt[-2562890621 - 112500 I] +
4 d)]) + ((-2 + 28125 I) + Sqrt[-2562890621 - 112500 I] -
4500 I Sqrt[70]) E^(-(1/
16) ((2 - 50629 I) + Sqrt[-2562890621 - 112500 I] +
4 d)^2) (π Erfi[
1/4 ((2 - 50629 I) + Sqrt[-2562890621 - 112500 I] + 4 d)] +
Log[(-2 + 50629 I) - Sqrt[-2562890621 - 112500 I] - 4 d] +
Log[1/((2 - 50629 I) + Sqrt[-2562890621 - 112500 I] + 4 d)]))
Plot[Im[f[d]],{d,-10,10}]


or (Same thing, I just make it look nicer)

k = -2562890621-112500I;
l = 2-28125I;
o = 2-50629I;
kk[d_] :=
1/(2 Sqrt[k Pi])*
(-(l+Sqrt[k]+4500 I Sqrt[70]) E^(-(1/16)(-o+Sqrt[k]-4d)^2)(Pi Erfi[1/4(-o+Sqrt[k]-4d)]-Log[-o+Sqrt[k]-4d]-Log[1/(o-Sqrt[k]+4d)])
+(l+Sqrt[k]-4500 I Sqrt[70]) E^(-(1/16)(o+Sqrt[k]+4d)^2)(Pi Erfi[1/4(o+Sqrt[k]+4d)]+Log[-o-Sqrt[k]-4d]+Log[1/(o+Sqrt[k]+4d)]))
Plot[Im[kk[d]], {d, -10, 10}]


• Evaluate these two values, {Im[f[3.]], Im[f[2.]]} to see why some places have no line – Jason B. Jan 18 '17 at 16:47
• @JasonB. I think those results are due to numerical errors; he is aware of that problem (hence his reference to underflow / overflow), and he is asking for a solution for it. Even increasing WorkingPrecision dramatically, however, does not seem to solve the problem. Saesun, I wonder if you can rewrite / Simplify / refactor your expression to a form that isn't affected by such huge errors. – MarcoB Jan 18 '17 at 16:51
• Thanks, I am trying to refactor my expression, I will let you know if it works! – Saesun Kim Jan 18 '17 at 17:08

With[{k = -2562890621 - 112500 I, l = 2 - 28125 I, o = 2 - 50629 I},
Plot[With[{c = -l - 4500 Sqrt[-70], f = 2 Sqrt[π],
sm = -o + Sqrt[k] - 4 d, sp = o + Sqrt[k] + 4 d},
Im[((c - Sqrt[k]) (f DawsonF[sm/4] -
Exp[-(sm/4)^2] (Log[sm] + Log[-1/sm])) +
(c + Sqrt[k]) (f DawsonF[sp/4] +
Exp[-(sp/4)^2] (Log[-sp] + Log[1/sp])))/(f Sqrt[k])]],
{d, -10, 10}]]


# Notes

1. Be kind to yourself; identify common subexpressions and isolate them. You'll thank yourself later when you're debugging.

2. In applications, the imaginary error function $\operatorname{erfi}(z)$ is not the quantity of interest, but rather its exponentially-scaled version, Dawson's integral (built-in as DawsonF[]). This has the advantage of being bounded even for large values.

• Thank you for introducing me Dawson's integral! – Saesun Kim Jan 18 '17 at 20:44

If all you need is a continuous Plot, you can interpolate the available Plot data.

plot1 = Plot[Im[f[d]], {d, -10, 10}];

points = Join @@ Cases[plot1, Line[pts__] :> pts, Infinity];

f2 = Interpolation[points];

{min, max} = MinMax[points[[All, 1]]];

Plot[f2[d], {d, min, max}]