Particularly when applied to calculating the (population) mean of a (continuous univariate) random variable, as in

dist2alt = 
  x \[Distributed] NoncentralFRatioDistribution[5, 4, 0, 7.2]]

(* 1.30371 *)

, what are the (numerical) methods used internally by the sentence N?

Does Mathematica provide any details about the concrete (numerical) methods used in a concrete execution of N, the number of iterations needed, etc.?


1 Answer 1


The Mean doc page says,

Mean[dist] is equivalent to Expectation[x,x\[Distributed]dist].

The Expectation doc page says,

N[Expectation[...]] calls NExpectation for expectations that cannot be done symbolically.

NExpectation can use NIntegrate, whose options can be specified through Method.

When you use Mean, the default (automatic) settings will be used. If you need more control, use the equivalent NExpectation. If you need control over how NExpectation calls NIntegrate, use its Method option.

  • $\begingroup$ Thank you! Is there a way to know what method is NIntegrate using in a given computation? (the documentation says that the default option is Automatic, which is like "choose the best method for this concrete case") The point is that I am able to give numerical results to some computations of means and variances using N, but I should be able to give a detailed way to reproduce them. $\endgroup$
    – Vicent
    Sep 8, 2017 at 12:18
  • $\begingroup$ @Vicent mathematica.stackexchange.com/q/26401/12 $\endgroup$
    – Szabolcs
    Sep 8, 2017 at 12:22
  • $\begingroup$ @Vicent I'd say that, in general, the most important thing is not to give steps to reproduce a certain numerical result precisely. It is more important to be able to carry out the calculation fully manually (not necessarily to do all steps), and through this understanding decide if a reasonably competent person can be expected to reproduce your calculations using any tool (not necessarily Mathematica). If there are any steps which seem particularly difficult, discuss those steps only. In addition, check all results returned by Mathematica (or whatever system you are using) in some way. $\endgroup$
    – Szabolcs
    Sep 8, 2017 at 12:37
  • $\begingroup$ All systems have bugs, and sometimes give wrong results, even for calculations which should be simple. You can look at your integrand and see if it's simple, then try increasing the precision and integration points in NIntegrate and see if the result is stable. $\endgroup$
    – Szabolcs
    Sep 8, 2017 at 12:39
  • $\begingroup$ After checking out the link you provided (very interesting!),it seems clear to me that it is nearly impossible trying to explain or reproduce in a detailed way the method used by Mathematica to numerically calculate a given mean or variance, apart from "applying a combination of numerical methods". Now I think I am going to focus on finding an approximation that is accurate enough and easy to implement by other researchers. What do you think? $\endgroup$
    – Vicent
    Sep 8, 2017 at 14:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.