Homework Help: Deriving gradient in spherical coordinates

1. May 5, 2010

Shackleford

I looked at my notes, but they're either incomplete or I simply forgot what the professor did to derive the gradient in spherical coordinates. Once I know that, deriving the divergence and curl given the supplementary equations listed is fairly straightforward. It was a little easier but certainly lengthy to do this for polar coordinates. We started by using the known formula for gradient in Cartesian coordinates and then using the chain rule with the Cartesian-to-polar coordinates equations to derive the polar coordinates gradient formula. However, consider this would be greatly more involved considering the Cartesian-to-spherical coordinates equations, I'm thinking there was a short-cut used that I didn't put in my notes. Thanks for any help.

2. May 7, 2010

vela

Staff Emeritus
Compare what the chain rule gives you:

$$df = \frac{\partial f}{\partial r} dr + \frac{\partial f}{\partial \theta} d\theta + \frac{\partial f}{\partial \phi} d\phi$$

with what the gradient gives you

$$df = (\nabla f)\cdot d\vec{r}$$

http://math.mit.edu/classes/18.013A/HTML/chapter09/section04.html

3. May 7, 2010

Shackleford

We didn't take the second approach, the change in distance/dot product one. We've used the chain rule extensively in this class.

Looking at using the chain rule method from Cartesian coordinates, it's going to be a ridiculously nasty process, and, I also don't know how to find ex, ey, and ez in spherical coordinates.

Last edited: May 7, 2010
4. May 7, 2010

vela

Staff Emeritus
Well, if you insist on doing it the painful way, there's really no way to avoid the pain. It's really not that bad, though. Just keep everything organized and check your steps along the way.

Going from ex, ey, and ez to er, eϕ, and eθ (or back) is just a change of basis. In other words, you're trying to solve equations like

ex = a1er + a2eϕ + a3eθ

It's just three linear equations and three unknown.

Last edited: May 7, 2010
5. May 7, 2010

Shackleford

Well, I wasn't quite following the other method, honestly.

A few of us met in his office yesterday and he set up a matrix. He said we would just be looking for the inverse matrix. He used Cramer's Rule, but I'm not familiar with it. I think it involves the inverse matrix equaling the adjoint matrix over the determinant of the matrix. The adjoint matrix is the cofactor matrix transpose. That was all new to me. I'm actually going to go out tonight on a Friday after work. I'll have to start this later tonight and scan it when I come to a stopping point. Thanks again for your help.

6. May 8, 2010

Shackleford

I don't see how it's easier even using linear algebra. Say I do the change of basis into ex, ey, and ez in terms r, phi, and theta, I'll still have to use the chain rule when I write down the gradient equation. The partial of phi with respect to x? theta with respect to theta, etc.? They're very nasty.

7. May 8, 2010

Shackleford

Actually, I think I found what I'm looking for.

http://planetmath.org/encyclopedia/%3Chttp://planetmath.org/?method=l2h&from=collab&id=76&op=getobj [Broken]

Last edited by a moderator: May 4, 2017
8. May 8, 2010

vela

Staff Emeritus
There are two steps to the problem. One is calculating the gradient in terms of the derivatives with respect to r, phi, and theta by using the chain rule. The second is writing it in terms of er, ephi, and etheta; this part is just a change-of-basis problem. I had assumed this was your approach, and that's what I was talking about as well. I didn't mean to suggest a different way to solve the problem.

To use the chain rule, you're going to have to calculate those derivatives. Tedious, yes. Nasty, not so much. As you have seen on that page you found, the derivatives expressed in spherical coordinates are actually pretty simple in form.

The matrix A whose columns are er, ephi, and etheta is the one that takes you from coordinates in the spherical basis to coordinates in the Cartesian basis. What you need is its inverse. If you note that A is also a rotation matrix, you should realize A is an orthogonal matrix; therefore, its inverse is just its transpose.

Last edited by a moderator: May 4, 2017
9. May 8, 2010

vela

Staff Emeritus
To elaborate a bit more, after the chain rule step, you'll have

