# How to plot a log log plot of the error

Suppose I have a function

$$f(x) = \frac{1}{1+e^x}$$

I can use the function Series[] to generate a series expansion of $f$ as follows

x0 = 0;
f[x_] = 1/(1 + E^x);
poly[n_] := Normal[Series[f[x], {x, x0, n}]]
poly


which yields

$$f(x) \approx \frac{1}{2}-\frac{x}{4}+\frac{x^3}{48}$$

Denote by $f_n(x)$ the series truncated after the nth term. I want to generate a plot of the error $|f(x)-f_n(x)|$ versus $|x|$ on log scales. I think I can do this with LogLogPlot[] as follows

Clear[error]
error[n_] := error[n] = Abs[f[x] - poly[n]]
LogLogPlot[error, {x, 10^-10, 1}]


This generates the plot Which I think looks correct, the error curve is a straight line as expected. But now suppose I change the point of expansion to $x_0 = 1$. Now I want to plot $|f(x)-f_n(x)|$ versus $|x-x_0|$ on log scales. How can I do this?

I have tried

ParametricPlot[{Log[error], Log[Abs[x - x0]]}, {x, x0, x0 + 1}]


but I don't know how I can label the ticks correctly as above. I think maybe I need to use ListLogLogPlot[] but I'm not sure how to generate the points for the x range.

What i'm looking to do is plot something similar to the matlab code to do this is available here

Shift the plot slightly by evaluating the error at x+x0

x0 = 1;
f[x_] = 1/(1 + E^x);
(* I just want a function in n and x, tried to base it
on poly but ended up in scoping hell *)
t[n_Integer, x_] := Normal[Series[f[y], {y, x0, n}]] /. y -> x
err[n_, x_] := Abs[f[x] - t[n, x]]

LogLogPlot[err[3, x + x0], {x, 10^-10, 1}] (If you want to retain the numerical error jumping around at 10^-16 you can use LogLogPlot[Evaluate[err[3, x + x0]], {x, 10^-10, 1}] why this is the case is beyond my understanding )

You probably want to plot Max[err[n,x+x0],err[n,x0-x]] since the error might be bigger on the other side of x0

• How come Evaluate changes the behavior of the plot? – ssch Jan 18 '13 at 20:15