Integrate with y-values and x-values to find expectation? (with python if possible)

139 Views Asked by At

I have approximations of $f(x)$ and value of $x$ as two vectors. i.e

f(x) = [0.01, 0.02 ... 0.01]
x = [2000 2050 ... 2500]

I want to find expected value of $x$, which is defined as the integration of $x*f(x)$ w.r.t. $x$ i.e.

$E[x] = \int_R x f(x) dx$

I only have values for the $f(x)$, which means that I can't solve the problem analytically. Does anyone know if it is possible to find the integration with only two vectors? It is possible to do with any package in python? I'm thinking that scipy might have something but have not found anything useful yet.

Thanks!


EDIT Both x and f(x) are drawn from samples that are not truly normally distributed. So i can not take the sum of $x$ divided by amount of $x$

1

There are 1 best solutions below

2
On

Just sum up the following:

\begin{equation} E\lbrace X \rbrace \simeq \frac{1}{N} \sum\limits_{n=1}^N x[n] f(x[n]) = \frac{1}{N} \Big(0.001 \times 2000 + 0.02 \times 2050 + ...\Big) \end{equation} This is just rephrasing what @Callus meant