Monday 30 May 2011

An introduction to e

*edit: I fixed the graphics, they should work in any browser now.

What is e?

Euler's number, $e$, is a very important irrational constant, it has wide uses across maths, science and economics. In particular it's useful in modelling the natural processes of growth and decay, compound interest as well as having a number of useful properties in calculus. We define $e$ as the exponential function that has a gradient of $1$ when it crosses the coordinate axis $x=0$, this can be represented in functions as: \[ \frac{\mathrm{d}}{\mathrm{d}x} e^x = 1, \ \text{when} \ x = 0\] Or graphically. The graph shows the plots of $e^x$, $3^x$ and the line $y = x+1$. The line also has a gradient of 1 for comparison:

But what is the value of $e$? Lets suppose there exists an exponential function $a^x$ where $a$ is an arbitrary constant, the derivative of this function is: \[\begin{align} \frac{\mathrm{d}}{\mathrm{d}x} a^x &= \lim_{\delta x \to 0} \ \frac{a^{x+ \delta x} - a^x}{\delta x} \\ \\ &= \lim_{\delta x \to 0} \ \frac{a^{x} ( a^{\delta x} - 1)}{\delta x} \end{align} \] $e$ has the unique property that its gradient is 1 when it crosses the coordinate axis. So make the derivative 1 and set $x=0$. This is: \[\begin{align} &\lim_{\delta x \to 0} \ \frac{a^{0} ( a^{\delta x} - 1)}{\delta x} = 1 \\ \\ &\lim_{\delta x \to 0} \ \frac{( a^{\delta x} - 1)}{\delta x} = 1 \\ \\ &\lim_{\delta x \to 0} \ a^{\delta x} = 1 + \delta x \\ \\ &\lim_{\delta x \to 0} \ 1 + \delta x = a^{\delta x} \\ \\ &\lim_{\delta x \to 0} \ (1 + \delta x)^{\frac{1}{\delta x}} = (a^{\delta x})^{\frac{1}{\delta x}} \\ \\ &\lim_{\delta x \to 0} \ (1 + \delta x)^{\frac{1}{\delta x}} = a \end{align}\] When this limit is evaluated the arbitrary constant $a$ is found to be $2.71828...$ This is Euler's number!

Euler's number can be expressed as another limit as well, by making the substitution $\delta x = \frac{1}{\xi}$. It can be seen that for $\frac{1}{\xi} \to 0$, $\xi \to \infty$, this can replace the limit of the final expression, so: \[ \lim_{\xi \to \infty} \ \Big(1+ \frac{1}{\xi} \Big)^{\xi} = e \] I have graphed this limit over a small range of $\xi$ values to demonstrate that it converges onto $e$.

e and calculus
Derivatives of exponents

Lets say I wanted to find the derivative of $a^x$: \[\begin{align} \frac{\mathrm{d}}{\mathrm{d}x} a^x &= \lim_{\delta x \to 0} \ \frac{a^{x+ \delta x} - a^x}{\delta x} \\ \\ &= \lim_{\delta x \to 0} \ \frac{a^{x} ( a^{\delta x} - 1)}{\delta x} \\ \\ &= \lim_{\delta x \to 0} \ a^{x} \Big( \frac{a^{\delta x} - 1}{\delta x} \Big) \end{align} \] Now that derivative isn't very pleasant. However we saw earlier that in the case where the arbitrary constant $a$ is equal to $e$ the limit evaluates to 1, so: \[ \lim_{\delta x \to 0} \ \frac{ (e^{\delta x} - 1) }{\delta x} = 1\] So it can be seen that: \[ \frac{\mathrm{d}}{\mathrm{d}x} e^x = \lim_{\delta x \to 0} \ e^{x} \Big( \frac{e^{\delta x} - 1}{\delta x} \Big) = e^x \cdot 1 = e^x \] So not only does $e$ make finding the derivative of exponents easier it has a rather unique property, it is its own derivative!

Integrating exponents

We can also find the antiderivative of $e^x$ using the the fact that $\frac{\mathrm{d}}{\mathrm{d}x} e^x = e^x$: \[ \int e^x \ \mathrm{d}x = \int \frac{\mathrm{d}}{\mathrm{d}x} (e^x) \ \mathrm{d}x \] From here it is simple enough to apply the fundamental theorem of calculus to find the antiderivative: \[ \int e^x \ \mathrm{d}x = \int \frac{\mathrm{d}}{\mathrm{d}x} (e^x) \ \mathrm{d}x = e^x + C \]

