NExpectation
✖
NExpectation
gives the numerical expectation of expr under the assumption that x follows the probability distribution dist.
gives the numerical expectation of expr under the assumption that {x1,x2,…} follows the multivariate distribution dist.
gives the numerical expectation of expr under the assumption that x1, x2, … are independent and follow the distributions dist1, dist2, ….
Details and Options

- xdist can be entered as x
dist
dist or x \[Distributed]dist.
- exprpred can be entered as expr
cond
pred or expr \[Conditioned]pred.
- NExpectation works like Expectation, except numerical summation and integration methods are used.
- For a continuous distribution dist, the expectation of expr is given by
where
is the probability density function of dist and the integral is taken over the domain of dist.
- For a discrete distribution dist, the expectation of expr is given by
where
is the probability density function of dist and the summation is taken over the domain of dist.
- NExpectation[expr,{x1dist1,x2dist2}] corresponds to NExpectation[NExpectation[expr,x2dist2],x1dist1] so that the last variable is summed or integrated first.
- N[Expectation[…]] calls NExpectation for expectations that cannot be done symbolically.
- The following options can be given:
-
AccuracyGoal ∞ digits of absolute accuracy sought PrecisionGoal Automatic digits of precision sought WorkingPrecision MachinePrecision the precision used in internal computations Method Automatic what method to use TargetUnits Automatic units to display in the output
Examples
open allclose allBasic Examples (3)Summary of the most common use cases
Compute the expectation of a polynomial expression:

https://wolfram.com/xid/0g7j9qe4cru-houj6b


https://wolfram.com/xid/0g7j9qe4cru-bothj9


https://wolfram.com/xid/0g7j9qe4cru-kavjri


https://wolfram.com/xid/0g7j9qe4cru-cl2gyl

Compute the expectation of an arbitrary expression:

https://wolfram.com/xid/0g7j9qe4cru-csl8ts


https://wolfram.com/xid/0g7j9qe4cru-bnr8lo


https://wolfram.com/xid/0g7j9qe4cru-dlm0pt

Compute a conditional expectation:

https://wolfram.com/xid/0g7j9qe4cru-k7ilu5


https://wolfram.com/xid/0g7j9qe4cru-ffc4yk

Scope (28)Survey of the scope of standard use cases
Basic Uses (9)
Compute the expectation for an expression in a continuous univariate distribution:

https://wolfram.com/xid/0g7j9qe4cru-cciykx

Discrete univariate distribution:

https://wolfram.com/xid/0g7j9qe4cru-d9cbvq

Continuous multivariate distribution:

https://wolfram.com/xid/0g7j9qe4cru-b5j6qz

Discrete multivariate distribution:

https://wolfram.com/xid/0g7j9qe4cru-bsajvr

Compute the expectation using independently distributed random variables:

https://wolfram.com/xid/0g7j9qe4cru-e3mepy

Find the conditional expectation with general nonzero probability conditioning:

https://wolfram.com/xid/0g7j9qe4cru-jamqej

Discrete univariate distribution:

https://wolfram.com/xid/0g7j9qe4cru-9oq16

Multivariate continuous distribution:

https://wolfram.com/xid/0g7j9qe4cru-bhk6y5

Multivariate discrete distribution:

https://wolfram.com/xid/0g7j9qe4cru-iiz3ha

Compute the conditional expectation with a zero-probability conditioning event:

https://wolfram.com/xid/0g7j9qe4cru-g5cok

Apply N[Expectation[…]] to invoke NExpectation if symbolic evaluation fails:

https://wolfram.com/xid/0g7j9qe4cru-t0gc2

https://wolfram.com/xid/0g7j9qe4cru-bet61z


https://wolfram.com/xid/0g7j9qe4cru-cjb03c


https://wolfram.com/xid/0g7j9qe4cru-bu1mdl

Find the expectation of a rational function:

https://wolfram.com/xid/0g7j9qe4cru-kdvjv


https://wolfram.com/xid/0g7j9qe4cru-fy0zr5


https://wolfram.com/xid/0g7j9qe4cru-jrfn9i


https://wolfram.com/xid/0g7j9qe4cru-wrnp8

Obtain results with different precisions:

https://wolfram.com/xid/0g7j9qe4cru-ciyyyh


