# Statistical parameters using probability density function
### Given probability density function, $p(x)$

$ p = 2x/b^2$, $0 < x < b$

### The mean value of $x$ is estimated analytically:
$\overline{x} = \int\limits_0^b x\, p(x)\, dx = \int\limits_0^b 2x^2/b^2 = \left. 2x^3/3b^2\right|_0^b =2b^3/3b^2 = 2b/3$


### the median
median: $ \int\limits_0^m p(x)\,dx = 1/2 = \int\limits_0^m 2x/b^2\,dx = \left. x^2/b^2 \right|_0^m = m^2/b^2 = 1/2$, $m = b/\sqrt(2)$

### the second moment
second moment: $x^{(2)} = \int\limits_0^b x^2\, p(x)\, dx = \int\limits_0^b 2x^3/b^2 = \left. x^4/2b^2\right|_0^b =b^4/2b^2 = b^2/2$

### the variance is the second moment less the squared mean value
$var(x) = x^{(2)} - \overline{x}^2 = b^2/2 - 4b^2/9 = b^2/18$




```
def p(x,b):
    return 2*x/(b**2)

```


```
b = 2
x = linspace(0,b,200)
y = p(x,b) 
```


```
plot(x,y)
xlabel('$x$')
ylabel('$p(x)$')
```


```
# approximate using the numerical integration
print trapz(y*x,x)
print 2.*b/3
```

    1.33335016793
    1.33333333333



```
print trapz(y*x**2,x)
print b^2/18
```

    2.00005050378
    2



```
import sympy
```


```
sympy.var('x,b,p,m')
p = 2*x/b**2
print p
```

    2*x/b**2



```
sympy.integrate(p*x,(x,0,b))
```




    2*b/3




```
sympy.integrate(p*x**2,(x,0,b))
```




    b**2/2




```
sympy.integrate(p,(x,0,m))
```




    m**2/b**2




```
sympy.solve(m**2/b**2 - 0.5,m)
```




    [-0.707106781186548*b, 0.707106781186548*b]




```

```

6ac40ff747f3969f9a9d3d2c9e5ec8432b4149b8
ipynb
Jupyter Notebook
notebooks/unsorted/estimate_mean_variance_median_using_pdf.ipynb
alexlib/engineering_experiments_measurements_course
0b80d90519a2a72547ffd9ef4da2158530016196
CC0-1.0
2018-05-03T09:41:03.000Z
2022-03-26T12:39:27.000Z
notebooks/unsorted/estimate_mean_variance_median_using_pdf.ipynb
alexlib/engineering_experiments_measurements_course
0b80d90519a2a72547ffd9ef4da2158530016196
CC0-1.0
2018-04-22T09:04:13.000Z
2018-04-22T09:04:13.000Z
notebooks/unsorted/estimate_mean_variance_median_using_pdf.ipynb
alexlib/engineering_experiments_measurements_course
0b80d90519a2a72547ffd9ef4da2158530016196
CC0-1.0
2015-07-02T11:39:57.000Z
2021-05-03T15:49:42.000Z
Qwen/Qwen-72B
1. YES
2. YES