Numerical Integration over region with singularities

391 Views Asked by At

I am trying to integrate the following $$\int_0^{2\pi}\frac{1}{\sqrt{1-\cos(x)}}dx$$ and I am stuck on how to proceed using Matlab or Sage.

3

There are 3 best solutions below

0
On BEST ANSWER

Just to complement the other answers.

There is an easier function to use instead of the quadgk. It is the integral function. They both do the same think, but the name "integral" is easier to remember, easier to find and easier to use. There is a good discussion about it on Mathworks blog.

Type it on MATLAB, and both functions will return Inf - which means the integral diverges.

f = @(x) 1./sqrt(1-cos(x))
integral(f,0,2*pi)
quadgk(f,0,2*pi)

As @Claude Leibovici noticed, however, we can evaluate the integral if the limits are not $0$ and $2\pi$.

format long
eps = 1e-2;
integral(f,eps,2*pi-eps)

And the result is

16.946414949423382

Not exactly the value, but pretty good. We can even get better results reducing the tolerances on the integral function.

2
On

This integral is a type II improper integral as the interval of integration includes a point at which the output values of the integrand approach $\pm \infty$. In this case, $f(x) \rightarrow \infty$ as $x \rightarrow 0$ and as $x \rightarrow 2\pi$, both of which comprise the limits of integration.

We proceed by examining the domain of $f$ and noting that it is in fact continuous and therefore integrable on $(0,2\pi)$. Thus, we choose some arbitrary element in the interval of integration for which $f$ is defined, say $\pi$, and then add the limits of two integrals as follows:

$$\lim_{a \rightarrow 0} \int_a^\pi \frac{1}{\sqrt[]{1-cos\theta}}d\theta + \lim_{b \rightarrow 2\pi} \int_\pi^{b} \frac{1}{\sqrt[]{1-cos\theta}}d\theta$$

First, compute the integrals irrespective of the limits. Then, after you have obtained the antiderivatives in terms of $a,b$ and $\theta$, solve the limits.

Whether the integral converges or not remains to be seen, but this is a standard approach to solving such a problem. I believe current versions of Matlab are able to handle infinite limits. Look into quadgk.

0
On

The antiderivative is not a major problem and then $$I(\epsilon)=\int_\epsilon^{2\pi-\epsilon}\frac{dx}{\sqrt{1-\cos(x)}}=2 \sqrt{2} \log \left(\cot \left(\frac{\epsilon }{4}\right)\right)$$ Using Taylor expansion built at $\epsilon=0$ gives $$I(\epsilon)=-2 \sqrt{2} \log \left(\frac{\epsilon }{4}\right)-\frac{\epsilon ^2}{12 \sqrt{2}}+O\left(\epsilon ^4\right)$$ Computing $$I\left(\frac{1}{100}\right)=2 \sqrt{2} \log \left(\cot \left(\frac{1}{400}\right)\right)\approx 16.9464149494303$$ while the above truncated series would give $\color{red} {16.94641494943}89$