Plotting pdf based on value

55 Views Asked by At

I'm given a continuous random variable X and have the probability density function as below:

enter image description here

Now, i want to plot when b = 2, and since i wasn't provided with any dataset, i attempted something like:

enter image description here

I was wondering if I'm doing it correctly as it's my first time plotting a density function.

1

There are 1 best solutions below

0
On BEST ANSWER

The pdf is given to you as a function of the parameter $b$

$$p(X=x|b ) =\begin{align}\begin{cases} \frac{2x}{b^{2}} & \textrm{ for } x \in [0,b] \\ \\ 0 & \textrm{ for everywhere else } \end{cases} \end{align}$$

then our density function is simply when we insert $b=2$

$$p(X=x|2 ) =\begin{align}\begin{cases} \frac{2x}{(2)^{2}} & \textrm{ for } x \in [0,2] \\ \\ 0 & \textrm{ for everywhere else } \end{cases} \end{align}$$

We simplify

$$p(X=x|2 ) =\begin{align}\begin{cases} \frac{x}{2} & \textrm{ for } x \in [0,2] \\ \\ 0 & \textrm{ for everywhere else } \end{cases} \end{align}$$

Using python here to create a graph

import numpy as np 
import matplotlib.pyplot as plt

    a=0
    b=2
    n=1000
    x = np.linspace(a,b,n)

    pdf = x/2

plt.plot(x,pdf)

enter image description here