# Integral of a function with two parts (piecewise defined)

The function has 2 parts:

$$f(x) = \begin{cases} -\sin x & x \le 0 \\ 2x & x > 0\end{cases}$$

I need to calculate the integral between $-\pi$ and $2$. So is the answer is an integral bewteen $-\pi$ and $0$ of $f(x)$ and then and $0$ to $2$. but why the calculation of the first part of $-\pi$ and $2$ aire on $-\sin x$ and the second part of the intgral is on $x^2$, which is part of the $F(x)$.

I'd like to get some help over here, I'm lost

-

You have the following fundamental property of integrals: if $f(x)$ is integrable on an interval $[a,b]$, and $c\in[a,b]$, then $$\int_a^b f(x) dx = \int_a^c f(x) dx + \int_c^b f(x) dx.$$ In your case, you thus have \begin{align} \int_{-\pi}^2 f(x) dx &= \int_{-\pi}^0 f(x) dx + \int_0^2 f(x) dx\\ &= \int_{-\pi}^0 -\sin(x) dx + \int_0^2 2x dx.\end{align}

-

Since your function for $x \le 0$ as $-\sin x$ and when $x >0$ your function is $2x$, you must split your integral.

Your function is defined as two separate functions for specific domains. Therefore, we must satisfy the conditions by integrating within the right bounds.

As we can see:

$$\int_{-\pi}^0 -\sin xdx + \int_{0}^2 2xdx$$

Now we integrate,

$$\int_{-\pi}^0 -\sin xdx =[\cos x]_{-\pi}^0 = 2$$

And

$$\int_{0}^2 2xdx = [x^2]_{0}^2 = 4$$

So our final answer is $$2 + 4 = 6$$

-

Note that $$\displaystyle\int_{-\pi}^{2} f(x) \, \mathrm{d}x = \displaystyle\int_{-\pi}^{0} f(x) \, \mathrm{d}x + \displaystyle\int_{0}^{2} f(x) \, \mathrm{d}x$$ because each integral is an area under the curve $f(x)$ under the given domain and we want to find the full area so we just add the two "components" of the area to get the total.

-