Integrals of functions defined by parts

Solve the integral $\displaystyle \int_0^4 f(x) \ dx$ with $\displaystyle f(x)=\left\{\begin{array}{lll} x+e^x & \mbox{ if } & 0\leq x<2 \\ 3 & \mbox{if} & 2\leq x<3 \\ 2+e^{2x} & \mbox{if} & 3\leq x<4 \end{array}\right.$

$$\displaystyle \int_0^2 (x+e^x) \ dx + \int_2^3 3 \ dx + \int_3^4 (2+e^{2x}) \ dx =$$

$$= \Big[\dfrac{x^2}{2}+e^x\Big]^2_0 + [3x]^3_2 + [2x]^4_3 + [\frac{1}{2}e^{2x}]^4_3=$$

$$=(2+e^2-1)+(9-6)+(8-6)+(\frac{1}{2}e^8-\frac{1}{2}e^6)=$$

$$=6+e^2+\frac{1}{2}(e^8-e^6)$$

The result is $6+e^2+\frac{1}{2}(e^8-e^6)$

Solve the integral $\displaystyle \int_{-1}^1 |x| \ dx$

The function $f(x)=|x|$ can be expressed as a piecewise function as follows: $$\displaystyle |x|=\left\{\begin{array}{rcl} -x & \mbox{ if } & x<0 \\ x & \mbox{if} & x\geq0 \end{array}\right.$$

Let's solve the integral piecewise

$$\displaystyle \int_{-1}^0 (-x) \ dx + \int_0^1 x \ dx =$$

$$= \Big[\dfrac{-x^2}{2}\Big]^0_{-1} + \Big[\dfrac{x^2}{2}\Big]^1_0=$$

$$=0-\Big(-\dfrac{1}{2}\Big)+\dfrac{1}{2}-0=1$$

The result is $1$

Back to topic