NExpectation
A numeric-only — falls back to summation/quadrature where Expectation stays symbolic.
NExpectation(f, Distributed(x, dist))tries the exact Expectation first; otherwise sums (discrete) or integrates (continuous) numerically. Always returns a machine float.Typed signatures
| Type | Package | Applies |
|---|---|---|
(any, expression<Distributed>) -> number | statistics | always |
Details
- Tries
Expectation(f, Distributed(x, dist))first — a real (exact) answer whenever it resolves, just converted to a float. Only falls back to a numeric approximation pastExpectation's own reach:fpast a linear/quadratic polynomial inx, or a distributionExpectationhas no closed form for at all. - Discrete, finite support (e.g. BinomialDistribution): an exact finite sum, converted to a float.
- Discrete, infinite support (e.g. PoissonDistribution): summed with an infinite-tail cutoff — stops once the cumulative PDF mass is within of and the current term is below .
- Continuous: double-exponential (tanh-sinh) quadrature, generalized to a finite interval, a semi-infinite one, or the whole real line depending on the distribution's domain, converging to the same relative tolerance.
- Distributions this package has no tabulated support/domain for (including every wave-4 compound distribution — TruncatedDistribution, MixtureDistribution, etc.) stay unevaluated — a documented gap, not a bug.
Examples
Basic #
for ; — cross-checked against wolframscript's N[Expectation[Sin[x], x \[Distributed] NormalDistribution[2,3]], 10]. Expectation itself stays unevaluated here (Sin is past its linear/quadratic reach).
exactly, up to quadrature round-off; cross-checked against wolframscript's N[Expectation[x^3, x \[Distributed] ExponentialDistribution[2]], 10].
Scope #
for — an infinite discrete sum with a tail cutoff, cross-checked against wolframscript's N[NExpectation[1/(x+1), x \[Distributed] PoissonDistribution[3]], 10].
A finite discrete sum over ; cross-checked against wolframscript's N[NExpectation[x^3, x \[Distributed] BinomialDistribution[5, 2/5]], 10].
About
| Examples | 4 |
|---|
See also: Expectation, NProbability, Distributed