https://wolfram.com/xid/0g7j9qe4cru-fnqvz2


https://wolfram.com/xid/0g7j9qe4cru-bca0sn


https://wolfram.com/xid/0g7j9qe4cru-b7kucy


https://wolfram.com/xid/0g7j9qe4cru-dqfi5m


https://wolfram.com/xid/0g7j9qe4cru-kcjk0


https://wolfram.com/xid/0g7j9qe4cru-esd50h

Compute an expectation for a time slice of a Poisson process:

https://wolfram.com/xid/0g7j9qe4cru-lmagcn

Find the expectation of an expression when the distribution is specified by a list:

https://wolfram.com/xid/0g7j9qe4cru-fig2hr

https://wolfram.com/xid/0g7j9qe4cru-blym6b

Quantity Uses (4)
Find expectation of quantity expressions:

https://wolfram.com/xid/0g7j9qe4cru-dt8gxo


https://wolfram.com/xid/0g7j9qe4cru-c5ho6i

Find expectations specified using QuantityDistribution:

https://wolfram.com/xid/0g7j9qe4cru-boff7u


https://wolfram.com/xid/0g7j9qe4cru-jpz8mx


https://wolfram.com/xid/0g7j9qe4cru-cb2tgp


https://wolfram.com/xid/0g7j9qe4cru-3ldbb

Find conditional expectations:

https://wolfram.com/xid/0g7j9qe4cru-jp7ryg

Calculate expectation with QuantityMagnitude:

https://wolfram.com/xid/0g7j9qe4cru-uhak3z

https://wolfram.com/xid/0g7j9qe4cru-pmz8jt


https://wolfram.com/xid/0g7j9qe4cru-w0dao0

Parametric Distributions (4)
Compute expectations for univariate continuous distributions:

https://wolfram.com/xid/0g7j9qe4cru-0j2eo


https://wolfram.com/xid/0g7j9qe4cru-b6p9xj


https://wolfram.com/xid/0g7j9qe4cru-jxk2or


https://wolfram.com/xid/0g7j9qe4cru-b75rek

Compute expectations for univariate discrete distributions:

https://wolfram.com/xid/0g7j9qe4cru-jrixg


https://wolfram.com/xid/0g7j9qe4cru-iwv07c


https://wolfram.com/xid/0g7j9qe4cru-ing8ai


https://wolfram.com/xid/0g7j9qe4cru-dcq1w6

Expectations for multivariate continuous distributions:

https://wolfram.com/xid/0g7j9qe4cru-d8nd8b


https://wolfram.com/xid/0g7j9qe4cru-cpm495


https://wolfram.com/xid/0g7j9qe4cru-cz594v

Expectations for multivariate discrete distributions:

https://wolfram.com/xid/0g7j9qe4cru-f41lyn


https://wolfram.com/xid/0g7j9qe4cru-c3d04m


https://wolfram.com/xid/0g7j9qe4cru-b2t61u

Nonparametric Distributions (2)
Using a univariate HistogramDistribution:

https://wolfram.com/xid/0g7j9qe4cru-kfcmmb

https://wolfram.com/xid/0g7j9qe4cru-6hyey

A multivariate histogram distribution:

https://wolfram.com/xid/0g7j9qe4cru-bfrdge

https://wolfram.com/xid/0g7j9qe4cru-kaahos

Using a univariate KernelMixtureDistribution:

https://wolfram.com/xid/0g7j9qe4cru-cfp9dj

https://wolfram.com/xid/0g7j9qe4cru-c6dg7b

Derived Distributions (9)
Compute the expectation using a TransformedDistribution:

https://wolfram.com/xid/0g7j9qe4cru-bovfpg

An equivalent way of formulating the same expectation:

https://wolfram.com/xid/0g7j9qe4cru-h4aphr

Find the expectation using a ProductDistribution:

https://wolfram.com/xid/0g7j9qe4cru-gdjg

An equivalent formulation for the same expectation:

https://wolfram.com/xid/0g7j9qe4cru-bf0feu

Using a component mixture of normal distributions:

https://wolfram.com/xid/0g7j9qe4cru-d7u00

Parameter mixture of exponential distributions:

https://wolfram.com/xid/0g7j9qe4cru-ecfaaj

Truncated Dirichlet distribution:

https://wolfram.com/xid/0g7j9qe4cru-digppw

