How does a calculator calculate sinx ?

Maths 1 Extension Notes
Not Examinable
How does a calculator calculate sin x ?
1
Polynomials
Most functions can be approximated by polynomials: an xn + an−1 xn−1 + . . . + a1 x + a0 .
To compute sin x, a calculator would evaluate such a polynomial.
x3
Example 1. Consider the function f (x) = x − .
6
To 4 decimal places of accuracy, we have
f (0) =
0
f (0.1) =
0.0998
f (0.2) =
0.1987
f (0.5) = 0.4792 ≈ 0.4794
f (1) = 0.8333 ≈ 0.8415
µ ¶
π
=
0.9248 ≈ 1
f
2
= sin(0)
= sin(0.1)
= sin(0.2)
= sin(0.5)
= sin(1)
µ ¶
π
= sin
.
2
We see that, for x close to 0, we have
x−
x3
≈ sin x.
6
Note that
f (x)
0
= x−
x3
6
x2
2
⇒
f (0)
=
0
0
f (x) = 1 −
⇒ f (0) =
1
00
00
f (x) =
−x ⇒ f (0) =
0
(3)
(3)
f (x) =
−1 ⇒ f (0) = −1
and if we let g(x) = sin x then
g(x)
g 0 (x)
g 00 (x)
g (3) (x)
=
sin x
=
cos x
= − sin x
= − cos x
⇒ g(0)
⇒ g 0 (0)
⇒ g 00 (0)
⇒ g (3) (0)
1
=
0
=
1
=
0
= −1
Therefore, if g(x) = sin x and f (x) = x −
x3
,
6
g(0)
g 0 (0)
g 00 (0)
g (3) (0)
then
=
=
=
=
f (0)
f 0 (0)
f 00 (0)
f (3) (0).
This special property of f (x) makes f (x) behave like sin x near x = 0, as shown in the graphs
given below:
2
Taylor polynomials
In general, for any differentiable function g(x), the Taylor polynomial
Pn (x) = g(0) + g 0 (0)x +
g 00 (0) 2
g (n) (0) n
x + ... +
x
2!
n!
satisfies
Pn (0)
Pn0 (0)
Pn00 (0)
..
.
(n)
Pn (0)
= g(0)
= g 0 (0)
= g 00 (0)
.
= ..
= g (n) (0)
and is (most of the time) a good approximation to g(x) when x is close to zero.
2
Note 2. Most calculators use something like Taylor polynomials to compute functions like
sin x, cos x, tan x, ex , etc.
Example 3. Consider the function g(x) = cos x. Then
g(x)
g 0 (x)
g 00 (x)
g (3) (x)
=
cos x
= − sin x
= − cos x
=
sin x
⇒ g(0)
⇒ g 0 (0)
⇒ g 00 (0)
⇒ g (3) (0)
=
1
=
0
= −1
=
0
Therefore
1
0
1
P3 (x) = 1 + 0x + − x2 + x3 = 1 − x2
2!
3!
2
is an approximation to cos x for x close to zero.
3
Taylor series
If we let n → ∞ for a Taylor polynomial Pn (x), we get a Taylor series. It can be shown that
x3 x5 x7
+
−
± ...
for all real x
3!
5!
7!
x2 x4 x6
cos x = 1 −
+
−
± ...
for all real x
2!
4!
6!
x
x2 x3
ex = 1 + +
+
+ ...
for all real x
1!
2!
3!
x2 x3 x4
ln(1 + x) = x −
+
−
± ...
for all real x.
2
3
4
It is interesting to note that, provided we add infinitely many terms, we have not just an
approximation, but an equality for most functions f (x). This means that we can make our
approximation as good as we like by adding enough terms.
sin x = x −
Example 4. If
x3 x5 x7 x9 x11
+
−
+
−
,
3!
5!
7!
9!
11!
then to 9 decimal places of accuracy, we have
f (x) = x −
f (1) = 0.841470985
and
sin(1) = 0.841470985,
and so f (x) is a good approximation to sin x when x is close to zero.
Note 5. The Taylor polynomials, that we have seen, give best results when x is close to
zero. If x is not close to zero then we need very high powers of x to get a good approximation.
In reality, calculators use a slightly different polynomial to approximate sin x. This other
polynomial is designed to give a good approximation even when x is not close to zero.
5
3
7
9
11
Example 6. Consider again f (x) = x − x3! + x5! − x7! + x9! − x11! .
Then f (6) = −2.0603 but sin(6) = −0.2794, and so we see that f (x) is not a good approximation to sin x when x = 6. This is because 6 is not close enough to zero. To get a better
approximation we need to include higher powers of x.
3
4
Finding square roots
We could use a Taylor series for f (x) =
least two other methods.
4.1
√
1 + x to find numbers like
√
2, but there are at
The method of progressive decimal places
The method of progressive decimal places is where we work out one decimal place at a time.
It is very accurate, but also very slow.
√
Example 7. Compute 4010.
We try and find a number x such that x2 = 4010. Note that
102 = 100 is too small
202 = 400 is too small
302 = 900 is too small
..
..
.
.
602 = 3600 is too small
702 = 4900 is too large
Since 70 is too large and 60 is too small, we know that x has to lie between 60 and 70.
Now note that
612
622
632
642
=
=
=
=
3721
3844
3969
4096
is
is
is
is
=
=
=
=
3981.61
3994.24
4006.89
4019.56
too
too
too
too
small
small
small
large.
Thus x has to lie between 63 and 64.
We now try decimal places for x
63.12
63.22
63.32
63.42
is
is
is
is
too
too
too
too
small
small
small
large,
and so x = 63.3 . . .
We can continue this process for as many decimal places as we wish!
4
4.2
Newton’s Method
√
√
Note that x = a ⇒ x2 = a ⇒ x2 − a = 0. Therefore, to find a, we can just solve
x2 − a = 0 for x, by using a numerical method like Newton’s Method.
Theorem 8. (Newton’s Method.) The equation f (x) = 0 can be solved by guessing an
approximate solution x0 and then iterating
xi+1 = xi −
f (xi )
.
f 0 (xi )
The sequence x0 , x1 , x2 , . . . normally has the property that xi+1 is a better approximation
than xi .
√
Example 9. Let’s find 2. We need to solve x2 − 2 = 0. Let f (x) = x2 − 2. Then
f 0 (x) = 2x. By Newton’s Method, we need to iterate
x2i − 2
2xi
xi
1
= xi − +
2
xi
1
xi
+ .
=
2
xi
xi+1 = xi −
We start with the initial approximation x0 = 2. We have
x0 = 2
x0
1
2 1
3
x1 =
+
= + =
2
x0
2 2
2
3
1
1
x1
17
+
= 2 + 3 =
x2 =
2
x1
2
12
2
x3
17
x2
1
1
577
=
+
= 12 + 17 =
.
2
x2
2
408
12
√
577
= 1.41421568627450980 and 2 = 1.41421356237309505, and so we can see
Now 408
√
that we have already got a good approximation to 2. One more iteration gives
√ x4 =
1.41421356237468991, and so we can see that
this
method
converges
very
quick
to
2. Fur√
thermore, we can use this method to find x for any value of x (not just values of x that
are close to zero).
It is likely that calculators use a method similar to this for calculating square roots.
4.3
Finding nth roots
In general, we can find the nth root
Method, this leads to iterating
√
n
xi+1 =
a of a by solving xn − a = 0. By using Newton’s
a
n−1
xi + n−1 .
n
nxi
5