Series for sin(x)
The function sin(x) has a well-known polynomial approximation.
sin(x) ≈ x - x3/6 + x5/120 - ...
This polynomial is produced by matching the function value, and then successively higher derivatives, at x=0. It is the result of the well-known Taylor expansion.
There are other approaches to finding polynomials to approximate sin(x). For instance, consider the roots of sin(x). They occur at x=nπ, where n is an integer. What would a polynomial which reproduces the roots at zero and ±π look like? It would be written most naturally as
where A is an arbitrary scaling constant. But we can also choose to write this, for a particular value of A, as
The next two roots of sin(x) are at x=±2π, so the polynomial which reproduces these five roots would be
Remembering that (a+b)(a-b)=a2-b2, this can be written more compactly as
This is generating a polynomial approximation to sin(x) not as a sum of terms, but as a product of terms, with the nth term of the product being
How can we quickly see how good these approximations are? Here we demonstrate the use of python with matplotlib, and also of the free, dedicated graphing program Gnuplot.
Gnuplot, if installed, is started by simply
gnuplot. It is not installed by default with
Raspbery Pi OS, although it is in the standard package repository,
so one may need to type
$ sudo apt-get install gnuplot
to install it. Here we compare the series above with just two terms each.
$ gnuplot G N U P L O T gnuplot> plot [-4:4][-2:2] x-x**3/6,x*(1-x*x/(pi*pi)),sin(x)
The functions to plot are separated by commas, the
** is the power operator, and the x and y
ranges are explicitly given in square brackets before the functions.
As one might have predicted, the product approximation starts to diverge visibly from sin(x) first, but it does get the roots at ±π precisely correct, so for values around ±π it is a better approximation than the Taylor sum.
If one then moves to including the first three terms in each series, the result is:
gnuplot> plot [-4:4][-2:2] x-x**3/6+x**5/120,x*(1-x*x/(pi*pi))*(1-x*x/(4*pi*pi)),sin(x)
Now the surprise is that the Taylor approximation has just a single
root at the origin, but does not cross the y axis anywhere else,
whereas the product approximation now crosses it five times. Try
setting the range to
[-8:8][-3:3] to see this.
Which approximation is better? It depends which properties of sin(x) it is important to retain in any given situation.
People familiar with matplotlib might prefer to use it, rather than Gnuplot.
$ ipython3 In : import matplotlib.pyplot as plt In : import numpy as np In : x=np.linspace(-4,4,200) In : plt.plot(x,x-x**3/6,'r') Out: [<matplotlib.lines.Line2D at 0x7f5589172ef0>] In : plt.plot(x,x*(1-x*x/(np.pi*np.pi)),'b') Out: [<matplotlib.lines.Line2D at 0x7f5589103e48>] In : plt.plot(x,np.sin(x),'k') Out: [<matplotlib.lines.Line2D at 0x7f5589115a90>] In : plt.show()
One then has to close the plot window in order to use the python window again. And, to repeat something like the second Gnuplot example,
x=np.linspace(-8,8,200) plt.plot(x,x-x**3/6+x**5/120,'r') plt.plot(x,x*(1-x*x/(np.pi*np.pi))*(1-x*x/(4*np.pi*np.pi)),'b') plt.plot(x,np.sin(x),'k') plt.ylim(-3,3) plt.grid(True) plt.show()
The website GeoGebra offers very good online graphing.
Geogebra is also available as a stand-alone application. Like Gnuplot, it is in the default Raspberry Pi OS repository, it is just not installed by default, so one has to install it explicitly.
sudo apt-get install geogebra
The coefficient of x in both series is one. The coefficient of x3 in the Taylor series is 1/6, whereas for the product it depends on how many terms are included. It initially appears as 1/π2, but changes as more terms are added. Calling this coefficient c3, one can write
Given that we know that c3 should ultimately be 1/6, this suggests that the sum of the reciprocals of the squares of the positive integers is π2/6. There may be plenty of caveats about the use of infinite series in this "proof", but the answer is correct.