Censored triangular distribution:

https://wolfram.com/xid/0g7j9qe4cru-wko7c


https://wolfram.com/xid/0g7j9qe4cru-b7zw3w

An equivalent formulation for the same expectation:

https://wolfram.com/xid/0g7j9qe4cru-pefhd


https://wolfram.com/xid/0g7j9qe4cru-n8sal1


https://wolfram.com/xid/0g7j9qe4cru-cyug61

Options (7)Common values & functionality for each option
AccuracyGoal (1)
Obtain a result with the default setting for accuracy:

https://wolfram.com/xid/0g7j9qe4cru-c2zgyo

Use AccuracyGoal to obtain the result with a different accuracy:

https://wolfram.com/xid/0g7j9qe4cru-fa930j

Method (3)
Use the Method option to increase the number of recursive bisections for numerical integration:

https://wolfram.com/xid/0g7j9qe4cru-ne7b5m

https://wolfram.com/xid/0g7j9qe4cru-xav24y

Compare with the exact result from Expectation:

https://wolfram.com/xid/0g7j9qe4cru-eh32rv


https://wolfram.com/xid/0g7j9qe4cru-gf0p4u

Calculate the expectation for an expression:

https://wolfram.com/xid/0g7j9qe4cru-elis8y

Obtain an estimate based on simulation:

https://wolfram.com/xid/0g7j9qe4cru-uxrpz


https://wolfram.com/xid/0g7j9qe4cru-ouokld

Calculate the expectation of an expression:

https://wolfram.com/xid/0g7j9qe4cru-xav3b

This example uses NIntegrate:

https://wolfram.com/xid/0g7j9qe4cru-1z3u7

Use Activate to evaluate the result:

https://wolfram.com/xid/0g7j9qe4cru-fxul3e

PrecisionGoal (1)
Obtain a result with the default setting for precision:

https://wolfram.com/xid/0g7j9qe4cru-447ct

Use PrecisionGoal to obtain the result with a different precision:

https://wolfram.com/xid/0g7j9qe4cru-cbv97a

WorkingPrecision (1)
By default, NExpectation uses machine precision:

https://wolfram.com/xid/0g7j9qe4cru-bgomwb

Use WorkingPrecision to obtain results with higher precision:

https://wolfram.com/xid/0g7j9qe4cru-dcbv84

TargetUnits (1)
Create a distribution object with quantity:

https://wolfram.com/xid/0g7j9qe4cru-fmhxd7

Expectation uses the quantity provided in the distribution as default:

https://wolfram.com/xid/0g7j9qe4cru-cw0r2m

Specify the target unit to "Hours":

https://wolfram.com/xid/0g7j9qe4cru-img4h1

Applications (17)Sample problems that can be solved with this function
Distribution Properties (3)
Obtain a raw moment for a continuous distribution:

https://wolfram.com/xid/0g7j9qe4cru-jg7e


https://wolfram.com/xid/0g7j9qe4cru-bqjsef

Obtain the mean of a discrete distribution:

https://wolfram.com/xid/0g7j9qe4cru-u3r1k


https://wolfram.com/xid/0g7j9qe4cru-cx56c4

Obtain the variance of a truncated distribution:

https://wolfram.com/xid/0g7j9qe4cru-fie97e

https://wolfram.com/xid/0g7j9qe4cru-gfaje9


https://wolfram.com/xid/0g7j9qe4cru-tjdvz


https://wolfram.com/xid/0g7j9qe4cru-mi7da7

Actuarial Science (4)
An insurance policy reimburses a loss up to a benefit limit of 10. The policyholder's loss, , follows a distribution with density function
for
and 0 otherwise. Find the expected value of the benefit paid under the insurance policy:

https://wolfram.com/xid/0g7j9qe4cru-cnb2x3

An insurance company's monthly claims are modeled by a continuous, positive random variable , whose probability density function is proportional to
where
. Determine the company's expected monthly claims:

https://wolfram.com/xid/0g7j9qe4cru-lk3ogj

https://wolfram.com/xid/0g7j9qe4cru-cuigs8

Claim amounts for wind damage to insured homes are independent random variables with common density function for
and 0 otherwise, where
is the amount of a claim in thousands. Suppose 3 such claims will be made. Compute the expected value of the largest of the three claims:

