# How can I calculate the moments of a truncated random variable?

I am using the Moment function to calculate the moments of an exponential random variable.

as follows,

Moment[ExponentialDistribution[3], 9]


However, I need to calculate the moments of a truncated (between 0 and 5) exponential random variable as well, however, I have checked the available documentation and I don't find anything. Can someone please tell me what I have to add to my current code for it to be truncated in the interval [0, 5]?

• Try: Moment[TruncatedDistribution[{0, 5}, ExponentialDistribution[3]], 1] Sep 14, 2022 at 14:38

\$Version

(* "13.1.0 for Mac OS X x86 (64-bit) (June 16, 2022)" *)

Clear["Global*"]


More generally, the truncated distribution is given by

tdist = TruncatedDistribution[{0, xmax}, ExponentialDistribution[λ]];


tdist inherits the assumption on the parameter for ExponentialDistribution and adds the assumption that xmax is positive real.

dpa = DistributionParameterAssumptions[tdist]

(* λ > 0 && Im[xmax] == 0 && xmax > 0 *)


The PDF is

PDF[tdist, x]


Verifying the PDF

Assuming[dpa,
Integrate[PDF[tdist, x], {x, -Infinity, Infinity}]]

(* 1 *)


The moments are then

Moment[tdist, r]

(* (λ^-r (Gamma[1 + r] -
Gamma[1 + r, xmax λ]))/(1 - E^(-xmax λ)) *)

CentralMoment[tdist, r]

(* (1/(-1 + E^(xmax λ)))E^(-1 + (1 +
1/(-1 + E^(xmax λ))) xmax λ) λ^-r (Gamma[
1 + r, -1 + (xmax λ)/(-1 + E^(xmax λ))] -
Gamma[1 + r, -1 + (1 + 1/(-1 + E^(xmax λ))) xmax λ]) *)


For example,

Assuming[dpa,
#[tdist] & /@ {Mean, Moment[#, 1] &, Moment[#, 2] &,
Variance, CentralMoment[#, 2] &}]
`