Lesson 2.7.1 built the Taylor polynomial pn from the first n derivatives at a. Let n grow without end and you get an infinite series, the Taylor series of f about a.
As in lesson 1.5.3, an infinite series means the limit of its partial sums. Here the partial sums are the Taylor polynomials p0,p1,p2,…, so the question is whether pn(x) settles on f(x).
Rule: Taylor series
f(x)=k=0∑∞k!f(k)(a)(x−a)k
This holds at every x where the partial sums pn(x) settle on f(x). This lesson finds where that is for five standard series, all about a=0.
The series for ex
Every derivative of ex is ex (lesson 2.3.4), which is 1 at 0. So every coefficient is k!1.
Rule: Series for the exponential
ex=1+x+2!x2+3!x3+⋯for every x
The terms shrink fast because k! eventually outgrows any power xk. The Proof Gym (stage PG5) proves that the series settles on ex for every x.
At x=1 the series gives e=1+1+21+61+⋯. The partial sums are 2.5, 2.6667, 2.7083, 2.7167 and 2.7181 after degrees 2 to 6. After degree 10 the gap to e is only 2.7×10−8.
Sine and cosine
The derivatives of sinx go round the cycle of four from lesson 2.3.5: sin, cos, −sin, −cos. At 0 their values are 0, 1, 0, −1, then the cycle repeats.
So the even powers drop out, and the odd ones alternate in sign. Cosine starts one step along the cycle, at 1, 0, −1, 0, so it keeps only the even powers.
Rule: Series for sine and cosine
sinx=x−3!x3+5!x5−⋯cosx=1−2!x2+4!x4−⋯for every x, in radians
Sine has only odd powers, like its symmetry sin(−x)=−sinx; cosine has only even powers, like cos(−x)=cosx (lesson 1.7.1).
The first terms are old friends. sinx≈x is the tangent at 0 from lesson 2.3.5, and cosx≈1−2x2 is the quadratic copy at the top of the wave.
Far from 0 you need many terms. Here are the partial sums for sin3, whose true value is 0.14112.
degree
1
3
5
7
9
11
13
partial sum
3
−1.5
0.525
0.091071
0.145312
0.140875
0.141131
The terms k!3k first grow, to 4.5 at k=3 and k=4, and only then shrink as k! wins. The partial sums swing wildly before they settle.
ln(1+x) and the geometric series
The derivatives of ln(1+x) are 1+x1, −(1+x)21, (1+x)32, −(1+x)46, by the rules of lessons 2.3.1 and 2.3.4. At 0 they are 1, −1, 2, −6. Divided by 1!,2!,3!,4!, they give the coefficients 1, −21, 31, −41.
For 1−x1 the k-th derivative at 0 is k!, so every coefficient is 1. Its Taylor series is the geometric series of lesson 1.5.3, with first term 1 and ratio x.
The bottoms are k, not k!, for ln(1+x), so its terms shrink slowly. Neither series works beyond ∣x∣=1; a later section shows what happens there.
Case study 1.4.7 used ln(1+R)≈R−2R2 for small returns R: these are the first two terms. At R=0.05, ln1.05=0.04879 against 0.04875.
Try it
sp.series(f, x, 0, 7) gives the Taylor series about 0 up to x6. O(x**7) stands for the terms from x7 on.
The loop adds up the series for e to degrees 2 to 6 and 10, with the gap to e. The last line prints the two numbers for ln1.05.
⌘/Ctrl + Enter runs the cell
How big is the error?
The first left-out term
Lesson 2.7.1 found that near a the error of pn is about C(x−a)n+1. The constant is the next coefficient, (n+1)!f(n+1)(a).
So the first term you leave out is an estimate of the error. If its coefficient is 0, as half of sine's are, use the next term that is not 0.
approximation
error
first left-out term
e0.5≈1+0.5+20.52+60.53
0.00289
240.54=0.0026
sin0.5≈0.5−60.53
0.000259
1200.55=0.00026
ln1.05≈0.05−20.052
0.0000402
30.053=0.0000417
The estimate is close, but it is not a promise: for e0.5 the true error is larger than the estimate.
A bound you can trust
When you need a guarantee, use the remainder bound. This lesson states it without proof.
Rule: Remainder bound
∣f(x)−pn(x)∣≤(n+1)!M∣x−a∣n+1
M is the largest size of f(n+1) anywhere between a and x. It is the first left-out term with the derivative at its worst, instead of at a.
For e0.5 with p3, the fourth derivative ex is at most e0.5 between 0 and 0.5. So the error is at most e0.5×240.54=0.0043, and the true error, 0.00289, is below that.
For sine and cosine every derivative is a sine or cosine, at most 1 in size. So M=1, and the error is at most (n+1)!∣x∣n+1.
How many terms
To get e within 10−6, use the bound with M=e<3: the error after degree n is below (n+1)!3. That first drops below 10−6 at degree 9, where it is 8.3×10−7, so 10 terms are enough. The true error is 3.0×10−7.
The answer depends on x. For ex within a relative error of 10−6, you need 10 terms at x=1, 20 at x=5, 29 at x=10 and 46 at x=20.
The slow series is ln(1+x) at x=1: ln2=1−21+31−⋯. After 10, 100 and 1,000 terms the error is 0.0475, 0.00498 and 0.0005, about 2n1. Six correct decimals would take about a million terms.
A smaller x fixes that. Since ln2=−ln(1−0.5), use the series at x=−0.5: its terms shrink like 0.5k, and 20 of them give ln2 within 4.4×10−8.
Try it
The first lines print the table's three errors next to the first left-out terms, then the bound for e0.5.
The fourth line is the bound 10!3 for e at degree 9, then the true error. terms_for adds terms of the series for ex until the relative error is below 10−6. The last lines print the slow and the fast way to ln2.
⌘/Ctrl + Enter runs the cell
Where a series stops working
The series for ex, sinx and cosx work for every x. The other two do not.
ln(1+x) at x=1.5. The function is fine there: ln2.5=0.9163. But the terms k1.5k grow, so the partial sums swing ever wider.
terms
1
2
3
4
5
10
20
30
partial sum
1.5
0.375
1.5
0.2344
1.7531
−2.4031
−96.8286
−3782.6561
Terms that do not shrink to 0 mean the series diverges (lesson 1.5.3). At x=−1 it is −(1+21+31+⋯), minus the harmonic series of lesson 1.5.3, which has no sum either. That matches ln0, which does not exist.
1−x1 at x=2. The series is 1+2+4+⋯, whose partial sums grow without end, while 1−21=−1. At x=−1 it is 1−1+1−⋯, which bounces, while 1−(−1)1=21. Lesson 1.5.3 met both.
Rule: Radius of convergence
converges for ∣x−a∣<Rdiverges for ∣x−a∣>R
Every Taylor series has such a distance R. For ln(1+x) and 1−x1, R=1; for ex, sinx and cosx there is no limit. At ∣x−a∣=R itself, check each end.
The trouble at one end limits the other. ln(1+x) breaks at x=−1, one unit from 0, so its series fails beyond 1 too, where the function is fine.
Near ∣x∣=R the series still converges, but slowly: ln2 took a million terms, and lesson 1.5.3's 1+0.9+0.81+⋯ needed 66 terms to come within 0.01 of its sum. A Taylor polynomial is still a good copy near 0; it is adding more terms far out that fails.
More terms carry the copy of sinx further out, without limit. The copies of ln(1+x) hug the curve only for ∣x∣≤1; beyond 1, more terms make them worse.
Try both sides of the edge. With x=0.5, raise the degree n and watch the error shrink. Then set x=1.5: every extra term makes the error larger.
Explore
Raise the degree and watch the polynomial hug the curve further from its centre. Move the centre, then the point, and compare the error with the first term left out.
y = ln(1 + x)its Taylor polynomial p5The large dot is the centre; the dashed line at x is the error.The dotted line marks x = −1, where the function breaks.
Polynomial
p5(x)=x−2x2+3x3−4x4+5x5
At x = 0.5
ln(1+x) = 0.40547, p5(x) = 0.40729
Error
−0.00183
First term left out
−0.0026
Reach
x is within 1 of the centre, the distance to the break at x = −1: more terms shrink the error.
Try it
ln1p_series adds the first n terms of the series for ln(1+x). At 1.5 the partial sums run away; at −1 they sink like minus the harmonic sums.
The last lines add 20 terms of the geometric series at 2 and at −1.
⌘/Ctrl + Enter runs the cell
Two series at once: (1+nr)n against er
Case study 2.1.5 found that er−(1+nr)n is about 2nr2er, which is n0.0013141 at r=0.05. The series for ln(1+x) and ex show where that comes from.
1
(1+nr)n=enln(1+r/n)
2
nln(1+nr)=r−2nr2+3n2r3−⋯
3
(1+nr)n=ereu≈er(1−2nr2)
So the gap er−(1+nr)n is about er×2nr2. At r=0.05, 2r2er=0.0013141, the number the table of case study 2.1.5 settled on.
Try it
The first line checks step 2 for n=12: nln(1+nr) against r−2nr2.
The loop prints the gap times n next to 2r2er, which it approaches as n grows.
⌘/Ctrl + Enter runs the cell
Euler's formula from the series
Lesson 1.7.3 checked Euler's formula eiθ=cosθ+isinθ with numbers. The series give one way to see why it holds for every angle θ, in radians.
Put x=iθ into the series for ex. The powers of i go round a cycle of four, 1,i,−1,−i (lesson 1.7.2):
eiθ=1+iθ−2!θ2−3!iθ3+4!θ4+5!iθ5−⋯
Sort the terms. The real ones, 1−2!θ2+4!θ4−⋯, are the series for cosθ. The others are i times θ−3!θ3+5!θ5−⋯, the series for sinθ.
So eiθ=cosθ+isinθ. This takes on trust that the series for ex works for complex x as well; all three series work for every input.
Try it
The cell adds 25 terms of ∑k!(iθ)k, with 1j for i, at θ=1 and θ=π. It compares each sum with cmath.exp and with cosθ+isinθ.
tidy rounds both parts to 6 places, as in lesson 1.7.3.
⌘/Ctrl + Enter runs the cell
Common mistakes
Radians for sine and cosine. The series x−6x3+⋯ needs x in radians, as the derivatives of lesson 2.3.5 do.
Which signs alternate. Sine, cosine and ln(1+x) alternate; ex and 1−x1 do not.
k, not k!, under ln(1+x). Its terms are kxk, with a minus sign on the even ones.
A series outside its range gives nonsense. The series for ln(1+x) at x=1.5 and for 1−x1 at x=2 diverge, though both functions have values there.
The first left-out term is an estimate, not a guarantee. For a guarantee, use the remainder bound.
More terms for larger ∣x∣. Ten terms give e within 10−6; e20 needs 46 for the same relative accuracy.
Standard series and the size of the error
0 of 12 correct
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
How to type answers
Powers with ^: x^7, 2^(1/3), a^-2.
Multiply with * or by writing side by side: 3x^2, 2(x+1).
ln(x) is the natural log, log(x, 2) is log base 2, e is Euler's number, sqrt(x) is a square root.
sin(x), cos(x) and tan(x) take radians; write pi for π and sin(x)^2 for sin²x.
Your first answer to each question is saved: it counts towards your score and brings the question back for review.
Exact answers like ln(20)/ln(3) are best. Decimals need about 4 significant figures.
Summary card
A Taylor series is the Taylor polynomial with n→∞; it equals f(x) where the partial sums settle on f(x).
ex=∑k!xk, sinx=x−3!x3+⋯ and cosx=1−2!x2+⋯ work for every x (radians for sine and cosine).
ln(1+x)=x−2x2+3x3−⋯ for −1<x≤1; 1−x1=1+x+x2+⋯ for ∣x∣<1. Beyond, they diverge.
The first left-out term estimates the error; the bound (n+1)!M∣x−a∣n+1 guarantees it. Larger ∣x∣ needs more terms.
(1+nr)n≈er(1−2nr2), from the series for ln(1+x) and ex. Putting iθ into the series for ex gives cosθ+isinθ.