Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The expression

Integrate[x^2, Flatten[{{x},{1,2}}]]

evaluates properly, to $\frac{7}{3}$. However,

NIntegrate[x^2, Flatten[{{x},{1,2}}]]


NIntegrate::vars: Integration range specification Flatten[{{x},{1,2}}] is not of the form {x, xmin, ..., xmax}. >>

An explicit Evaluate is required on the second parameter to make this work. So I assume that NIntegrate has a HoldAll on its second parameter.

Did I have any way of knowing this before hand? That is, is this behavior documented? And, if it is (or even if it is not), why do the two functions behave differently?

share|improve this question
Such information can be found at the end of the "Details and Options" section in the documentation for NIntegrate (and for other functions, too). Try also executing Attributes[NIntegrate]. – Michael E2 Nov 12 '13 at 2:48
@MichaelE2 Thanks. So do you also know why the two functions (should) behave differently? Also, if you want to post this as an answer, I'll accept it. – rogerl Nov 12 '13 at 21:01
"…NIntegrate has a HoldAll on its second parameter…" - well, HoldAll does mean what it says; all inputs given are held. – J. M. May 26 '15 at 23:49
up vote 2 down vote accepted

The reason that it works for Integrate and not for NIntegrate is that NIntegrate has the attribute HoldAll and Integrate does not. Attributes, if any, are listed at the end of the "Details and Options" section of the documentation page for a function. They may also be inspected with the Attributes command:

(* {Protected,ReadProtected} *)

(* {HoldAll,Protected} *)

Aside from the difference point out by the OP, there is also this one if x has a value:

x = 4
(* 4 *)

NIntegrate[x^2, {x, 1, 2}]
(* 2.33333 *)

Integrate[x^2, {x, 1, 2}]

Integrate::ilim: Invalid integration variable or limit(s) in {4,1,2}. >>

I do not know why the developers have chosen to treat these similar functions differently.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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