Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Apologies if this is a duplicate, but I couldn't find it.

The expression

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

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

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

returns

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
1  
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
add comment

1 Answer

up vote 1 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:

Attributes@Integrate
(* {Protected,ReadProtected} *)

Attributes@NIntegrate
(* {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
add comment

Your Answer

 
discard

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.