# Need advice on approximating the sum of a trigonomitric series which (I think) has no analytical solution

I've encountered a maths problem in a programming project I'm working on. I've tried a lot of things already, and I'm feeling very swamped with maths that is way above my head.

I need to find:

$$f_N(x) = \sum_{n=1}^N cos(n^2x)$$

Now I've discovered I can use de Moivre's theorum and express this as the real part of an exponential series

$$Re\{ \sum_{n=1}^N e^{in^2x} \}$$

After some investigation I don't believe there is an analytical solution for this, so I'm not sure it's useful.

Numerical appromimations are better than the brute force approach I'm currently using as speed is far more importent than accuracy for my use case.

I believe what I'm looking for is the Taylor expansion of the first equation - however I have no idea how to approach finding the Taylor expansion of a sum to n. Maybe it's not possible? Googleing hasn't helped me here, searching "Taylor expansion of a finite series" just comes up with results for "Taylor series".

I think that maybe what I can do is find the derivatives of $$f_N(x)$$ use those as the terms in the Taylor series. I have a few questions:

• Am I correct in saying that the second equation doesn't have an analytical solution?
• Is using the Taylor expansion by finding the derivatives of the series the correct approach? (UPDATE: Just found this, which is for a polynomial rather than a trigonometric function, but leads me to believe that this method is valid. UPDATE 2: not possible, coefficients in the taylor expansion are themselves a series)
• If so, does anyone have any examples of a Taylor expansion of a series that I could look at?
• If not, what alternatives should I be looking at for finding a numerical approximation?

UPDATE: I should add that x is small, $$0 < n^2x < \pi$$ which should make approximations easier

Thanks!

PS: I'm not a mathematician (which I'm sure is obvious!) and it has been a long time since I was at uni - would really appreciate answers in the form a comp-sci undergraduate could understand (to the extent to which that is possible!)

• Have you consider approximating this via an integral instead. Look up Fresnel integral Commented May 14, 2022 at 13:12
• I will have a look at that, thanks!
– Newt
Commented May 14, 2022 at 13:20
• $f(x)=\sum_{i=1}^n cos(n^2 x)=n\,cos(n^2 x)$. I assume you mean $f(x)=\sum_{i=1}^n cos(i^2 x)$ or $f(x)=\sum_{i=1}^n cos(i n^2 x)$? Commented May 14, 2022 at 14:48
• Yes! Edited it now.
– Newt
Commented May 14, 2022 at 14:50
• Sorry. Better now?
– Newt
Commented May 14, 2022 at 14:56

It looks like:

$$\sum_{n=1}^N \cos(n^2x)= \text{Re}\sum_{n=1}^N e^{i x n^2}$$

Now a difference:

$$\sum_{n=0}^b a_n=\sum_{n=0}^\infty a_n-\sum_{n=b}^\infty a_n\implies \text{Re}\sum_{n=1}^N e^{i x n^2} = \text{Re}\sum_{n=1}^\infty e^{i x n^2} - \text{Re}\sum_{n=N}^\infty e^{i x n^2}$$

So the general idea is to:

$$\text{Re}\sum_{n=1}^\infty e^{i x n^2} - \text{Re}\sum_{n=N}^\infty e^{i x n^2}= \text{Re}\sum_{n=1}^\infty e^{i x n^2} - \text{Re}\sum_{n=0}^\infty e^{i x (n+N)^2}$$

Now use Jacobi theta functions

However, an infinite sum, by itself, may diverge

Please correct me and give me feedback!

• Thanks for this - might take me a while to make sense of those Jacobi theta functions!
– Newt
Commented May 14, 2022 at 16:05
• @Newt I do not know much about them either, but they still are useful for similar problems. Commented May 14, 2022 at 16:06
• I'm wondering if a closed form is really useful. Is there a more efficient way to approximate an elliptic theta function which is an infinite series rather than just evaluating the original sum which is a finite series? Commented May 14, 2022 at 17:14
• @StevenClark Your can explore this Wolfram Elliptic functions link to find identities Commented May 14, 2022 at 17:24
• The more I look at this the more I think this goes far beyond my maths skills. Thanks for the help, I'll mark this as the correct answer
– Newt
Commented May 14, 2022 at 18:52