Deriving gradient in spherical coordinates

Click For Summary
The discussion centers on deriving the gradient in spherical coordinates, with participants expressing challenges in recalling the professor's method and the complexity of using the chain rule. They note that while deriving the gradient in polar coordinates was lengthy, the transition to spherical coordinates is more complicated due to the necessary change of basis from Cartesian to spherical coordinates. Participants discuss using linear algebra techniques, such as matrix inverses and Cramer's Rule, to facilitate this process, emphasizing the importance of organization and careful calculation. There is also a focus on the tedious nature of calculating partial derivatives and ensuring consistency in notation for spherical coordinates. Ultimately, the conversation highlights the intricate relationship between different coordinate systems and the mathematical rigor required to navigate them effectively.
Shackleford
Messages
1,649
Reaction score
2
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.

sph.jpg
 
Physics news on Phys.org
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}

This page goes into more detail:

http://math.mit.edu/classes/18.013A/HTML/chapter09/section04.html
 
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:
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:
vela said:
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.


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.
 
vela said:
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.

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.? :eek: They're very nasty.
 
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
 
Last edited by a moderator:
Shackleford said:
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.? :eek: They're very nasty.
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.
Shackleford said:
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
This page is actually deriving the Laplacian, not the gradient.
 
Last edited by a moderator:
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
vela said:
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.

This page is actually deriving the Laplacian, not the gradient.

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
vela said:
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.

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.

sph-1.jpg
 
  • #12
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
vela said:
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.

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
Shackleford said:
Hybrid gradient?
:smile: 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.
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.
Yeah, that's right.
 
  • #15
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
I'm not sure how you're getting that. You have θ=cos-1(y/x), so ∂θ/∂z=0 by inspection.
 
  • #17
vela said:
I'm not sure how you're getting that. You have θ=cos-1(y/x), so ∂θ/∂z=0 by inspection.

Well, d(phi)/dz is 0.
 
  • #18
Oh, so you're not following the convention used in your initial post, where theta and phi were backwards (mathematicians would disagree)?
 
  • #19
vela said:
Oh, so you're not following the convention used in your initial post, where theta and phi were backwards (mathematicians would disagree)?

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.
 

Similar threads

  • · Replies 7 ·
Replies
7
Views
1K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
33
Views
4K
Replies
2
Views
1K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 4 ·
Replies
4
Views
9K
  • · Replies 4 ·
Replies
4
Views
2K