Problem 41:  Integrating the modulus function ($✓$ $✓$) 2000 Paper I

Show that

${\int }_{-1}^{1}|\phantom{\rule{0.3em}{0ex}}x{\mathrm{e}}^{x}\phantom{\rule{0.3em}{0ex}}|\mathrm{d}x=-{\int }_{-1}^{0}x{\mathrm{e}}^{x}\mathrm{d}x+{\int }_{0}^{1}x{\mathrm{e}}^{x}\mathrm{d}x$

and hence evaluate the integral.

Evaluate the following integrals:

(i)
${\int }_{0}^{4}|\phantom{\rule{0.3em}{0ex}}{x}^{3}-2{x}^{2}-x+2\phantom{\rule{0.3em}{0ex}}|\phantom{\rule{0.3em}{0ex}}\mathrm{d}x\phantom{\rule{0.3em}{0ex}};$
(ii)
${\int }_{-\pi }^{\pi }|\phantom{\rule{0.3em}{0ex}}sinx+cosx\phantom{\rule{0.3em}{0ex}}|\phantom{\rule{2.77695pt}{0ex}}\mathrm{d}x\phantom{\rule{0.3em}{0ex}}.$

The very ﬁrst part shows you how to do this sort of integral (with mod signs in the integrand) by splitting up the range of integration at the points where the integrand changes sign. In parts (i) and (ii) you have to use the technique on different examples.

Solution to problem 41

For the ﬁrst part, note that $|x{\mathrm{e}}^{x}|=-x{\mathrm{e}}^{x}$ if $x<0\phantom{\rule{0.3em}{0ex}}$. Then integrate by parts to evaluate the integrals:

${\int }_{-1}^{0}\left(-x{\mathrm{e}}^{x}\right)\mathrm{d}x+{\int }_{0}^{1}x{\mathrm{e}}^{x}\mathrm{d}x=-\left(\left[\rightx{\mathrm{e}}^{x}{\left]\right}_{-1}^{0}-{\int }_{-1}^{0}{\mathrm{e}}^{x}\mathrm{d}x\right)+\left(\left[\rightx{\mathrm{e}}^{x}{\left]\right}_{0}^{1}-{\int }_{0}^{1}{\mathrm{e}}^{x}\mathrm{d}x\right)=2-2{\mathrm{e}}^{-1}\phantom{\rule{2.77695pt}{0ex}}.$

For the next parts, we have to ﬁnd out where the integrand is positive and where it is negative.

(i) ${x}^{3}-2{x}^{2}-x+2=\left(x-1\right)\left(x+1\right)\left(x-2\right)$ (spotting the factors), so the integrand is positive for $0\le x<1\phantom{\rule{0.3em}{0ex}}$, negative for $1 and positive for $2 (a quick sketch will help with this). Splitting the range of integration into these ranges and integrating gives

$\begin{array}{lll}\hfill {\int }_{0}^{4}\left|\right\phantom{\rule{0.3em}{0ex}}{x}^{3}-2{x}^{2}-x+2\phantom{\rule{0.3em}{0ex}}\left|\right\phantom{\rule{0.3em}{0ex}}\mathrm{d}x\phantom{\rule{-85.35826pt}{0ex}}& \phantom{\rule{2em}{0ex}}& \hfill \text{(}\ast \text{)}\\ \hfill & ={\int }_{0}^{1}\left({x}^{3}-2{x}^{2}-x+2\right)\phantom{\rule{0.3em}{0ex}}\mathrm{d}x-{\int }_{1}^{2}\left({x}^{3}-2{x}^{2}-x+2\right)\phantom{\rule{0.3em}{0ex}}\mathrm{d}x+{\int }_{2}^{4}\left({x}^{3}-2{x}^{2}-x+2\right)\phantom{\rule{0.3em}{0ex}}\mathrm{d}x\phantom{\rule{2em}{0ex}}& \hfill \text{(3)}\\ \hfill & =22\frac{1}{6}\phantom{\rule{0.3em}{0ex}}.\phantom{\rule{2em}{0ex}}& \hfill & \phantom{\rule{2em}{0ex}}\end{array}$

