In https://www.johndcook.com/blog/2012/02/21/care-and-treatment-of-singularities, the author explains the subtraction method to get rid of singularities when performing numerical integration.

The example he gives is the integral $\int_{0}^{1}\frac{1}{\sqrt{\sin x}}dx$.

To accurately compute this integral numerically, one first finds the approximation of integrand near $x=0$, which is $\frac{1}{\sqrt{x}}$ for this case.

Then, the original integral can be written like $\int_{0}^{1}(\frac{1}{\sqrt{\sin x}}-\frac{1}{\sqrt{x}})dx+\int_{0}^{1}\frac{1}{\sqrt{x}}dx$.

The latter term can be computed analytically by hand, so the author mentions that the work only left is computing the former one with numerical integration method such as trapezoidal, Simpson, etc.

I understand that the singularity is eliminated from the former integrand but I could not understand how one can actually compute it with numerical method.

For example, let's say I want to compute it with Simpson's method:


Then, I must evaluate $f(0)$ with the computer to fully compute the former integral. However, how can one compute $\frac{1}{\sqrt{sin(0)}}-\frac{1}{\sqrt{0}}$ with the computer? Shouldn't it give DivisionByZero error?

I want to understand how can this problem solved or am I misunderstand something?

  • 1
    $\begingroup$ You know that $\frac1{\sqrt{\sin x}}-\frac1{\sqrt x}$ is continuous near $x=0$ and that its limit is $0$. So in your implementation you define $f(x)=0$ if $x=0$ and $f(x)=\frac1{\sqrt{\sin x}}-\frac1{\sqrt x}$ otherwise. $\endgroup$
    – user3883
    Commented Nov 30, 2019 at 12:22
  • 1
    $\begingroup$ A related question-answer with the explanation of singularity treatment of the EFIE-type integral; however, without the focus on your particular questions. $\endgroup$
    – Anton Menshov
    Commented Nov 30, 2019 at 13:58
  • $\begingroup$ @Rahul, Anton Menshov Thanks for your answers! I understood it. $\endgroup$
    – Senna
    Commented Dec 2, 2019 at 12:02


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.