$$\nabla f = (\textrm{stuff})\hat{e}_x + (\textrm{stuff})\hat{e}_y + (\textrm{stuff})\hat{e}_z$$

where the stuff is expressed in terms of the spherical coordinates. To get your final answer, you want to change basis by multiplying the vector by A-1.

If you're not comfortable with the matrix stuff, you can solve equations like

ex = a1er + a2eϕ + a3eθ

to express the Cartesian basis vectors in terms of the spherical basis vectors and then substitute the results into your expression for the gradient and then simplify.

10. May 8, 2010

Shackleford

Yeah, sorry. As for that page, I meant that (2), (7), and (8) are very helpful. Now, I can plow through the chain rule less painfully. The rest, as you noted, is unrelated to what I'm doing.

11. May 8, 2010

Shackleford

Yeah, d/dx, d/dy, and d/dz will be in terms of r, phi, and theta. I'm familiar with the process in polar coordinates, but it was just a bit easier.

Is this the correct system I want to solve? This is what the professor wrote down. I want the inverse of the large matrix. And are you saying its inverse is its transpose? I've taken linear algebra, by the way. It was in fall 2008, though, so I am a bit rusty but still confident in doing linear algebra.

12. May 8, 2010

vela

Staff Emeritus
That's the matrix you want already. It converts vectors in the cartesian basis and gives you their coordinates in the spherical basis. You might notice that its rows are equal to the spherical basis vectors. Also, if you multiply it by its transpose, you'll get the identity matrix, so yes, its inverse is its transpose.

If you multiply the hybrid gradient by the matrix you have there, you should get the answer you shooting for.

13. May 8, 2010

Shackleford

Yeah, I know the rows are the spherical basis vectors. That's where I got it. Hybrid gradient? If I'm understanding this correctly, then

ex = cos(theta)sin(phi)-er +cos(theta)cos(phi) e-theta + -sin(theta) e-phi
ey = sin(theta)sin(phi)-er +sin(theta)cos(phi) e-theta + cos(theta) e-phi
ez = cos(phi)-er -sin(phi) e-theta + 0 e-phi

I hope that's right. lol.

14. May 8, 2010

vela

Staff Emeritus
Well, you have the gradient in Cartesian coordinates

$$\nabla = \textbf{e}_x \frac{\partial}{\partial x} + \textbf{e}_y \frac{\partial}{\partial y} + \textbf{e}_z \frac{\partial}{\partial z}$$

and in spherical coordinates

$$\nabla = \textbf{e}_r \frac{\partial}{\partial r} + \textbf{e}_\phi \frac{1}{r} \frac{\partial}{\partial \phi} + \textbf{e}_\theta \frac{1}{r \sin \phi} \frac{\partial}{\partial \theta}$$

but

$$\nabla = (\textrm{spherical stuff})\hat{e}_x + (\textrm{spherical stuff})\hat{e}_y + (\textrm{spherical stuff})\hat{e}_z$$

is like a cross, or hybrid, between the two.
Yeah, that's right.

15. May 9, 2010

Shackleford

Well, I've worked out dr/dx, dr/dy, dr/dz, d(phi)/dx, d(phi)/dy, d(phi)/dz.

I'm having trouble with d(theta)/dx, d(theta)/dy, and for d(theta)/dz, I get

-1/[r*sin(theta)]

16. May 9, 2010

vela

Staff Emeritus
I'm not sure how you're getting that. You have θ=cos-1(y/x), so ∂θ/∂z=0 by inspection.

17. May 9, 2010

Shackleford

Well, d(phi)/dz is 0.

18. May 9, 2010

vela

Staff Emeritus
Oh, so you're not following the convention used in your initial post, where theta and phi were backwards (mathematicians would disagree)?

19. May 9, 2010

Shackleford

Oh, damn, I didn't even notice that. I was checking my work with the website I posted earlier. I just need to switch theta and phi from that website to be consistent with our (original) notation - r, phi, theta, not r, theta, phi.