The density of random variable $X$ is $f(x) = \frac{(x-8)(12-x)}{9}$ for $8\leq x \leq 11$ and 0 otherwise.

Using the R integrate function

(a) find the probability that $x< 10.4$

(b) find the probability that $9 < x < 10.5$

(c) find the expected value of $X$

(d) find the variance of $x$

#### Solution

The density of random variable $X$ is

` $$ \begin{equation*} f(x)= \begin{cases} \frac{(x-8)(12-x)}{9} & 8\leq x\leq 11\\ 0 & \text{ otherwise }. \end{cases} \end{equation*} $$ `

Define a function `fx`

```
## Define the density function
fx<-function(x){
(x-8)*(12-x)/9
}
```

(a) The probability that $X< 10.4$, i.e., $P(X< 10.4)=\int_8^{10.4}f(x)\; dx$.

```
## Calculate probability using integrate function
P1<-integrate(fx,lower=8,upper=10.4)
print(P1)
```

`0.768 with absolute error < 8.5e-15`

$P(X< 10.4) = 0.768$

(b) The probability that $9 < X < 10.5$ is $P(9<X<10.5)=\int_9^{10.5}f(x) \; dx$.

```
## Calculate probability using integrate function
P2<-integrate(fx,lower=9,upper=10.5)
print(P2)
```

`0.625 with absolute error < 6.9e-15`

$P(9<X< 10.5) = 0.625$

(c) Expected value of $X$ is $E(X) =\int_8^{11}xf(x) \; dx$.

```
## Calculate expectation using integrate function
Ex<-integrate(function(x) x*fx(x),lower=8,upper=11)
print(Ex)
```

`9.75 with absolute error < 1.1e-13`

The expected value of $X$ is $E(X)=9.75$

(d) The variance of $X$ is $V(X) = \int_8^{11}(x-E(x))^2f(x)\; dx$.

```
## Calculate variance using integrate function
Vx<-integrate(function(x) (x-Ex$value)^2*fx(x),lower=8,upper=11)
print(Vx)
```

`0.5375 with absolute error < 6e-15`

The variance of $X$ is $V(X)=0.5375$