https://wolfram.com/xid/0g7j9qe4cru-j3ddn8

Let represent the age of an insured automobile involved in an accident. Let
represent the length of time the owner has insured the automobile at the time of the accident.
and
have joint probability density function
for
and
, and 0 otherwise. Calculate the expected age of an insured automobile involved in an accident:

https://wolfram.com/xid/0g7j9qe4cru-lsj0oy

Sports (2)
A baseball player is a 0.300 hitter. Find the expected number of hits if the player comes to bat 3 times:

https://wolfram.com/xid/0g7j9qe4cru-e2h2rl

A basketball player shoots free throws until he hits 4 of them. His probability of scoring in any one of them is 0.7. Find the number of shots the player is expected to shoot:

https://wolfram.com/xid/0g7j9qe4cru-fk5tkt

Random Experiments (2)
Four six-sided dice are rolled. Find the expectation of the minimum value:

https://wolfram.com/xid/0g7j9qe4cru-fpwrzm

Find the expectation of the maximum value:

https://wolfram.com/xid/0g7j9qe4cru-t5ya6

Find the expectation of the sum of the three largest values. Using the identity and linearity of Expectation, you get:

https://wolfram.com/xid/0g7j9qe4cru-nmr49m

A random sample of size 10 from a continuous distribution is sorted in ascending order. A new random variate is generated. Find the probability that the 11
sample falls between the fourth and fifth smallest values in the sorted list:

https://wolfram.com/xid/0g7j9qe4cru-o9v3b2

https://wolfram.com/xid/0g7j9qe4cru-ro81w

The probability equals and is independent of
:

https://wolfram.com/xid/0g7j9qe4cru-f4zyfj

It is also independent of the distribution:

https://wolfram.com/xid/0g7j9qe4cru-cyl2kl

https://wolfram.com/xid/0g7j9qe4cru-mcfoh2

Risk Analysis (2)
Study the tail value at risk (TVaR) for the exponential distribution:

https://wolfram.com/xid/0g7j9qe4cru-ip6ykd

https://wolfram.com/xid/0g7j9qe4cru-iua9em

https://wolfram.com/xid/0g7j9qe4cru-gj2t6

https://wolfram.com/xid/0g7j9qe4cru-dree00


https://wolfram.com/xid/0g7j9qe4cru-c029p5


https://wolfram.com/xid/0g7j9qe4cru-lcy7bc

Value at risk may underestimate possible losses. Consider two models for stock log-returns:

https://wolfram.com/xid/0g7j9qe4cru-htrh1
Fix parameter so that values at risk at the 99.5% level are equal:

https://wolfram.com/xid/0g7j9qe4cru-dik478


https://wolfram.com/xid/0g7j9qe4cru-cyptj0

Now compute the expected losses in both models, given that they exceed the value at risk:

https://wolfram.com/xid/0g7j9qe4cru-f6l471

The losses are actually bigger in the second model:

https://wolfram.com/xid/0g7j9qe4cru-hh6uyn

Other Applications (4)
A drug has proven to be effective in 40% of cases. Find the expected number of successes when applied to 100 cases:

https://wolfram.com/xid/0g7j9qe4cru-nsfci1

Assuming stock logarithmic return follows a stable distribution, find the value at risk at the 95% level:

https://wolfram.com/xid/0g7j9qe4cru-borxh

https://wolfram.com/xid/0g7j9qe4cru-bmpaw7

Compute the 95% value at risk point loss of the current S&P 500 index value, assuming the above distribution:

https://wolfram.com/xid/0g7j9qe4cru-ck8szg

Find the expected shortfall of logarithmic return:

https://wolfram.com/xid/0g7j9qe4cru-k5dres

Compute the associated point loss:

https://wolfram.com/xid/0g7j9qe4cru-dyeq07

A site has mean wind speed 7 m/s and Weibull distribution with shape parameter 2:

https://wolfram.com/xid/0g7j9qe4cru-dnfa1k

The resulting wind speed distribution over a whole year:

https://wolfram.com/xid/0g7j9qe4cru-d2ugs1

The power curve for a GE 1.5 MW wind turbine:

https://wolfram.com/xid/0g7j9qe4cru-bfvx4q

https://wolfram.com/xid/0g7j9qe4cru-baimdd

