This is a tricky problem that seems to defy wolfram alpha, most/all of the commercially available numerical integrators on the market, and even my trusty TI-84.

Evaluate \[ \int_{-\pi}^{\pi} \left(\frac{x}{\pi}\right)^{100001}\sin(x) dx \] and in general, write an algorithm that can compute \[ S_n = \int_{-\pi}^{\pi} \left(\frac{x}{\pi}\right)^{n}\sin(x) dx \] to at least 10 digits of accuracy in linear time.

Hint: \(S_n \le 2\), why?

## Comments

Sort by:

TopNewestFor \(n\) even, the integral is zero. For \(n\) odd, we may use the series expansion of \(\sin(x)\). But faster methods might exist. – Abhishek Sinha · 3 years, 6 months ago

Log in to reply

\(1.9738221879\times 10^{-9}\)

aka \(\frac{2\pi^2}{(n+1)(n+2)}\) for odd n

But why did you put up the spoiler? It is not hard to get the definite integral for say n = 1..10. Then not hard to get the pattern and hence the basic recurrence. Then not hard to compare to the series for \(\sin\pi\) and consider the error. – Joe Sixpack · 3 years, 6 months ago

Log in to reply

I'm assuming you mean the spoiler I posted on Chandler's post: I wanted to encourage people to derive the full series rather than the obvious pattern. While the error of your method decays w.r.t to \(O(n^{-4})\), it may not be very accurate for low values of \(n\).

The exercise was given more as a word of caution: an elegant solution isn't always great; especially when working in the domain of numerical algorithms, care must be taken to verify instabilities in your chosen method. – Lee Gao · 3 years, 6 months ago

Log in to reply

S(2n) will be zero since the integrand is odd function. For S(2n+1), you can use integration by parts twice to get \(S_{2n+1} = 2-\frac{2n(2n+1)}{\pi^2}S_{2n-1}\) From here, also using the initial condition that \(S_1 = 2\) you can find all values of \(S_n\) – Shouvik Ganguly · 3 years, 3 months ago

Log in to reply

unstable

If you're interested, this was a problem I considered for an optimization problem @ Cornell University this past spring, and I wrote up my experience with the problem here. – Lee Gao · 3 years, 3 months ago

Log in to reply

https://www.dropbox.com/s/9jc9hnl5g2w5wh7/lsq2.pdf. – Lee Gao · 3 years, 3 months ago

The link I shared is broken, the correct one isLog in to reply

python:

Of course you'll have to mess with this slightly to actually use exponents as high as 100001, but you get the idea... – Chandler West · 3 years, 6 months ago

Log in to reply

However you're close, and with a little bit of cleverness, you can derive a stable series from this unstable series. Hint: look at the first order non-linear recurrence, find a way to express it as a first order linear recurrence, reduce it to a different sum, and find what function it corresponds to as the truncated taylor expansion of. That will help you in transforming this series into an infinite series that is stable. – Lee Gao · 3 years, 6 months ago

Log in to reply

Note that Mathematica does, in fact, handle this integral incredibly well with the right tweaks. – Michael Lee · 3 years, 6 months ago

Log in to reply