# Calculating probability with a piecewise density function

I tried solving this, and I am pretty sure I am integrating this correctly, however, my solution manual shows -1 in the equation when doing this and I do not know why. The answer in the solution manual is correct.

Problem: Find the corresponding distribution function and use it to determine the probability that a random variable having the distribution function will take on a value between 0.4 and 1.6.

f(x) = x for 0 < x < 1
2-x for 1 <= x < 2
0 elsewhere


so for F(0.4 < x < 1.6) I did after integrating:
2(1.6) - [(1.6)^2 / 2] - [(0.4)^2 / 2] = 1.84
however the correct answer is 0.84. The solution manual has a -1 in their equation, but I do not know how they got it.

• Note that in this simple case, you can just calculate areas of rectangles and triangled and get the result. – Raphael Nov 17 '10 at 15:35

Since $f(t)$ is defined piecewise, you have to be careful with the integral. This is the source of your mistake.

If $0 < x < 1$, $$F(x) = \int_0^x f(t) dt = \int_0^x t dt = \left.\frac{1}{2}t^2\right|_0^x = \frac{1}{2}x^2,$$ which you have.

However, if $1 \leq x < 2$, then you have to break the integral that yields $F(x)$ up into pieces. This is $$F(x) = \int_0^x f(t) dt = \int_0^1 t dt + \int_1^x (2-t) dt = \left.\frac{1}{2}t^2\right|_0^1 + \left[2t - \frac{1}{2}t^2\right]_1^x$$ $$= \frac{1}{2} + 2x - \frac{1}{2}x^2 - 2 + \frac{1}{2} = 2x - \frac{1}{2}x^2 - 1.$$ Here's where the $-1$ comes in.

This is a common mistake. If it makes you feel any better, my probability students trip up over this all the time. :)

• Wow, thank you very much for the well explained solution. – Raptrex Nov 17 '10 at 6:43

First, probabilities are from $0$ to $1$, so you're certainly wrong.

Second, you calculated the cdf incorrectly for the interval $1 \leq x < 2$. It should be $$F(x) = \int_0^1 t \, \mathrm{d}t + \int_1^x 2-t \, \mathrm{d}t.$$ You forgot the first part, and integrated the second part from $0$ instead of from $1$. Since $$\int_0^1 t \, \mathrm{d}t = 1/2$$ whereas $$\int_0^1 2-t \, \mathrm{d}t = 3/2,$$ you counter $1/2$ too little and $3/2$ too much, for a total gain of $+1$.