Using Mathematica I want to solve an integral over a function that contains both determined and undetermined parts which looks like this:

r[\[Theta], z] = Sqrt[(h/2)^2 - z^2] + g[\[Theta]] - h/2

As you can see the h/2 and root terms are determined, but g remains an undetermined function of $\theta$. Now I take an integral over this function to both z and theta:

V = Integrate[[Integrate[1/2 r[\[Theta], z]^2, {z, -h/2, h/2}], {\[Theta], 0, 2 \[Pi]}]

which results in:

$$V= \int_0^{2 \pi } \left(\frac{1}{8} (\pi -4) h^2 g(\theta )+\frac{1}{2} h g(\theta )^2+\frac{1}{48} (10-3 \pi ) h^3\right) \, d\theta$$

As you can see, the last term contains no dependence on $\theta$ and therefore I would like that part of the integral solved. In particular I would like my result to look like this $$V=\frac{1}{24} (10-3 \pi )\pi h^3 + \frac{1}{8} (\pi -4) h^2 \int_0^{2 \pi }g(\theta )\, d\theta+\frac{1}{2} h \int_0^{2 \pi }g(\theta )^2 \, d\theta$$

Is there some way to force mathematica to solve the parts of the function that are not dependent (or with known dependence) on the variable towards which I integrate?


1 Answer 1


Yes, there is such a way. Try this, for example. First define a function to integrate;

int[expr_] := Integrate[expr, {z, -h/2, h/2}, {\[Theta], 0, 2 \[Pi]}]

Then map this function onto the terms of your expression:

r[\[Theta], z] = Sqrt[(h/2)^2 - z^2] + g[\[Theta]] - h/2;

Map[int, Expand[1/2 r[\[Theta], z]^2]]

This results in:

$$\int_0^{2 \pi } -\frac{1}{2} h^2 g(\theta ) \, d\theta +\int_0^{2 \pi } \frac{1}{8} \pi h^2 g(\theta ) \, d\theta +\int_0^{2 \pi } \frac{1}{2} h g(\theta )^2 \, d\theta +\frac{1}{24} \pi (10-3 \pi ) h^3 $$

  • 1
    $\begingroup$ Great, thanks! Quick comment: did you know that you can copy the output of mathemetica directly as latex by right-clicking on the equation and selecting "Copy as -> Latex"? $\endgroup$
    – Michiel
    Commented Jul 4, 2014 at 12:12
  • $\begingroup$ @Michiel No, I did not. $\endgroup$ Commented Jul 4, 2014 at 14:40

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.