# Mathematica: Substituting in for integrand

1. Mar 15, 2012

### Arijun

I would like to be able to write my integrand before my integral and then have my integral be more compact. However Mathematica does not seem to like when I try and substitute in my dq's. Is there a way to tell mathematica to evaluate the substitution before evaluating the integral?(and, I guess, maintaining the order of my dq's, since I think mathematica would have a hard time parsing the integral if it assumes the dq's commute with the rest of the integrand)

This is what I'm trying to integrate:
$$\text{dg}\text{:=}G \rho /r`^2\ \text{dVol};\ \text{dVol}\text{:=}\sin [\theta ]\ r^2\ d\phi \ d\theta \ dr; \\g=\int _0^R\int _0^{\pi }\int _0^{2\pi }\text{dg}$$
In case you're wondering, it's the gravitational field outside a uniform sphere.

2. Mar 16, 2012

### djelovin

You can't do that!

3. Mar 21, 2012

### Arijun

4. Mar 22, 2012

### Bill Simpson

I'm not convinced it is completely hopeless.

But what you are trying to do is subvert the usual evaluation process and that is almost always problematic.

While it isn't "desktop publishing" your input, which is what I suspect you REALLY want, this does work:

In[1]:= dg=Sequence[Sin[θ]r^2,θ,r];

In[2]:= Integrate[dg]

Out[2]= -1/3 r^3 Cos[θ]

Other than inserting that Sequence[] and writing θ,r instead of dθ,dr that is close to what you wrote.

Sequence[] allows you to enter a bare collection of comma separated items and Integrate is looking for an integrand separated by a comma from the variable of integration.

Unfortunately at the moment I don't see a way to do definite integrals where the limits of integration are separated from the integrand and variable of integration.

But I would not be too surprised if some much brighter person who really understands the depths of MMA evaluation could come up with some way of doing what you want. You might try asking your question in a couple of other places where a few of the really skilled folks will take the time to answer interesting puzzles.

Last edited: Mar 22, 2012
5. Mar 24, 2012

### Hepth

What about something like defining each integration variable separate?

d\[Phi] = {\[Phi], 0, 2 \[Pi]};
d\[Theta] = {\[Theta], 0, \[Pi]};
dr = {r, 0, R};
POT = G \[Rho]/r^2;
dVol = Sequence[POT Sin[\[Theta]] r^2 , d\[Phi], d\[Theta], dr]
Integrate[dVol]