3

Consider the function $\csc(t)\sin(3t)$ on the interval $[0,\pi]$. This is a perfectly well-behaved smooth function, as can be seen when plotting it:

Plot[2 Csc[t] Sin[3 t], {t, 0, π}]

so why cannot I not numerically integrate it by running the following?

NIntegrate[2 Csc[t] Sin[3 t], {t, 0, π}]

Instead I get the error message "NIntegrate::errprec: Catastrophic loss of precision in the global error estimate due to insufficient WorkingPrecision or divergent integral". FYI I expect the answer to be $2\pi$, as can be seen by running

Integrate[2 Csc[t] Sin[3 t], {t, 0, π}]

Thanks in advance for any help.

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
Chris
  • 1,033
  • 4
  • 8

1 Answers1

6

Maybe my last comment makes it worth posting my comments as an answer. The first one shows that the error message contains a hint at a fix, and one naturally would try it out first. The second one seems a common-sense thing to try. For the last one I had to take a look into what NIntegrate was doing.

Round-off error (from the asymptotes of Csc[t]). Following the advice in the error message, try it wth WorkingPrecision -> 16. – Michael E2 18 mins ago

Or try NIntegrate[2 Csc[t] Sin[3 t] // TrigExpand, {t, 0, \[Pi]}] – Michael E2 9 mins ago

In some sense, NIntegrate selects a bad rule (Clenshaw-Curtis oscillatory). Try NIntegrate[2 Csc[t] Sin[3 t], {t, 0, \[Pi]}, Method -> "GaussKronrodRule"] – Michael E2 52 secs ago

Method -> "LevinRule" also works.

Michael E2
  • 235,386
  • 17
  • 334
  • 747
  • Does anyone have a reference for how Method -> "ClenshawCurtisOscillatoryRule" works? I assume the catastrophic loss of precision comes from some sort of extrapolation to the endpoints where the integrand is undefined (not from a catastrophic loss in Csc[t] per se, which is improbable). – Michael E2 Nov 28 '21 at 16:03
  • 1
    If memory serves, that one is supposed to be an implementation of the method of Piessens and Branders, first noted here, and then extended here. – J. M.'s missing motivation Dec 09 '21 at 20:24
  • @J.M. Thanks for the references. – Michael E2 Dec 10 '21 at 15:23