Derivatives of logarithms

$e$ is also very useful when dealing with logarithms. Suppose I find the differential of an arbitrary logarithm in base $a$: \[ \begin{align} \frac{\mathrm{d}}{\mathrm{d}x} \log_{a} x &= \lim_{\delta x \to 0} \ \frac{\log_{a} (x + \delta x) - \log_{a} x }{\delta x} \\ \\ &= \lim_{\delta x \to 0} \ \frac{ \log_{a} \Big( \frac{x + \delta x} {x} \Big) } {\delta x} \\ \\ &= \lim_{\delta x \to 0} \ \frac{ \log_{a} \Big( 1 + \frac{\delta x}{x} \Big) } {\delta x} \end{align} \] Making the substitution $\xi = \frac{\delta x}{x}$, the limit is now becomes $\xi \to 0$ \[ \begin{align} \frac{\mathrm{d}}{\mathrm{d}x} \log_{a} x &= \lim_{\xi \to 0} \ \frac{ \log_{a} (1 + \xi) } {x \xi} \\ \\ &= \lim_{\xi \to 0} \ \frac{1}{x} \Big( \frac{1}{\xi} \log_{a} (1 + \xi) \Big) \end{align} \] Now it isn't a particularly pleasant derivative, but what if $ \lim_{\xi \to 0} \frac{1}{\xi} \log_{a} (1+ \xi) = 1$, then the derivative would just be $\frac{1}{x}$. This can be solved fairly easily using algebra: \[ \begin{align} &\lim_{\xi \to 0} \ \frac{1}{\xi} \log_{a} (1+ \xi) = 1 \\ \\ &\lim_{\xi \to 0} \ \log_{a} (1+ \xi) = \xi \\ \\ &\lim_{\xi \to 0} \ 1 + \xi = a^{\xi}\end{align} \] Raising both these expressions to the power $\frac{1}{\xi}$: \[ \lim_{\xi \to 0} \ (1+\xi)^{\frac{1}{\xi}} = a\] Now that limit should look familiar, we derived it earlier, it is $e$. The logarithm to base $e$ is very useful as it is easy to find derivatives of logarithms. The logarithm to base $e$ is given a special symbol $\log_{e} x = \ln x$

Some interesting properties

We established that $e$ is its own derivative, this means it can be differentiated infinitely, so it can be expressed as a Taylor expansion: \[ \exp(x) = 1 + x + \frac{1}{2}x^2 + \frac{1}{6} x^3 + \cdots \] To find $e$ we must set $x=1$, this simplifies the expansion down to: \[ e = 1 + 1 + \frac{1}{2} + \frac{1}{6} + \cdots \] or in sigma notation: \[ e = \sum_{k=0}^{\infty} \frac{1}{k!} \] The function $e^x$ is defined by the area under the curve $e^x$ so $e^x$ can be represented by the integral: \[ e^x = \int_{-\infty}^{x} e^x \ \mathrm{d}x \] So an expression of $e$ is: \[e = \int_{-\infty}^{1} e^x \ \mathrm{d}x\] The function $\ln x$ is defined by the area under the curve $\frac{1}{x}$. This can be used to form an interesting expression for 1: \[ \int_{1}^{e} \frac{1}{x} \ \mathrm{d}x = 1 \]

Monday 23 May 2011

Proof of Taylor expansion

Taylor's Theorem:

  • The function $f(x)$ is infinitely differentiable
  • The function $f(x)$ and all its derivatives exist at $x=\xi$
  • The function $f(x)$ can be expressed as a series of the form: \[ f(x) = \sum_{k=0}^{\infty} a_k (x-\xi)^k \]

Differentiating term by term: \[\begin{align*} f(x) &= a_0 + a_1(x-\xi) + a_2(x-\xi)^2 + \cdots \\ \\ f'(x) &= a_1 + 2a_2(x-\xi) + 3a_3(x-\xi)^2 + \cdots \\ \\ f''(x) &= 2a_2 + 2\times 3 a_3(x-\xi) + 3 \times 4 a_4(x-\xi)^2 +\cdots \\ \\ f'''(x) &= 2 \times 3 a_3 + 2 \times 3 \times 4 a_4 (x-\xi) + 3 \times 4 \times 5 a_5(x-\xi)^2 + \cdots \end{align*} \]

