The moment generating function of an exponential random variable X is given by mgf(t) = m/(m - t)
That is, mgf(t) = E(exp(t*X)) = m/(m - t)
Let X_1, X_2, .... X_n are iid random variables having exponential distribution with parameter m.
Let m = 2;
and t = 0.5;
n = 10000
I wish to get an estimate of mgf(0.5) using sum_{i = 1 to 10000} exp(0.5 * X_i) as given my code below:
size = 10000;
m = 2;
xVal = exprnd(m,[1,size]);
t = 0.5;
tVal = t * xVal;
eVal = exp(tVal);
avgVal = sum(eVal)/size
actVal = m/(m - t)
the actual value is 4/3 = 1.333 given by actVal
When I run my code the estimate avgVal churns out results such as
9.9936, 12.9107, 10.6934
when it should ideally give values close to 1.333 according to the law of large numbers.
I face similar problems for quite a few values of m and t.
Where am I going wrong??