The total mean energy produced over the course of a year is then 4.3 GWh:

https://wolfram.com/xid/0g7j9qe4cru-baamd9

Estimate the distribution of the lengths of human chromosomes:

https://wolfram.com/xid/0g7j9qe4cru-ghgkyu

https://wolfram.com/xid/0g7j9qe4cru-enq41

The expected chromosome length, given that the length is greater than the mean:

https://wolfram.com/xid/0g7j9qe4cru-k16csl

Properties & Relations (7)Properties of the function, and connections to other functions
The expectation of an expression in a continuous distribution is defined by an integral:

https://wolfram.com/xid/0g7j9qe4cru-js67d


https://wolfram.com/xid/0g7j9qe4cru-bv62be

The expectation of an expression in a discrete distribution is defined by a sum:

https://wolfram.com/xid/0g7j9qe4cru-b1i8wz


https://wolfram.com/xid/0g7j9qe4cru-kz9qwe

Mean, Moment, Variance, and other properties are defined as expectations:

https://wolfram.com/xid/0g7j9qe4cru-iwe9y

https://wolfram.com/xid/0g7j9qe4cru-e6in2e


https://wolfram.com/xid/0g7j9qe4cru-mfj1q


https://wolfram.com/xid/0g7j9qe4cru-cmhmlq


https://wolfram.com/xid/0g7j9qe4cru-i57lyo


https://wolfram.com/xid/0g7j9qe4cru-5fcbr

Use Expectation to find a symbolic expression for an expectation:

https://wolfram.com/xid/0g7j9qe4cru-b33zae

https://wolfram.com/xid/0g7j9qe4cru-eenbh1


https://wolfram.com/xid/0g7j9qe4cru-pkobp5


https://wolfram.com/xid/0g7j9qe4cru-bzmcmw

N[Expectation[…]] is equivalent to NExpectation if symbolic evaluation fails:

https://wolfram.com/xid/0g7j9qe4cru-ef8yf1

https://wolfram.com/xid/0g7j9qe4cru-epm0j1


https://wolfram.com/xid/0g7j9qe4cru-cezvyb


https://wolfram.com/xid/0g7j9qe4cru-db3rgk

Use AsymptoticExpectation to find an asymptotic approximation of an expectation:

https://wolfram.com/xid/0g7j9qe4cru-c6y4hq

https://wolfram.com/xid/0g7j9qe4cru-dsw2cp


https://wolfram.com/xid/0g7j9qe4cru-ddpn4p


https://wolfram.com/xid/0g7j9qe4cru-pqwjh

Compute the probability of an event:

https://wolfram.com/xid/0g7j9qe4cru-m8g5dj

Obtain the same result using NExpectation:

https://wolfram.com/xid/0g7j9qe4cru-efo8y8

Possible Issues (1)Common pitfalls and unexpected behavior
NExpectation may fail without a warning message in the presence of symbolic parameters:

https://wolfram.com/xid/0g7j9qe4cru-lyjhp

Expectation gives a closed-form result for this example:

https://wolfram.com/xid/0g7j9qe4cru-cuwaqz

Wolfram Research (2010), NExpectation, Wolfram Language function, https://reference.wolfram.com/language/ref/NExpectation.html.
Text
Wolfram Research (2010), NExpectation, Wolfram Language function, https://reference.wolfram.com/language/ref/NExpectation.html.
Wolfram Research (2010), NExpectation, Wolfram Language function, https://reference.wolfram.com/language/ref/NExpectation.html.
CMS
Wolfram Language. 2010. "NExpectation." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/NExpectation.html.
Wolfram Language. 2010. "NExpectation." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/NExpectation.html.
APA
Wolfram Language. (2010). NExpectation. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/NExpectation.html
Wolfram Language. (2010). NExpectation. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/NExpectation.html
BibTeX
@misc{reference.wolfram_2025_nexpectation, author="Wolfram Research", title="{NExpectation}", year="2010", howpublished="\url{https://reference.wolfram.com/language/ref/NExpectation.html}", note=[Accessed: 09-July-2025
]}
BibLaTeX
@online{reference.wolfram_2025_nexpectation, organization={Wolfram Research}, title={NExpectation}, year={2010}, url={https://reference.wolfram.com/language/ref/NExpectation.html}, note=[Accessed: 09-July-2025
]}