# Where is the flaw in evaluating the following integral?

I was trying to evaluate a complicated integral by substitution and along the way I got stuck in nonsensical answer. Surprisingly enough the point I wanted to discuss can be demonstrated using the following primitive integral:

$\displaystyle\int_0^\pi \sin\theta d\theta=-\cos\theta|_0^\pi=-\cos\pi+\cos 0=1+1=2$

Now Imagine we are trying to do the same integral in another way, by substitution.

If we take $\sin\theta\equiv y$ then the limits of the integral will change accordingly from $0$ to $\pi$ to from $0$ to $0$, which will kill the integral instantly and give us $0$!

So either there is a flaw in my solution that I cannot find, or that there are conditions under which one can (or cannot) use integration by substitution that I am not aware of (at least I have never seen it in college level calculus).

-
If you take $y=\sin\,\theta$, how do you express $\mathrm d\theta$ in terms of $\mathrm dy$? – J. M. Jan 3 '12 at 15:03
The flaw is in not using change of variables correctly. – cardinal Jan 3 '12 at 15:04
This is a classic – leonbloy Jan 3 '12 at 15:05
The sine function starts as zero at the lower integration limit, grows to one at the middle, and then decreases back to zero at the upper limit. The image is thus a unit interval, not an empty one. – Sasha Jan 3 '12 at 15:07
@Revo: see my answer below. Your error lies in the fact that it's not true that $\cos \theta = \sqrt{1-y^2}$ for all the values of $\theta$ which you're integrating over. – Clive Newstead Jan 3 '12 at 15:19

Integration by substitution tells us that $$\int_a^b f(g(\theta))g'(\theta)\, d\theta = \int_{g(a)}^{g(b)} f(y)\, dy$$ where $g:[a,b] \to g([a,b])$ is continuously differentiable and $f:g([a,b]) \to \mathbb{R}$ is continuous.

Now, between $0$ and $\frac{\pi}{2}$, if we set $y=g(\theta)=\sin \theta$ then $g'(\theta)=\cos \theta = \sqrt{1-y^2}$. But between $\frac{\pi}{2}$ and $\pi$ it is in fact the case that $\cos \theta = -\sqrt{1-y^2}$. So in the above expression we must have $$f(y) = \begin{cases} \frac{y}{\sqrt{1-y^2}} & \text{if } 0 \le \theta \le \frac{\pi}{2} \\ -\frac{y}{\sqrt{1-y^2}} & \text{if } \frac{\pi}{2} \le \theta \le \pi \end{cases}$$

And so the integral actually transforms, by integration by substitution, to

$$\int_0^1 \frac{y}{\sqrt{1-y^2}}\, dy + \int_1^0 \frac{-y}{\sqrt{1-y^2}}\, dy$$

which can readily be seen to evaluate to $2$.

-
+1 for clear explanation. – NikBels Jan 3 '12 at 15:15
Excellent explanation, thank you so much. I am wondering why such subtleties are not taught in calculus courses? Do you know any book that cover similar subtleties? – Revo Jan 3 '12 at 15:20
@Revo: No problem. I don't know of any books that cover this sort of thing, I'm afraid - it's just the kind of thing you learn to spot after a while. It's really down to being very cautious when dealing with things like square roots to make sure the root you're taking is the root you're meant to take -- this kind of thing is often glossed over at school level, but I think most undergraduate-level courses try to teach good habits in this respect. – Clive Newstead Jan 3 '12 at 15:42