Let's say we want a find a polynomial (\(f(x)\) that can give the approximate values of \(e^x\) for \(x\) values very close to 0.
A polynomial is of the form:
\[ c_0 + c_1 x + c_2 x^2 + c_3 x ^3 + \cdots + c_n x^n \]
We will represent this as \(f_n(x)\), where \(n\) represents the degree of the polynomial:
\[ f_n(x) = c_0 + c_1 x + c_2 x^2 + c_3 x ^3 + \cdots + c_n x^n \]
If we want \(f(x)\) to approximate \(e^x\) near \(x=0\). A good place to start would be to make sure \(f(x)=e^x\) when \(x=0\):
\[\begin{gather} f(0) = c_0 + c_1 (0) + c_2 0^2 + \cdots + c_n 0^n = e^0 \\ c_0 = 1 \end{gather}\]
This means:
\[ f_n(x) = 1 + c_1 x + c_2 x^2 + c_3 x ^3 + \cdots + c_n x^n \]
The graph below shows \(f_0(x)\) (purple line):
For \(x\) values very close to 1, you could say \(e^x \approx f_0(x)\), but we can do better. Let's say we also want the derivative of \(f(x)\) to be equal to the derivative of \(e^x\) at \(x=0\):
\[\begin{align} & \frac{d f(x)}{dx} = c_1 + (2)c_2 x + (3)c_3 x^2 + (4)c_4 x^3 + \cdots + (n)c_n x^{n-1} \\ & \left. \frac{d f(x)}{dx} \right\rvert_{x=0} = c_1 = \left. \frac{d e^x}{dx} \right\rvert_{x=0} \implies c_1 = 1 \end{align}\]
This means:
\[ f_n(x) = 1 + x + c_2 x^2 + c_3 x ^3 + \cdots + c_n x^n \]
The graph of \(f_1(x)=1 + x\) looks like:
The purple line has both the value and the first derivative equal to \(e^x\) at \(x=0\). Now let's try to make the second derivative of \(f(x)\) equal to the second derivative of \(e^x\) at \(x=0\):
\[\begin{align} & \left( \frac{d}{dx} \right)^2 f(x) = (2)c_2 + (3)(2)c_3 x + (4)(3)c_4 x^2 + \cdots + (n)(n-1)c_n x^{n-2} \\ & \left. \left( \frac{d}{dx} \right)^2 f(x) \right\rvert_{x=0} = (2)c_2 = \left. \left( \frac{d}{dx} \right)^2 e^x \right\rvert_{x=0} \implies c_2 = \frac{1}{2} \end{align}\]
This means:
\[ f_n(x) = 1 + x + \frac{x^2}{2} + c_3 x ^3 + \cdots + c_n x^n \]
The graph of \(f_2(x)=1 + x + \frac{x^2}{2}\) looks like:
Let's try the same with the third derivative:
\[\begin{align} & \left( \frac{d}{dx} \right)^3 f(x) = (3)(2)c_3 + (4)(3)(2)c_4 x + (5)(4)(3)c_5 x^2 + \cdots + (n)(n-1)(n-2)c_n x^{n-3} \\ & \left. \left( \frac{d}{dx} \right)^3 f(x) \right\rvert_{x=0} = (3)(2)c_3 = \left. \left( \frac{d}{dx} \right)^3 e^x \right\rvert_{x=0} \implies c_3 = \frac{1}{3!}\end{align}\]
If we repeat this process till the tenth derivative, we get:
\[ f_{10}(x) = 1 + x + \frac{x^2}{2} + \frac{x ^3}{3!} + \frac{x ^4}{4!} + \frac{x ^5}{5!} + \cdots + \frac{x ^{10}}{10!} \]
If we graph this:
This seems like a really good approximation.
Let's try to do something similar with \(\sinh(x)\). We want a polynomial \(f_n(x)\) to would approximate the values of \(\sinh(x)\) near \(x=0\). Let's start with equating \(f(0)\) and \(\sinh(0)\):
\[\begin{gather} f(x) = c_0 + c_1 x + c_2 x^2 + c_3 x ^3 + \cdots + c_n x^n \\ f(0) = c_0 = \sinh(0) \end{gather}\]
Now let's try the equate the derivative at 0 (keep in mind \(\frac{d}{dx} \sinh(x) = \cosh(x)\)):
\[\begin{gather} f(x) = \sinh(0) + c_1 x + c_2 x^2 + c_3 x ^3 + \cdots + c_n x^n \\ f'(x) = c_1 + (2)c_2 x + (3)c_3 x^2 + \cdots + (n)c_n x^{n-1} \\ f'(0) = c_1 = \cosh(0) \end{gather}\]
Now let's try the equate the second derivative at 0 (keep in mind \(\frac{d}{dx} \cosh(x) = \sinh(x)\)):
\[\begin{gather} f(x) = \sinh(0) + \cosh(0)x + c_2 x^2 + c_3 x ^3 + \cdots + c_n x^n \\ f''(x) = (2)c_2 + (3)(2)c_3 x + \cdots + (n)(n-1)c_n x^{n-2} \\ f''(0) = (2)c_2 = \sinh(0) \implies c_2 = \frac{\sinh(0)}{2} \end{gather}\]
Now let's try the same with the third derivative:
\[\begin{gather} f(x) = \sinh(0) + \cosh(0)x + \frac{\sinh(0)}{2} x^2 + c_3 x ^3 + \cdots + c_n x^n \\ f^{(3)}(x) = (3)(2)c_3 + + (4)(3)(2) x + (5)(4)(3)x^2 + \cdots + (n)(n-1)(n-2)c_n x^{n-3} \\ f^{(3)}(0) = 3! c_3 = \cosh(0) \implies c_3 = \frac{\cosh(0)}{3!} \end{gather}\]
If we try this many times:
\[\begin{gather} f(x) = \sinh(0) + \cosh(0)x + \frac{\sinh(0)}{2} x^2 + \frac{\cosh(0)}{3!} x^3 + \frac{\sinh(0)}{4!} x^4 + \cdots \\ f(x) = x + \frac{x^3}{3!} + \frac{x^5}{5!} + \frac{x^7}{7!} \cdots \end{gather}\]
Let's see how good this is as an approximation just with the first three terms (notice the scaling of the x-axis and y-axis):
Given an arbitrary function \(g(x)\) which can be differentiated infinite times. We can find approximate values of \(g(x)\) near \(x=0\) by using the formula:
\[ g(0) + g'(0)x + \frac{g''(0)}{2!}x^2 + \frac{g^{(3)}(0)}{3!}x^3 + \frac{g^{(4)}(0)}{4!}x^4 + \cdots\]
An infinite series which tries to approximate the values of a function around \(x=0\) by equating the function at 0 and equating all orders of derivatives at 0 is called a Maclaurin series. Sometimes this is a very good approximation when \(x\) is close to 0, and sometimes it's not a good approximation at all. Also, notice that in the Maclaurin series, when we take the \(i\)th derivative and let \(x=0\), we are left with \([(i!)c_i]\).
Let's take this a step further, can we find an approximation for g(x) at \(x=a\) where \(a\) can be any real number in the domain of \(g\)? This "general" version of the Maclaurin series is called the Taylor series.
Let \(h(x)=g(x+a)\), and let \(p(x)\) be an approximation for \(h(x)\) near \(x=0\).
\[\begin{align} p(x) &\approx h(x) \\ p(x) &\approx g(x+a)\end{align}\]
We can use the Maclaurin series to represent \(p\):
\[ p(x) = h(0) + h'(0)x + \frac{h''(0)}{2!}x^2 + \frac{h^{(3)}(0)}{3!}x^3 + \frac{h^{(4)}(0)}{4!}x^4 + \cdots \]
Since \(h(x) = g(x+a)\), then, when \(x=0\):
\[\begin{align} p(x) &= g(a) + g'(a)x + \frac{g''(a)}{2!}x^2 + \frac{g^{(3)}(a)}{3!}x^3 + \frac{g^{(4)}(a)}{4!}x^4 + \cdots \\ g(x+a) &\approx g(a) + g'(a)x + \frac{g''(a)}{2!}x^2 + \frac{g^{(3)}(a)}{3!}x^3 + \frac{g^{(4)}(a)}{4!}x^4 + \cdots \end{align}\]
Let \(z = x+a\):
\[\begin{align} g(z) &\approx g(a) + g'(a)(z-a) + \frac{g''(a)}{2!}(z-a)^2 + \frac{g^{(3)}(a)}{3!}(z-a)^3 + \frac{g^{(4)}(a)}{4!}(z-a)^4 + \cdots \end{align}\]
The equation above is the Taylor series, it is of the form \(\sum^{\infty}_{i=0} \frac{g^{(i)}(a)}{i!} (x-a)^i\), where the approximation is around to \(x=a\).
For example, let's say we want to calculate \(\sin(x)\) for \(x\) values close to \(a\), and let's say \(\sin(a)\) and \(\cos(a)\) is known to to us.
We want to find a polynomial \(f_n(x)\) of the form below that can be used to get an approximation of \(\sin(x)\) around \(a\). Let's try to use \(f_n(x)\) to approximate \(\sin(x)\) at \(x=a\):
\[ f_n(x) = c_0 + c_1 (x-a) + c_2 (x-a)^2 + \cdots + c_n (x-a)^n \]
Firstly, we want \(f_n(a) = \sin(a)\):
\[ f_n(x) = \sin(a) + c_1 (x-a) + c_2 (x-a)^2 + \cdots + c_n (x-a)^n \]
Is \(f_0(x) = \sin(a)\) a good approximation for \(\sin(x)\) when \(x\) is near \(a\)? If \(a= \frac{2 \pi}{3}\):
\[\begin{align} x &&(2\pi)/3 - 0.01 && (2\pi)/3 && (2\pi)/3 + 0.01 \\ f_0(x) &&0.866 &&0.866 &&0.866 \\ \sin(x) &&0.8710 &&0.866 &&0.8610 \end{align}\]
The graph \(f_0(x)\) (purple line) looks like:
Can we do better? Let' say we also want the derivative of \(f(x)\) to be equal the derivative of \(\sin(x)\) at \(x=a\):
\[\begin{gather} f_n(x) = \sin(a) + c_1 (x-a) + c_2 (x-a)^2 + \cdots + c_n (x-a)^n \\ \left. \frac{d f_n (x)}{dx} \right\rvert_{x=a} = c_1 = \left. \frac{d \sin(x)}{dx} \right\rvert_{x=a} \implies c_1 = \cos(a) \end{gather}\]
Is \(f_1(x) = \sin(a) + \cos(a)(x-a) \) a good approximation for \(\sin(x)\) when \(x\) is near \(a\)? If \(a= \frac{2 \pi}{3}\):
\[\begin{align} x &&(2\pi)/3 - 0.01 && (2\pi)/3 &&(2\pi)/3 + 0.01 \\ f_1(x) &&0.87103 &&0.866 &&0.86103 \\ \sin(x) &&0.87098 &&0.866 &&0.86098 \end{align}\]
The graph \(f_1(x)\) looks like:
Can we do better? Let' say we also want the second derivative of \(f(x)\) to be equal the derivative of \(\sin(x)\) at \(x=a\):
\[\begin{gather} f_n(x) = \sin(a) + \cos(a) (x-a) + c_2 (x-a)^2 + \cdots + c_n (x-a)^n \\ \left. \frac{d^2 f_n (x)}{(dx)^2} \right\rvert_{x=a} = 2c_2 = \left. \frac{d^2 \sin(x)}{(dx)^2} \right\rvert_{x=a} \implies c_2 = -\frac{\sin(a)}{2} \end{gather}\]
If \(f_2(x) = \sin(a) + \cos(a)(x-a) - \frac{\sin(a)}{2}(x-a)^2\), then \(f_2(a) = \sin(a)\), \(f_2'(a) = \cos(a)\) and \(f_2''(a) = -2\sin(a)\).
The graph \(f_2(x)\) looks like:
Let's try to do the same with the third and fourth derivative.
\[ \begin{gather} \left. \frac{d^3 f_n (x)}{(dx)^3} \right\rvert_{x=a} = (3)(2) c_3 = \left. \frac{d^3 \sin (x)}{(dx)^3} \right\rvert_{x=a} \implies c_3 = -\frac{\cos(a)}{(3)(2)} \\ \left. \frac{d^4 f_n (x)}{(dx)^4} \right\rvert_{x=a} = (4)(3)(2) c_4 = \left. \frac{d^4 \sin (x)}{(dx)^4} \right\rvert_{x=a} \implies c_4 = \frac{\sin(a)}{(4)(3)(2)} \end{gather} \]
This means \(f_4(x)\) looks like this:
\[ f_4(x) = \sin(a) + \cos(a)(x-a) - \frac{\sin(a)}{2}(x-a)^2 - \frac{\cos(a)}{3!}(x-a)^3 + \frac{\sin(a)}{4!}(x-a)^4\]
Is \(f_4(x)\) a good approximation for \(\sin(x)\) when \(x\) is near \(a\)? If \(a= \frac{2 \pi}{3}\):
\[\begin{align} x &&(2\pi)/3 - 0.04 &&(2\pi)/3 - 0.02 && (2\pi)/3 &&(2\pi)/3 + 0.02 &&(2\pi)/3 + 0.04 \\ f_4(x) &&0.885327342504 &&0.875851537811 &&0.866 &&0.855852871144 &&0.845338009171 \\ \sin(x) &&0.885327342926 &&0.875851537824 &&0.866 &&0.85585287113 &&0.845338008739 \end{align}\]
The graph \(f_4(x)\) looks like:
You can probably now guess what the formula for \(f_n(x)\) would be:
\[ \begin{align} f_n(x) = &f(a) + f'(a)(x-a) + \frac{f''(a)}{2}(x-a)^2 + \\ &\frac{f'''(a)}{3!}(x-a)^3 + \frac{f^{(4)}(a)}{4!}(x-a)^4 + \cdots + \frac{f^{(n)}(a)}{n!}(x-a)^n \end{align} \]
This is an example of a Taylor polynomial.
We chose \(f(x)\) to be a polynomial with finite terms, but what if we let \(f(x)\) be a power series (i.e. have infinite terms)?
\[ f(x) = \sum^{\infty}_{n=0} \frac{f^{(n)}(a)}{n!}(x-a)^n \]
This is called the Taylor series. If \(a=0\), then it is also called the Maclaurin series.