5
$\begingroup$

I am an advanced novice Mathematica user and have done a fair amount of single-variable calculus things with it. This semester I am using Mathematica for multi-variate calculus and when I tried to use Mathematica to solve a double integral I got incorrect results. I discovered that the syntax for the Integrate command has you list the variables in the opposite order they appear in the integrand. At first blush this seems dumb and annoying but perhaps there is a good reason for it. If so, I'd like to know what it is. If not, is anyone else annoyed by this?

$\endgroup$
6
  • $\begingroup$ "Multiple integrals use a variant of the standard iterator notation". Straight from the documentation. Just Mathematica convention. $\endgroup$
    – ciao
    Apr 12, 2014 at 1:48
  • $\begingroup$ I'm ashamed to admit I don't even understand the question. Integrate[x + y, {x, 0, a}, {y, 0, b}] seems fine to me. What opposite order? Can someone explain the problem to me? I'm not trying to criticise the question, I'm just curious. $\endgroup$
    – user484
    Apr 12, 2014 at 4:18
  • 2
    $\begingroup$ @RahulNarain The issue that OP has (which I must admit I empathize with) is that Integrate[x+y,{x,0,a},{y,0,f[x]}] refers to an integral $\int_0^a\int_0^{f(x)}(x+y)dydx$. The inversion of the $dydx$ terms with the iterator may seem unnatural to some. $\endgroup$
    – VF1
    Apr 12, 2014 at 5:19
  • $\begingroup$ Well, you just have to use the physicists' convention to get the right ordering of the variables: $\int_0^a\mathrm dx \int_0^{f(x)}\mathrm dy\,(x+y)$ $\endgroup$
    – celtschk
    Apr 12, 2014 at 19:56
  • 2
    $\begingroup$ It's a convention one simply has to get used to (read: I don't know why we did it that way either, and I also never much liked it). There may well be a good reason that nobody has ever explained to me. $\endgroup$ Apr 13, 2014 at 19:23

1 Answer 1

8
$\begingroup$

This ordering is used in all functions in Mathematica, not just Integrate.

Here's an example with Table:

In[1]:= Table[f[i, j], {i, 3}, {j, 4}]
Out[1]= {{f[1, 1], f[1, 2], f[1, 3], f[1, 4]}, 
         {f[2, 1], f[2, 2], f[2, 3], f[2, 4]}, 
         {f[3, 1], f[3, 2], f[3, 3], f[3, 4]}}

The inner loop is according to j, the outer according i.

In[2]:= Dimensions[%]
Out[2]= {3, 4}

Looking at the dimensions it starts to make some kind of sense for Table. Even more if I write it like this:

In[3]:= Table[0, {3}, {4}]
Out[3]= {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}

Which I could replace by

In[4]:= ConstantArray[0, {3, 4}]
Out[4]= {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}

Now for ConstantArray it makes perfect sense: if I want an array with dimensions {3,4}, I'll write {3,4} in ConstantArray.

It also makes sense to make all these functions consistent with each other, so you never have to think about which convention a particular function uses: they all use the same.

In the end of course it is just a convention, and I don't think that this particular convention is better than others. I just wanted to point out that it does make sense, as it's consistent with the rest of the system: Integrate, Sum, Table, RandomReal, etc. all work the same way.

$\endgroup$
2
  • $\begingroup$ Thanks Szabolcs, I figured there had to be a reason and you provided a solid explanation of why. I think I'll just use the symbolic mode for double and triple integrals since I know I will screw them up otherwise. Thanks :) $\endgroup$
    – Glenn
    Apr 12, 2014 at 3:17
  • 1
    $\begingroup$ Perhaps the convention is so you can form a single-variable integral, then cut and paste another single-variable integral into the argument of the first integral, thus yielding the "reverse" order of integration variables. $\endgroup$ Jun 26, 2015 at 17:38

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