Solve for $f(x)$ around the point $x=\xi$: \[\begin{align*} f(\xi) &= a_0 \\ f'(\xi) &= a_1 \\ f''(\xi) &= 2a_2 \\ f'''(\xi) &= 2 \times 3a_3 \end{align*}\] this can be expressed more generally as: \[ f^{(k)}(\xi) = a_k k! \] so: \[ a_k = \frac{f^{(k)}(\xi)}{k!} \] Substituting this into the original series: \[ f(x) = \sum_{k=0}^{\infty} \frac{f^{(k)}(\xi)}{k!} (x-\xi)^k \] This is the Taylor expansion for a single variable.

A little more on the Taylor series:

  • In general the Taylor series is only valid in a small region of x values. Often the series will diverge if $|x-\xi| > 1 $, so in general the series is only valid for $ \xi - 1 \le x \le \xi + 1$. However this is not the case for all functions.
  • When the function $f(x)$ is not expanded completely there is some uncertainty in the expansion, this is denoted as: \[f(x) = S_n(x) + R_n (x)\] Where $S_n(x)$ is the sum of the first n terms and $R_n (x)$ is the sum of the remaining terms. As $n \to \infty $ : $S_n (x) \to f(x)$ and $R_n(x) \to 0$

Thursday 19 May 2011

Calculating π!

I'd imagine everyone is familiar with π, the mathematical constant that relates the diameter of a circle with its circumference. I'm also fairly sure most people can recite it to a fair number of decimal places. But how was π calculated? The Greek mathematician Archimedes was one of the first to approximate pi. He made use of the fact that: \[\pi = \frac{A}{r^2}\] He then used what is known as the method of exhaustion to calculate the area of the circle. This method involves using polygons with increasing numbers of sides to approximate the area of the circle. Wikipedia provided a nice example of this method:
This enabled him to approximate π to 3 decimal places.

Calculus and trigonometry


This post however is going to focus more upon using calculus to approximate π. So the obvious place to start is using trigonometry, specifically the inverse trigonometric functions. I started by finding the maclaurin series associated with arctan: \[\arctan x = x + \frac{x^3}{3} - \frac{x^5}{5} + \frac{x^7}{7} - \frac{x^9}{9} + \cdots \ \text{for} \ |x| \le 1\] Which can be expressed in sigma notation as: \[\sum_{k=0}^\infty \frac{(-1)^k x^{1+2k}}{1+2k} \ \text{for} \ |x| \le 1\] We can use the fact that $\arctan 1 = \frac{\pi}{4}$ to simplify the above sigma notation to approximate π \[ \pi = 4\sum_{k=0}^\infty \frac{(-1)^k}{1+2k} \] This is known as the Leibniz formula. It has a slow convergence; over 300 terms are needed to calculate the first 2 decimal places of π. The slow convergence is the result of the expansion being towards the end of the valid region of this taylor expansion, thus many terms are needed to accurately appoximate π.

Another trigonometric function that can be used is inverse sine. The maclaurin series of this function is: \[\arcsin x = x + \frac{x^3}{6} + \frac{3 x^5}{30} + \frac{5 x^7}{112} + \frac{35 x^9}{1152} + \cdots \ \text{for} \ |x| \le 1 \] Which can also be expressed in sigma notation as: \[ \sum_{k=0}^\infty \frac{(2k)! \ x^{1+2k}}{4^k(k!)^2(2k+1)} \ \text{for} \ |x| \le 1 \] As with inverse tan we can make use of the fact that $\arcsin \frac{1}{2} = \frac{\pi}{6}$ to simplify this series down to: \[ \pi = 6 \sum_{k=0}^{\infty} \frac{(2k)! \ (\frac{1}{2})^{1+2k}}{4^k(k!)^2(2k+1)} \] The approximation for π using this series converges more quickly due to the approximation being taken at 1/2. Whilst the inverse sine series has a much greater convergence it is inefficient due to the use of factorials. So improvements of the leibniz series would be better placed to accurately calculate π. I came across an interesting expression of π involving inverse tan purely by chance. But the convergence is much better than the previous series due to its position on the expansion. \[ \pi = 4\Big(\arctan \frac{1}{2} + \arctan \frac{1}{3}\Big)\]
Numerical Methods


A completely different approach to calculating π is to find the area under the curves that define the inverse trigonometry functions. I chose to use the integral that defines arctan: \[\pi = 4\int_0^1 \frac{1}{1+x^2}\ \mathrm{d}x\] This can be transformed into the left riemann sum: \[ \pi = \lim_{n \to \infty} \ 4 \sum_{k=0}^{n} \frac{1}{1+x_k^2} \times \frac{1}{n}\] By reducing n to a finite number this integral can be approximated. The same can be done with the right and middle riemann sums to approximate π. The issue is however that riemann sums make use of rectangles to approxmate the area under the integral. A more efficient and accurate approximation comes from the trapezoidal rule and Simpson's rule. Both of these provide better approximations for the area under the integral.

A practical comparison

So I've talked a lot about efficiency but what does that all mean in practice? Well I've written this script to let you trial strips on numerical integrals and terms in infinite integrals. Just type and number into the strips box and click calculate π. For the record:
\[ \pi = 3.14159265358979323846 \cdots \]
Series expansions

Method of Calculation Value of π
Leibniz formula
Magical Intuition
Term/Strip number:

*If you enter values larger than around 10 million it will start to lag.
Method of Calculation Value of π
Arcsin
Term/Strip number:

Arcsine will only function up to about 90 terms, this is due to the size of numbers the factorial function generates.

Numerical integration
Method of Calculation Value of π
Left Riemann Sum
Right Riemann Sum
Middle Riemann Sum
Trapezoidal Rule
Simpson's Rule
Term/Strip number:

*Simpson's rule is only valid for even numbers of strips and once again using more than about 10 million strips will cause it to lag.

Saturday 14 May 2011

Cyclic Integration

So I had a revelation recently on how to compute integration by parts that appear to be cyclic. Consider the function: \[ I = \int e^x \sin x \ \mathrm{d}x \] Integrating this by parts is trivial using the standard method: \[ \int u \frac{\mathrm{d}v}{\mathrm{d}x} \ \mathrm{d}x = uv - \int v \frac{\mathrm{d}u}{\mathrm{d}x} \ \mathrm{d}x \] Hence for the function I: \[ \begin{array}{rlc} u = e^x & \frac{\mathrm{d}v}{\mathrm{d}x} = \sin x \\ \frac{\mathrm{d}u}{\mathrm{d}x} = e^x & v = -\cos x \end{array} \] So: \[ I = -e^x \cos x + \int e^x \cos x \ \mathrm{d}x \] The end term must be integrated by parts again: \[ \begin{array}{rlc} u = e^x & \frac{\mathrm{d}v}{\mathrm{d}x} = \cos x \\ \frac{\mathrm{d}u}{\mathrm{d}x} = e^x & v = \sin x \end{array} \] So this is: \[ I = -e^x \cos x +e^x \sin x - \int e^x \sin x \ \mathrm{d}x \] But the final integral is the same as the original integral so this can be expressed as: \[ I = -e^x \cos x +e^x \sin x - I \] This is: \[ 2I = -e^x \cos x +e^x \sin x \] which means: \[I = \frac{1}{2}e^x(\sin x - \cos x) \]

Monday 2 May 2011

Dear facebook...

I keep seeing questions that say 9÷3(4-1) or something similar of the form a÷b(c-d). Everyone seems to assume that there is an answer to this question, but the use of deliberately ambiguous notation means there is not!

From the example above I could mean:
\[\frac{9}{3(4-1)} = 1\]
or
\[\Big(\frac{9}{3}\Big)(4-1) = 9\]
All of you who have done GCSE maths should be familiar with: BODMAS, BIDMAS, BEDMAS, take your pick there are a lot of mnemonics. These are the orders of operation, which are:

  • Brackets first
  • Indices (powers and roots) second
  • Multiplication and division third
  • Addition and subtraction last

But what people seem to forget is that all operations of each order are performed simultaneously, not from left to right. So questions like this have no answer, without more explicit notation they are meaningless.

What your calculator says is wrong...

What Google says is wrong...

Each of these will have had to interpret your ambiguous notation and will have either implicitly but brackets around one expression or have worked from left to right as it was probably programmed to do when notation was not explicit. This does not mean the answer it returned was right!


To summarise: the whole purpose of notation is make communication clear and explicit. Writing mathematical expressions such as the above is like removing all verbs from a sentence, you can attempt to guess at what it means. But different people will interpret the sentence differently, as with the above expression.

Try interpreting the following sentence, I doubt everyone will come up with the same answer. I've even been kind enough to show you where the verbs that I removed were.

"Paradoxically ____ may occur with an immediate increase in ____ after ____."