2

I'm trying to calculate the following sum: $C_n = \sum_{k=0}^{n} \cos\left(\dfrac{2k\pi}{2n+1}\right)$

In order to get hints, I programmed the following code in Python:

from math import *
def C(k,n):
    return cos((2*k*pi)/(2*n+1))

S = 0.0
n = int(input("choose a value for n: "))

while(True):
    for k in range(n+1):
        S += C(k,n)
        print('step ', k,' is S = ',S)
    S = 0.0
    print('\n\n')
    n = int(input("choose a value for n: "))

The sums all end up equal to 0.5. Wolfram Alpha agrees.

I..don't.. I tried to express the cosine as $\dfrac{e^{i\frac{2k\pi}{2n+1}}+e^{-i\frac{2k\pi}{2n+1}}}{2}$, then extract the $k$ as a power like so: $\sum_{k=0}^{n}\dfrac{ \left( e^{i\frac{2\pi}{2n+1} }\right)^k+ \left(e^{-i\frac{2\pi}{2n+1}} \right)^k }{2}$

$= \dfrac{1}{2} \sum_{k=0}^{n} \left(e^{i\frac{2\pi}{2n+1}}\right)^k +\left(e^{-i\frac{2\pi}{2n+1}} \right)^k$

That way, if I'm correct, those two terms are each a sum of terms of a geometric series. While a $\dfrac{1}{2}$ does appear later on as separate term, this approach seems to create more problems than it solves.

I would be grateful for any pointers :) Thanks in advance.

Bernard
  • 175,478
DeltaXY
  • 107

2 Answers2

2

It is always by the same fashion

$$\begin{aligned} 2\sin\left(\frac{\pi}{2n+1}\right)\sum_{k=0}^{n}\cos\left(\frac{2k\pi}{2n+1}\right) & = \sum_{k=0}^{n} \left(\sin\left(\frac{2k+1}{2n+1}\pi\right) - \sin\left(\frac{2k-1}{2n+1}\pi\right)\right)\\ & = \sin\left(\frac{2n+1}{2n+1}\pi\right) - \sin\left(-\frac{\pi}{2n+1}\right)\\ & = \sin\left(\frac{\pi}{2n+1}\right) \end{aligned}$$

hence $C_{n}=\frac1{2}$

1

With $z:=\exp\frac{i2\pi}{2n+1}$,$$C_n=\frac12\left(\frac{1-z^{n+1}}{1-z}+\frac{1-z^{-n-1}}{1-z^{-1}}\right)=\frac{(1-z^{n+1})(1+z^{-n})}{2(1-z)}=\frac12+\frac{z^{-n}-z^{n+1}}{2(1-z)}.$$But the last term vanishes because $z^{2n+1}=1$.

Incidentally, I recommend a few clean-code changes:

from math import cos, pi

twopi = 2*pi
while(True):
    n = int(input('choose a value for n: '))
    S, denominator = 0, 2*n+1
    for k in range(n+1):
        S += cos(k*twopi/denominator)
        print(f'step {k} is S = {S}')#This f-string requires Python 3.6 or later.
    print('\n\n')
J.G.
  • 115,835