True mean of a truncated distribution? I use C++ GSL library to generate random numbers now. The numbers obey a distribution, (e.g. normal or lognormal distribution). This library requires the input of expected value ${\mu}$ (i.e. mean) and std. deviation $\sigma$. I'd like sample random numbers within an interval $(a, b)$. So, when the generated numbers is out of the interval, then that number is discarded. For instance, I'd like to sample numbers having a normal distribution with $\mu$ = 5, $\sigma$ = 0.5, $a$ = 0.5, and $b$ = 10. The $\mu$ must be in the interval $(a, b)$.
The question is: someone said the input $\mu$ and $\sigma$ are not true $\mu$ and $\sigma$ of the sampled numbers, because the pdf $f(x)$ is truncated. But I think, since the input $\mu$ is within the $(a, b)$, and $(a, b)$ is wide enough, they might not be so different.
Is it a big difference between the input and true $\mu$ and $\sigma$? Is it anyway to analytically derive the true values of them?
Maybe, the true $\mu$ is $E(x) = \int_a^bxf(x)dx$? am I right?

For truncated distributions, it is customary to parameterise them in terms of the original parameters, ie those of the untruncated distribution. For instance, the truncated normal distribution$$\mathcal N_-^+(\mu,\sigma^2,a,b)$$restricts the untruncated normal distribution$$\mathcal N_(\mu,\sigma^2)$$to the interval $(a,b)$, meaning that the untruncated normal $\mathcal N_(\mu,\sigma^2)$ density is restricted to the $(a,b)$ interval and renormalised$$f_-^+(x;\mu,\sigma^2,a,b)=\varphi(x;\mu,\sigma^2)\Big/\int_a^b\varphi(\xi;\mu,\sigma^2)\,\text d\xi\tag{1}$$Using the original mean-variance parameterisation is easier than using the truncated mean-variance parameterisation as

*

*The definition of the distribution is straightforward, as shown by (1). By contrast, if given the truncated mean-variance parameterisation, one would need to revert back to the untruncated mean-variance parameterisation to write (1).

*In most situations, there exist no analytical formula for the mean and/or variance of the truncated distributions. Take for instance a truncated multivariate Normal distribution.

Note however that the truncated normal distribution$$\mathcal N_-^+(\mu,\sigma^2,a,b)$$ allows for$$\sigma^2<0$$when $a$ and $b$ are both finite. Meaning that
$$\exp\{(x-\mu)^2/2\kappa\}\Big/\int_a^b \exp\{(\xi-\mu)^2/2\kappa\}\,\text d\xi$$
is well-defined for all $\kappa\in\mathbb R$.
Note also that simulating from the untruncated version until the outcome stands in $(a,b)$ may prove a very inefficient way of simulating from the truncated version.
