# calculate CDF from given PDF

I am trying to understand the calculate the CDF from the given PDF

$$f(x) = \begin{cases} 0.5& 0\le x<1\\ 1& 1\le x<1.5\\ 0& \text{otherwise}\end{cases}$$

The CDF is

$$F(x) = \begin{cases}0 & x<0\\ 0.5x & 0\le x<1\\ x-0.5 & 1\le x<1.5\\ 1 & x\ge 1.5\end{cases}$$

$$0.5x$$ for $$0\le x<1$$

and

$$x-0.5$$ for $$1\le x<1.5$$

are calculated?

If you know the pdf $$f(x)$$ then the cdf is obtained via integration

$$F(x) = \int_{-\infty}^x {f(t)}~{\rm d}t \tag{1}$$

$$f(x) = \begin{cases} 1/2 & 0 \leq x <1\\ 1 & 1 \leq x < 3/2\\ 0 & \mbox{otherwise} \end{cases} \tag{2}$$

It is just a matter on calculating the integral

$$x < 0$$

If $$x < 0$$ then, $$f(x) = 0$$ and

$$F(x) = \int_{-\infty}^{x}f(t)~{\rm d}t = 0 \tag{3}$$

$$0 \leq x < 1$$ in this range the $$f(x) = 1/2$$ so that

$$F(x) = \int_{-\infty}^{x}f(t)~{\rm d}t = \int_{-\infty}^{0}f(t)~{\rm d}t + \int_{0}^{x}f(t)~{\rm d}t = 0 + \int_{0}^{x}\frac{1}{2}~{\rm d}t = \frac{x}{2}\tag{4}$$

$$1 \leq x < 3/2$$

As before

$$\begin{eqnarray} \int_{-\infty}^{x}f(t)~{\rm d}t &=& \int_{-\infty}^{0}f(t)~{\rm d}t + \int_{0}^{1}f(t)~{\rm d}t + \int_{1}^{x}f(t)~{\rm d}t \\ &=& 0 + \int_{0}^{1}\frac{1}{2}~{\rm d}t + \int_{1}^{x}1~{\rm d}t \\ &=& \frac{1}{2} + (x - 1) = x - \frac{1}{2} \tag{5} \end{eqnarray}$$

$$x > 3/2$$

Finally

$$\begin{eqnarray} \int_{-\infty}^{x}f(t)~{\rm d}t &=& \int_{-\infty}^{0}f(t)~{\rm d}t + \int_{0}^{1}f(t)~{\rm d}t + \int_{1}^{3/2}f(t)~{\rm d}t + \int_{3/2}^{x}f(t)~{\rm d}t\\ &=& 0 + \int_{0}^{1}\frac{1}{2}~{\rm d}t + \int_{1}^{3/2}1~{\rm d}t + 0\\ &=& \frac{1}{2} + \frac{1}{2} = 1 \tag{6} \end{eqnarray}$$

If you put everything together you'd get

$$F(x) = \begin{cases} 0 & x < 0 \\ x/2 & 0 \leq x < 1 \\ x - 1/2 & 1 \leq x < 3/2 \\ 1 & x > 3/2 \end{cases}$$