Building approximations for sin(x)
Build up the concept of the Taylor series
Problem
We first encounter the function sin(x) when using right-angled triangles, where sine of an angle is defined to be the ratio of the length of the side opposite the angle to the length of the hypotenuse. Clearly this ratio must give a number which varies continuously between 0 and 1 as the angle varies from 0 to 90 degrees .
However, your calculator will give you a value of sin(x) for any value of x you care to choose, no matter how big or small. Calculators do not do this by 'drawing triangles'. Instead they approximate sin(x) by a polynomial function. In this problem we shall investigate the properties of these polynomials.
Look at an approximation by a cubic polynomial:
$$ \sin(x)\approx a + b x + c x^2+ d x^3\quad\quad\mbox{where }\, a, b, c \,\mbox{ and } \, d \,\mbox{ are constants} $$ (where $x$ is in radians). By experimenting with the numerical values of $\sin(x)$ what values would you suggest for the constants?
[Aside: Why is it not
possible to 'solve' for these constants?]
Extend your solution to 4th, 5th and higher order polynomials.
Test the accuracy of your final solution over a range 0 to $\pi$ radians.
Why is it sufficient to work within this range?
Extension : Repeat this challenge to find approximations for $\cos(x)$ and $\log(1+x)$.
Discussion point : Why does it make sense to be able to approximate $\sin(x)$ by a polynomial? What other functions do you think would have polynomial approximations? Do you think that all functions can be approximated by polynomials?
Getting Started
As a brute force approach you can choose 4 values of x, work out sin(x) and then solve the 4 simultaneous equations in 4 variables. This will give a polynomial which matches the values for your choices of x.
However, you can save time by noting the symmetry properties of sin(x), in that sin(-x) = - sin(x).
Student Solutions
Aleksander from Gdynia Bilingual High School No 3, Poland used the properties of the sine function to find a polynomial approximation.
As we know, polynomials are one of the most flexible functions
and hence, can have very different shapes. They are probably the
most flexible functions you can find, thus we can state a
hypothesis that every function can be approximated by a polynomial
of an appropriately high degree. Let's now consider sine, the
functions that is very difficult to calculate and thus we usually
need its approximation. In the beginning let's find coefficients in
the following expression: $$\sin x \approx a + bx +cx^2 +dx^3.$$
Let's make a few observations:
(1) Sine is an odd function
(2) $\sin [0]=0$
(3) For sufficiently small $x$, $\sin x \approx x$.
Polynomials are odd only if coefficients of even powers of $x$
are equal to 0.
From the statements above we have:
$\sin (0) = 0 \Rightarrow a=0$
From (3), $b=1$\\ From (1), $c=0$.
After simplification $\sin x \approx x +dx^3$. Taking $x =
{\pi \over 6}$ and $\sin x = 0.5$ a simple calculation gives $d = -
0.1643968$ which is close to $d = -{1\over 6}$ and we have $\sin x
\approx x - {x^3 \over 6}$.
To get approximation of $\sin x$ using polynomials of higher
degrees, we have to remember that coefficients of even powers
should be equal to 0. For that reason the next degree of a
polynomial that can be used here is the 5th.
Andrei from Romania used the Taylor series and drew graphs to show the polynomial approximations .
To solve this problem, I use the Taylor series expansion around the origin. I see that the derivatives of $f(x) = \sin x $ are: $$\eqalign{ f^{4k}(x) &= \sin x \cr f^{4k+1}(x) &= \cos x \cr f^{4k+2}(x) &= -\sin x \cr f^{4k+3}(x) &= -\cos x }.$$ The formula for the Taylor expansion is: $$f(x) = f(x_0) + {(x - x_0)\over 1!}f'(x_0)+ {(x - x_0)^2\over 2!}f''(x_0)+... + {(x - x_0)^k\over k!}f^{(k)}(x_0)+ ...$$ Evidently, the odd-order derivatives are 0 for $x_0=0$. So, $\sin x$ could be written around the origin as: $$\sin x = x - {x^3\over 3!} + {x^5\over 5!} - {x^7\over 7!} + ...$$ The simplest method to test the accuracy of the series expansion is to represent on the same graph the function and its different order expansions.Image
The function sin(x) is represented in white, the first order polynomial in red, the third in cyan, the fifth in green and the seventh in yellow. It can be observed that the accuracy is better and better. As the order of the polynomial increases, the accuracy increases.
It is remarkable that, using only up to the seventh order polynomial, I obtain a very good approximation of the function. Sin is a periodic function and so it is sufficient to work on the interval $[-\pi, \pi]$, and, observing that sin is an odd function the interval $[0, \pi]$ is enough. Around $\pi$, in fact I should use the expansion of the function around this value. This is equivalent to moving the y-axis $\pi$ to the right.
I work in a similar manner for $\cos x$ and $\log (1+x).$ For $\cos x$, the MacLaurin series expansion is: $$\cos x = 1 - {x^2\over 2!} + {x^4\over 4!} - {x^6\over 6!} +...$$
Image
The function is in blue, the second order polynomial in violet, the fourth - in white and the sixth in red. I see that the sixth order polynomial is a rather good approximation on the whole interval.
As cos is periodic, the interval $[-\pi, \pi]$ is sufficient, and more, as cos(x) is even $[0, \pi]$ is enough.
For, $\log (1+x)$, I consider the logarithm to the base e. Here, I obtain the following MacLaurin series expansion: $$\log (1+x) = x - {x^2\over 2} + {x^3\over 3} - {x^4\over 4} + {x^5\over 5} ...$$
Image
Here, the colours of the curves are as follows: violet for the function, white for the first order approximation, red for the second, cyan for the third, green for the fourth and yellow for the fifth.
In this case, the approximations are good only on a small interval around the origin. I think that for approximations of the function valid on different intervals, I have to use the series expansion around the chosen point. So, around x=1: $$\log (1 + x) = \log 2 + {x-1\over 2} - {(x-1)^2\over 2^3} + {(x-1)^3\over 24} - {(x-1)^4\over 64} + {(x-1)^5\over 160}1 ...$$
Image
The colours are as follows: the function in red, the first order polynomial in cyan, the second order one in green, the third in yellow, the fourth in blue, and the fifth in violet.
Teachers' Resources
In general, any function whose derivatives of all orders are finite can be written as a power series
$$f(x) = f(0) + x f'(0) + \frac{x^2}{2!}f''(0) + \dots + \frac{x^n}{n!}f^{(n)}(0)+\dots$$
This expansion is an infinite series (not a polynomial).
Truncating this series at a given point provides us with a
polynomial approximation to f(x).
The question of how big the errors are in this approximation
is a difficult one to answer, and more details will be discovered
at university in Numerical Analysis courses.