# Understanding output of multivariable integration

I'm new to Mathematica and I'm trying to integrate this function:

K = Function[{x,theta},
((b - x^3 (d/(Cos[theta])^2 - b/x)^3) (e - 2 b/x)^3/(((b - x^3 (e - 2 b/x)^3)
(d/(Cos[theta])^2 - b/x)^3))) Sin[theta]]


from $\theta = 0$ to $\theta = \pi$ and from $x = c$ to $x = \frac{f \cos^2(\theta)}{a + \cos^2(\theta)}$ by executing this command:

Integrate[K, {theta, 0, Pi}, {x, c, f((Cos[theta])^2)/(a + (Cos[theta])^2)}].


However, when I do this, the output is $\pi \left(-\left(\left(\sqrt{\frac{a}{a+1}}-1\right) f+c\right)\right) Function\left(\{x,\text{theta}\},\frac{\sin (\text{theta}) \left(\left(e-\frac{2 b}{x}\right)^3 \left(b-x^3 \left(\frac{d}{\cos ^2(\text{theta})}-\frac{b}{x}\right)^3\right)\right)}{\left(b-x^3 \left(e-\frac{2 b}{x}\right)^3\right) \left(\frac{d}{\cos ^2(\text{theta})}-\frac{b}{x}\right)^3}\right)$

What is the meaning of the Function part of this result?

The result seems like it's a product of the constants and the function itself, but this doesn't make sense because I clearly specified integration limits.

-
Two things. First, K is a system variable, so should not be used, and, in general, caution should be used when capitalizing variable names as you can run into conflicts. Second, did you look up Function in the help? What about Integrate? Do the integrands use Function? –  rcollyer Aug 19 '13 at 16:17
I did read about Integrate, but when I do Integrate[((b - x^3 (d/(Cos[theta])^2 - b/x)^3) (e - 2 b/x)^3/(((b - x^3 (e - 2 b/x)^3) (d/(Cos[theta])^2 - b/x)^3))) Sin[theta], {theta, 0, Pi}, {x, c, f ((Cos[theta])^2)/(a + (Cos[theta])^2)}], like the form of inputs in the help, it just outputs $\int _0^{\pi }\int _c^{\frac{f \cos ^2(\text{theta})}{a+\cos ^2(\text{theta})}}\frac{\sin (\text{theta}) \left(e-\frac{2 b}{x}\right)^3 \left(\left(b-d x \sec ^2(\text{theta})\right)^3+b\right)}{\left((2 b-e x)^3+b\right) \left(d \sec ^2(\text{theta})-\frac{b}{x}\right)^3}dxd\text{theta}$ –  Libby Aug 20 '13 at 7:07
The integral has 20 terms, and each just as nasty as the last. I would have been surprised if Mathematica could have handled it. You're going to have to try substitutions. –  rcollyer Aug 20 '13 at 12:40
I'm still curious about what the Function part of my original question means, though. The terms that come before it seem plausible based on the sort of result I expect, and when I do Integrate using other simple Functions (like x^2) as arguments, it seems to work fine. –  Libby Aug 20 '13 at 12:54
Left an answer to that question. –  rcollyer Aug 20 '13 at 13:46

This was to long for a comment.

Function is a transformation rule, and scoping construct. It allows the user to avoid defining a dependent variable, e.g.

Function[{x}, x^2]


is equivalent to

y[x_] := x^2


but in the second case y is now associated with the transformation (see DownValues) which is not always desirable, or necessary. Outside of Function, or the definition of y, x has no meaning, so functions like Integrate cannot access it, even if the integration variable has the same name. The two do not exist in the same scope. (This is called lexical scoping, and in a sense, the variables have unique names. Module and With operate in a similar manner. Block does not.) In your integral, you wrote the equivalent of

$$\int^b_a f \, \mathrm{d}x$$

which, strictly speaking, is an abuse of notation. We implicitly assume that $f$ is a function of $x$, but $f$ could just as easily be a constant. In mathematics, we can get away with this because there is usually enough extra information to infer what we mean by $f$. In Mathematica, we do not have that luxury, and Mathematica interpreted the Function as a constant. This occurred even with the presence of x and theta in it because of their scoped nature. To be mathematically correct, you are looking for the equivalent of

$$\int^b_a f(x) \, \mathrm{d}x,$$

or

Integrate[Function[{x}, x^2][x], {x, a, b}]
Integrate[y[x], {x, a, b}]


Note, the square brackets. Unless you need it, because of the complexity of the function, the use of Function here is overkill, and the expression should be used directly

Integrate[x^2, {x, a, b}]

-
Thank you; that's really helpful! –  Libby Aug 21 '13 at 11:42