Can you compute ln(2) using only a basic
calculator with four operations: [+], [-], [×], [÷]?
I can tell you one way. Simply compute the following sum:
1−12+13−14+15−16+17+….
We can compute the above sum for large values of n using live.sympy.org
:
>>> def axn_ln2(n): return 1.0*(-1)**(n+1)/n >>> sum([ axn_ln2(n) for n in range(1,100) ]) 0.69(817217931) >>> sum([ axn_ln2(n) for n in range(1,1000) ]) 0.693(64743056) >>> sum([ axn_ln2(n) for n in range(1,1000000) ]) 0.693147(68056) >>> ln(2).evalf() 0.693147180559945
As you can see, the more terms you add in this series, the more accurate the series approximation of ln(2) becomes. A lot of practical mathematical computations are done in this iterative fashion. The notion of series is a powerful way to calculate quantities to arbitrary precision by summing together more and more terms.
put together. The summation sign is the short way to express
certain long expressions: \[ a_3 + a_4 + a_5 + a_6 + a_7 = \sum_{3 \leq i \leq 7} a_i = \sum_{i=3}^7 a_i. \] * $\sum a_i$: series. The running total of a sequence until $n$: \[ S_n = \sum_{i=1}^n a_i = a_1 + a_2 + \ldots + a_{n-1} + a_n. \] Most often, we take the sum of all the terms in the sequence: \[ S_\infty = \sum_{i=1}^\infty = a_1 + a_2 + a_{3} + a_4 + \ldots. \] * $n!$: the //factorial// function: $n!=n(n-1)(n-2)\cdots 3\cdot2\cdot1$. * $f(x)=\sum_{n=0}^\infty a_n x^n$: //Taylor series// approximation of the function $f(x)$. It has the form of an infinitely long polynomial $a_0 + a_1x + a_2x^2 + a_3x^3 + \ldots$ where the coefficients $a_n$ are chosen so as to encode the properties of the function $f(x)$.
There exist formulas for calculating the exact sum of certain series. Sometimes even infinite series can be calculated exactly.
The sum of the geometric series of length n is: n∑k=0rk=1+r+r2+⋯+rn=1−rn+11−r.
If |r|<1, we can take the limit as n→∞ in the above expression to obtain: ∞∑k=0rk=11−r.
Consider the geometric series with r=12. If we apply the above formula formula we obtain ∞∑k=0(12)k=11−12=2.
You can also visualize this infinite summation graphically. Imagine you start with a piece of paper of size one-by-one and then you add next to it a second piece of paper with half the size of the first, and a third piece with half the size of the second, etc. The total area that this sequence of pieces of papers will occupy is:
The sum of the first N+1 terms in arithmetic progression is given by: N∑n=0(a0+nd)=a0(N+1)+N(N+1)2d.
We have the following closed form expression involving the first N integers: N∑k=1k=N(N+1)2,N∑k=1k2=N(N+1)(2N+1)6.
Other series which have exact formulas for their sum are the p-series with even values of p: ∞∑n=11n2=π26,∞∑n=11n4=π490,∞∑n=11n6=π6945. These series are computed by Euler's method.
Other closed form sums: ∞∑n=1(−1)n+1n2=π212,∞∑n=1(−1)n+1n=ln(2), ∞∑n=114n2−1=12, ∞∑n=11(2n−1)2=π28,∞∑n=1(−1)n+1(2n−1)3=π332,∞∑n=11(2n−1)4=π496.
Even when we cannot compute an exact expression for the sum of a series it is very important to distinguish series that converge from series that do not converge. A great deal of what you need to know about series is different tests you can perform on a series in order to check whether it converges or diverges.
Note that convergence of a series is not the same as convergence of the underlying sequence ai. Consider the sequence of partial sums Sn=∑ni=0ai: S0,S1,S2,S3,…, where each of these corresponds to a0, a0+a1, a0+a1+a2, a0+a1+a2+a3,….
We say that the series ∑ai converges if the sequence of partial sums Sn converges to some limit L: limn→∞Sn=L.
As with all limits, the above statement means that for any precision ϵ>0, there exists an appropriate number of terms to take in the series Nϵ, such that |Sn−L|<ϵ, for all n≥Nϵ.
The only way the partial sums will converge is if the entries in the sequences an tend to zero for large n. This observation gives us a simple series divergence test. If limn→∞an≠0 then ∑nan diverges. How could an infinite sum of non-zero quantities add up to a finite number?
If ∑n|an| converges, ∑nan also converges. The opposite is not necessarily true, since the convergence of an might be due to some negative terms cancelling with the positive ones.
A sequence an for which ∑n|an| converges is called absolutely convergent. A sequence bn for which ∑nbn converges, but ∑n|bn| diverges is called conditionally convergent.
An alternating series of which the absolute values of the terms are decreasing and go to zero converges.
The series ∞∑n=11np converges if p>1 and diverges if p≤1.
Suppose limn→∞anbn=p, then the following is true:
If L is defined by L=limn→∞n√|an| then ∑nan diverges if L>1 and converges if L<1. If L=1 the test is inconclusive.
L=limn→∞|an+1an|, then is ∑nan diverges if L>1 and converges if L<1. If L=1 the test is inconclusive.
In a power series an=cnxn, the nth term is multiplied by the nth power of x. For such series, the convergence or divergence of the series depends on the choice of the variable x.
The radius of convergence ρ of ∑ncn is given by: 1ρ=limn→∞n√|cn|=limn→∞|cn+1cn|. For all −ρ<x<ρ the series an converges.
If ∫∞af(x)dx<∞, then ∑nf(n) converges.
The Taylor series approximation to the function sin(x) to the 9th power of x is given by sin(x)≈x−x33!+x55!−x77!+x99!. If we want to get rid of the approximate sign, we have to take infinitely many terms in the series: sin(x)=∞∑n=0(−1)nx2n+1(2n+1)!=x−x33!+x55!−x77!+x99!−x1111!+….
This kind of formula is known as a Taylor series approximation. The Taylor series of a function f(x) around the point a is given by: f(x)=f(a)+f′(a)(x−a)+f′′(a)2!(x−a)2+f′′′(a)3!(x−a)3+⋯=∞∑n=0f(n)(a)n!(x−a)n.
The McLaurin series of f(x) is the Taylor series expanded at a=0: f(x)=f(0)+f′(0)x+f′′(0)2!x2+f′′′(0)3!x3+…=∞∑n=0f(n)(0)n!xn.
Taylor series of some common functions: cos(x)=1−x22+x44!−x66!+x88!+…ex=1+x+x22+x33!+x44!+x55!+…ln(x+1)=x−x22+x33−x44+x55−x66+…cosh(x)=1+x22+x44!+x66!+x88!+x1010!+…sinh(x)=x+x33!+x55!+x77!+x99!+x1111!+… Note the similarity in the Taylor series of sin, cos and sinh and cosh. The formulas are the same, but the hyperbolic version do not alternate.
The names Taylor series and McLaurin series are used interchangeably. Another synonym for the same concept is a power series. Indeed, we are talking about a polynomial approximation with coefficients an=f(n)(0)n! in front of different powers of x.
If you remember your derivative rules correctly, you can calculate the McLaurin series of any function simply by writing down a power series a0+a1x+a2x2+… taking as the coefficients an the value of the n'th derivative divided by the appropriate factorial. The more terms in the series you compute, the more accurate your approximation is going to get.
The zeroth order approximation to a function is f(x)≈f(0). It is not very accurate in general, but at least it is correct at x=0.
The best linear approximation to f(x) is its tangent T(x), which is a line that passes through the point (0,f(0)) and has slope equal to f′(0). Indeed, this is exactly what the first order Taylor series formula tells us to compute. The coefficient in front of x in the Taylor series is obtained by first calculating f′(x) and then evaluating it at x=0: f(x)≈f(0)+f′(0)x=T(x).
To find the best quadratic approximation to f(x), we find the second derivative f′′(x). The coefficient in front of the x2 term will be f′′(0) divided by 2!=2: f(x)≈f(0)+f′(0)x+f′′(0)2!x2.
If we continue like this we will get the whole Taylor series of the function f(x). At step n, the coefficient will be proportional to the nth derivative of f(x) and the resulting nth degree approximation is going to imitate the function in its behaviour up the nth derivative.
We are looking for the sum S given by: S=n∑k=0rk=1+r+r2+r3+⋯+rn. Observe that there is a self similar pattern in the expanded summation S where each term to the right has an additional power of r. The effects of multiplying by r will therefore to “shift” all the terms of the series: rS=rn∑k=0rk=r+r2+r3+⋯+rn+rn+1, we can further add one to both sides to obtain 1+rS=1+r+r2+r3+⋯+rn⏟S+rn+1=S+rn+1. Note how the sum S appears as the first part of the expression on the right-hand side. The resulting equation is quite simple: 1+rS=S+rn+1. Since we wanted to find S, we just isolate all the S terms to one side: 1−rn+1=S−rS=S(1−r), and then solve for S to obtain S=1−rn+11−r. Neat no? This is what math is all about, when you see some structure you can exploit to solve complicated things in just a few lines.
Compute the sum of the infinite series ∞∑n=01N+1(NN+1)n. This may appear complicated, but only until you recognize that this is a type of geometric series ∑arn, where a=1N+1 and r=NN+1: ∞∑n=01N+1(NN+1)n=∞∑n=0arn=a1−r=1N+111−NN+1=1.
How does a calculator compute sin(40∘)=0.6427876097 to ten decimal places? Clearly it must be something simple with addition and multiplication, since even the cheapest scientific calculators can calculate that number for you.
The trick is to use the Taylor series approximation of sin(x): sin(x)=x−x33!+x55!−x77!+x99!+…=∞∑n=0(−1)nx2n+1(2n+1)!.
To calculate sin of 40 degrees we just compute the sum of the series on the right with x replaced by 40 degrees (expressed in radians). In theory, we need to sum infinitely many terms to satisfy the equality, but in practice you calculator will only have to sum the first seven terms in the series in order to get an accuracy of 10 digits after the decimal. In other words, the series converges very quickly.
Let me show you how this is done in Python.
First we def
ine the function for the nth term:
an(x)=(−1)nx2n+1(2n+1)!
>>> def axn_sin(x,n): return (-1.0)**n * x**(2*n+1) / factorial(2*n+1)
Next we convert 40∘ to radians:
>>> forti = (40*pi/180).evalf() 0.698131700797732 # 40 degrees in radians
NOINDENT These are the first 10 coefficients in the series:
>>> [ axn_sin( forti ,n) for n in range(0,10) ] [(0, 0.69813170079773179), # the values of a_n for Taylor(sin(40)) (1, -0.056710153964883062), (2, 0.0013819920621191727), (3, -1.6037289757274478e-05), (4, 1.0856084058295026e-07), (5, -4.8101124579279279e-10), (6, 1.5028144059670851e-12), (7, -3.4878738801065803e-15), (8, 6.2498067170560129e-18), (9, -8.9066666494280343e-21)]
NOINDENT To compute sin(40∘) we sum together all the terms:
>>> sum( [ axn_sin( forti ,n) for n in range(0,10) ] ) 0.642787609686539 # the Taylor approximation value >>> sin(forti).evalf() 0.642787609686539 # the true value of sin(40)
You can think of the Taylor series as “similarity coefficients” between f(x) and the different powers of x. By choosing the coefficients as we have an=f(n)(?)n!, we guarantee that Taylor series approximation and the real function f(x) will have identical derivatives. For a McLaurin series the similarity between f(x) and its power series representation is measured at the origin where x=0, so the coefficients are chosen as an=f(n)(0)n!. The more general Taylor series allow us to build an approximation to f(x) around any point xo, so the similarity coefficients are calcualted to match the derivatives at that point: an=f(n)(xo)n!.
Another way of looking at the Taylor series is to imagine that it is a kind of X-ray picture for each function f(x). The zeroth coefficient a0 in the power series tells you how much of the constant function there is in f(x). The first coefficient, a1, tells you how much of the linear function x there is in f, the coefficient a2 tells you about the x2 contents of f, and so on and so forth.
Now get ready for some crazy shit. Using your new found X-ray vision for functions, I want you to go and take a careful look at the power series for sin(x), cos(x) and ex. As you will observe, it is as if ex contains both sin(x) and cos(x), except for the alternating negative signs. How about that? This is a sign that these three functions are somehow related in a deeper mathematical sense: recall Euler's formula.
Show that ∞∑n=01N+1(NN+1)nn=N. Hint: take the derivative with respect to r on both sides of the formula for the geometric series.