taylor series approximations: visualizing convergence and radius
Watching polynomials wrap around sin, cos and ln: factorial-fast convergence for entire functions, and the hard wall of the convergence radius where adding terms makes things worse.

A Taylor series is an act of extrapolation: measure a function's value and all its derivatives at a single point, and reconstruct the function everywhere else from that purely local information. For some functions the reconstruction works globally. For others it hits an invisible wall at a precisely predictable distance. This experiment visualizes both outcomes side by side, using , , and as the cast.
The formalism is three centuries old — Brook Taylor published it in 1715, and Colin Maclaurin popularized the special case — but watching polynomials wrap themselves around a transcendental function still doesn't get old.
the setup #
The Taylor series of about the expansion point is
and the order- Taylor polynomial is that sum truncated at . The truncation error has the Lagrange form
for some between and — so factorials fight powers, and whoever wins decides convergence.
For the implementation there is a pleasant shortcut: the derivatives of sine are just phase-shifted sines, , and likewise for cosine. One formula then evaluates about any expansion point:
def taylor_sin(x, n_max, x0=0.0):
out = np.zeros_like(x)
for n in range(n_max + 1):
out += np.sin(x0 + n * np.pi / 2) / factorial(n) * (x - x0) ** n
return out
For the derivatives are , and the factorials cancel into the tidy series
sine and cosine — the well-behaved cases #
and are entire functions: their Taylor series converge for every real , from any expansion point. What the visualization adds to that dry statement is how convergence happens — each new order extends the region where the polynomial hugs the target, pushing the inevitable polynomial blow-up further out:


By order 15 the polynomials track both functions across two full periods. The overlay plot compresses the whole progression into one frame per function:

ln(x) — the wall #
The bottom panel above shows something qualitatively different. The series for about converges only where . The reason is the singularity at : a power series converges inside the largest disk around that avoids the nearest singularity, so the radius is exactly . The frustrating consequence is that the wall also stands at , where itself is perfectly smooth — the singularity on the left poisons the series on the right.


The experiment quantifies the wall by tracking the error while stepping the order from 10 to 14: at (inside) the error shrinks by a factor of ; at (outside) it grows by a factor of . Adding terms past the radius is worse than useless.
how the error behaves #
Inside the radius, convergence is factorial-fast. The dual-panel view makes the geometry of the error visible — a valley of machine-precision agreement around , walls that steepen with order:

Fixing an evaluation point and sweeping the order instead gives clean straight lines on a log scale — the hallmark of exponential-or-better decay:

trust, but verify #
Plots are persuasive, which is exactly why the numbers behind them need independent checks. Before rendering anything, the experiment compares every implementation against SymPy's symbolic series() at multiple points and expansion points — the worst disagreement is — and against known values. One check is a nice illustration of why validation needs theory: of cosine misses by , which looks like a bug until you compute the first omitted term, . The "error" is the truncation remainder itself, on the nose.
takeaways #
Taylor polynomials are local creatures. For entire functions like sine and cosine, "local" quietly becomes "global" and 15 terms cover the plane. For , the nearest singularity draws a hard circle around the expansion point, and no amount of extra terms buys a single point beyond it — the series diverges faster with more terms outside the wall. If the previous experiment's lesson was that smoothness sets the speed of convergence, this one's is sharper: analyticity decides whether convergence happens at all.
The companion experiment on Fourier series asks the same questions with sines instead of powers — and fails in the opposite way, everywhere at once by a little rather than beyond a wall by everything.