# attempting to plot the asymptotic expansion of the complementary error function

I was trying to plot the asymptotic expansion of erfc(x) for some value of x:

exact[x_] := 1/Sqrt[\[Pi]]*Gamma[1/2, x^2];
seriesz[x_, n_] :=
Exp[-x^2]/(x*Sqrt[\[Pi]])
Sum[(-1)^m* (2 m - 1)!! /(2^m *x^(2 m)), {m, 1, n}];

x = 2;
mmax = 5*x;

Print[StringForm["Exact answer: ", exact[1.0*x]]]
Show[Plot[{exact[x]}, {m, 0, mmax}, PlotStyle -> {Dashed, Red}], ListPlot[Table[{m, seriesz[x, m]}, {m, 0, mmax}]]]


but the series is always ends up much lower on the plot than the actual value. Instead of getting something where the series oscillates around the exact value, what I'm getting when I run this code is:

Exact answer: 0.0046777349810472645 When what I'm looking for is this (which I get when I make this alteration to the code):

seriesz[x_, n_] := 0.00517 + Exp[-x^2]/(x*Sqrt[\[Pi]])*Sum[(-1)^m* (2 m - 1)!! /(2^m *x^(2 m)), {m, 1, n}]; Any advice what I'm doing wrong that the series isn't centered around the exact value and instead is centered around some smaller value?

Could be an error in your expression? Mathematica can do asymptotic expansions using Series, I believe. Consider this:

f[x_] = 1/Sqrt[π]*Gamma[1/2, x^2];
ListPlot[
Table[Normal@Series[f[x], {x, ∞, n}] /. x -> 2, {n, 1, 20, 2}]
, PlotRange -> All
, Epilog -> {Line[{{0, f}, {25, f}}]}
]
`

results in the following: • I did not realise Mathematica had that capability! And I see in your code that to change x, you changed f(2). Useful, thank you! – Jomy Blue Sep 21 '17 at 5:31
• Could you just explain what the purpose of {n, 1, 20, 2} in the above code segment is? – Jomy Blue Sep 21 '17 at 5:34
• The table index n (which is the order of the expansion, essentially), goes from 1 to 20 in steps of 2. I did this because the expansion had only odd parts of x. – march Sep 21 '17 at 5:36