(ii) $sinx+cosx$ changes sign when $tanx=-1$, i.e. when $x=-\frac{1}{4}\pi$ and $x=\frac{3}{4}\pi$. Splitting the range of integration into these ranges and integrating gives

$\begin{array}{llll}\hfill {\int }_{-\pi }^{\pi }\left|\right\phantom{\rule{0.3em}{0ex}}sinx+cosx\phantom{\rule{0.3em}{0ex}}\left|\right\phantom{\rule{2.77695pt}{0ex}}\mathrm{d}x& ={\int }_{-\pi }^{-\frac{1}{4}\pi }\phantom{\rule{0.3em}{0ex}}\phantom{\rule{0.3em}{0ex}}\phantom{\rule{0.3em}{0ex}}\phantom{\rule{0.3em}{0ex}}\phantom{\rule{0.3em}{0ex}}-\left(sinx+cosx\right)\phantom{\rule{0.3em}{0ex}}\mathrm{d}x+{\int }_{-\pi ∕4}^{\frac{3}{4}\pi }\phantom{\rule{0.3em}{0ex}}\phantom{\rule{0.3em}{0ex}}\phantom{\rule{0.3em}{0ex}}\phantom{\rule{0.3em}{0ex}}\phantom{\rule{0.3em}{0ex}}\left(sinx+cosx\right)\phantom{\rule{0.3em}{0ex}}\mathrm{d}x+{\int }_{\frac{3}{4}\pi }^{\pi }\phantom{\rule{0.3em}{0ex}}\phantom{\rule{0.3em}{0ex}}\phantom{\rule{0.3em}{0ex}}\phantom{\rule{0.3em}{0ex}}\phantom{\rule{0.3em}{0ex}}-\left(sinx+cosx\right)\phantom{\rule{0.3em}{0ex}}\mathrm{d}x\phantom{\rule{2em}{0ex}}& \hfill & \phantom{\rule{2em}{0ex}}\\ \hfill & =\left[\rightcosx-sinx{\left]\right}_{-\pi }^{-\frac{1}{4}\pi }+\left[\right-cosx+sinx{\left]\right}_{-\frac{1}{4}\pi }^{\frac{3}{4}\pi }+\left[\right+cosx-sinx{\left]\right}_{\frac{3}{4}\pi }^{\pi }\phantom{\rule{2em}{0ex}}& \hfill & \phantom{\rule{2em}{0ex}}\\ \hfill & =4\sqrt{2}\phantom{\rule{2em}{0ex}}& \hfill & \phantom{\rule{2em}{0ex}}\end{array}$

Alternatively, start by writing $sinx+cosx=\surd 2\phantom{\rule{0.3em}{0ex}}cos\left(x-\frac{1}{4}\pi \right)\phantom{\rule{0.3em}{0ex}}$ which makes the changes of sign easier to spot and the integrals easier to do.

Post-mortem

If you give a bit more thought to part (ii), you will see easier ways of doing it. Since the trigonometric functions are periodic with period $2\pi \phantom{\rule{0.3em}{0ex}}$ the integrand is also periodic. Write the integrand in the form $\sqrt{2}\left|\rightcos\left(x-\frac{1}{4}\pi \right)\left|\right\phantom{\rule{0.3em}{0ex}}$. Integrating this over any $2\pi$ interval gives the same result. Indeed, we may as well integrate $\sqrt{2}\left|\rightsinx\left|\right\phantom{\rule{0.3em}{0ex}}$ from $0$ to $2\pi$; or from $0$ to $\pi$ and double the answer.

After the ﬁrst edition of this book appeared, a correspondent e-mailed to suggest that we should integrate ($\ast$) by writing it in the form

${\int }_{0}^{4}\left({x}^{3}-2{x}^{2}-x+2\right)\phantom{\rule{0.3em}{0ex}}\mathrm{d}x-2{\int }_{1}^{2}\left({x}^{3}-2{x}^{2}-x+2\right)\phantom{\rule{0.3em}{0ex}}\mathrm{d}x.$

Yes, that’s quite a good idea; it would have saved a bit of writing and reduced the risk of arithmetical errors.