Thursday, August 27, 2009

Series for sine and cosine


You probably know that the sine and cosine functions can also be given as a series:

sin(x) = x - x3/3! + x5/5! - x7/7! ...

cos(x) = 1 - x2/2! + x4/4! - x6/6! ...


And furthermore, that the exponential function can also be given as a series:

ex = 1 + x/1! + x2/2! + x3/3! + x4/4! ...


These series are really interesting. One reason is that they make clear that the formulas for the derivatives of these functions are obviously correct.

Take e first:
ex      = 1 + x/1! + x2/2! + x3/3! + x4/4! ...

d/dx ex = 0 + 1/1 + 2x/2 + 3x2/(3*2!) + 4x3/(4*3!) ...
= 1 + x/1! + x2/2! + x3/3! ...
= ex


Now, the sine:

sin(x) = x - x3/3! + x5/5! - x7/7! ...

d/dx sin(x) = 1 - 3x2/3*2! + 5x4/5*4! - 7x6/7*6! ...
= 1 - x2/2! + x4/4! - x6/6! ...
= cos(x)


That's really spectacular. So the question I had was: where do these series come from. And I'm not sure this is the only way, but I think they come from a Taylor series. The Taylor series approximates a function f(x) at a particular point x = a by the series:

f(x) ≈ Σ (n=0 to n=∞) f(n)(a)/n! * (x-a)n


where f(n)(a) is the nth derivative of f(x). For ex, all of these derivative terms are just ex. Evaluating the series for a = 0 these derivatives are 1, and the series becomes (as we had above):

f(x) ≈ Σ (n=0 to n=∞) xn / n!


Now, I still have a couple of problems. For example, in order to get the terms of the Taylor series for sine and cosine we will have to know the derivatives, which is also what we seek, so that is a circular argument. Also, I'm not very clear on what the a is about. The approximation to f(x) works for the "neighborhood of a."

R code:
plot(1:2*pi,ylim=c(-1.2,1.2),type='n')
curve(sin,from=0, to=2*pi,
col='blue',lwd=5)
curve(cos,from=0, to=2*pi,
col='red',lwd=5,add=T)
lines(c(0,2*pi),c(0,0),lty=2,lwd=3)

No comments: