# How to integrate a vector function in spherical coordinates?

### How to integrate a vector function in spherical coordinates?

In my specific case, it's an electric field on the axis of charged ring (see image below), the integral is pretty easy, but I don't understand how handle the vector $(r,\theta,\phi)$ while integrating over $\phi$.

I tried the following:

$$\vec{E}=\int\limits_{Q}{\frac{kdq}{\|\vec{r}\|^3}\vec{r}}$$ $$=\int_0^{2\pi}{\frac{k\lambda \vec{r}sin\theta d\phi}{\|\vec{r}\|^3}\vec{r}}$$ $$=\int_0^{2\pi}{\frac{k\lambda Rd\phi}{\|\vec{r}\|^3}\vec{r}}$$ $$=\frac{k\lambda R}{\|\vec{r}\|^3}\int_0^{2\pi}{\vec{r}d\phi}$$

Now, if I convert $\vec{r}$ to $(x,y,z)$ coordinates and integrate it's ok:

$$\int_0^{2\pi}{\vec{r}d\phi}=\int_0^{2\pi}{r(sin\theta cos\phi,sin\theta sin\phi,cos\theta)d\phi} = 2\pi r(0,0,cos\theta)=2\pi z\hat{z}$$

Putting it in the original expression will give the correct result.

But trying to do the following in spherical coordinates failed:

$$\int_0^{2\pi}{\vec{r}d\phi}=\int_0^{2\pi}{(r,\theta,\phi)d\phi} = {2\pi(r,\theta,\pi)}$$

Which is completely wrong...

### What am I doing wrong?

-

In that final integral, I think you are making the very old, very common mistake of just thinking of a vector as three numbers. It is easy to do this because we learn about vectors in Cartesian coordinates first, and in Cart coords, thinking of a vector as three numbers is easy because it works. $\vec{r}$ is absolutely not $(r,\theta,\phi)$. Rather, $\vec{r}$ is $r\hat{r}$, and $\hat{r}$ depends on $\theta$ and $\phi$. The integral you want to calculate is
$\int \vec{r} d\phi = \int r\hat{r} d\phi = \int r\hat{r}(\theta,\phi) d\phi$
Actually, I don't like the way that looks on my screen, but what I am trying to emphasize is that $\hat{r}$ is a function of $\theta$ and $\phi$. Therefore $\hat{r}$ is different at each value of $\phi$ and this change with $\phi$ has to be calculated correctly for you to do the integral correctly. And, last of all, you need to understand that as you "add" each little piece of your integral, it is like adding a new vector to a sum. And the various vectors will all partically cancel and partially reinforce each other.
How would you express $\hat{r}$ without converting back to cartesian coordinates? –  User Apr 17 '13 at 9:59
To your first question, yes each coordinate should be independent of the others. But a vector is not just a set of coordinates. In Cartesian coords it's easy to think of it that way, because it works. But we can't do that when we move to other coordinates. Try to think of it this way: A vector is "a thing unto itself". Its components in a particular coordinate system are just a way of expressing it in that coordinate system, nothing more. The coords $(r,\theta,\phi)$ define a location in space, sure. The vector $\vec{r}$ is the thing pointing to that location. –  bob.sacamento Apr 17 '13 at 15:25
To your second question, when we are in spherical coordinates $\hat{r}$ is just something "fundamental" that can't be expressed any other way. It certainly can't be expressed as any $a\hat{\theta}+b\hat{\phi}$ because $\hat{r}$ is always normal to $\hat{\theta}$ and $\hat{\phi}$. So, yes, if you want to express it as anything other than $\hat{r}$, you'll have to use Cart coords somehow. A couple of different ways would be $\hat{r}=\sin\theta\cos\phi\hat{x}+\sin\theta\sin\phi\hat{y}+\cos\theta\hat{z}=(‌​x\hat{x}+y\hat{y}+z\hat{z})/\sqrt{x^2+y^2+z^2}$. –  bob.sacamento Apr 17 '13 at 15:31
Let me rephrase part of my first comment: the coords $(r,\theta,\phi)$ are a way of indicating a location in space. But $\vec{r}$ is that location itself. It's kind of like the difference between the number 2 and the numeral "2" that we use to represent the number 2. In your final integral, you are trying to integrate over the representations of several locations, when you need to be integrating over the locations themselves. –  bob.sacamento Apr 17 '13 at 15:47