How to obtain the gradient of $T(x,y,z)$, in spherical coordinates for the spherical basis vectors using Maple?

64 Views Asked by At

Let $T(x,y,z)$ be a function.

Then $$\nabla T=\frac{\partial T}{\partial x}\hat{i}+\frac{\partial T}{\partial y}\hat{j}+\frac{\partial T}{\partial z}\hat{k}\tag{1}$$ is the gradient of $T$.

I would like to obtain $\nabla T$ in spherical coordinates and in terms of the spherical basis vectors $\hat{r}$, $\hat{\theta}$, and $\hat{\phi}$.

This is a big calculation to do by hand. I would like to do the calculation as way of exercise. I gave up halfway by hand to try with Maple.

I believe I know the steps required, but I would like Maple to some of the parts in between the steps. However, I start to obtain huge expressions in Maple.

Here are the steps.

From a previous calculation, I know what $\hat{i}$, $\hat{j}$, and $\hat{k}$ are in terms of $\hat{r}$, $\hat{\theta}$, and $\hat{\phi}$:

$$\hat{i}=sin(\theta)cos(\phi)\hat{r}+cos(\theta)cos(\phi)\hat{\theta}-sin(\phi)\hat{\phi}\tag{2}$$

$$\hat{j}=sin(\theta)sin(\phi)\hat{r}+cos(\theta)sin(\phi)\hat{\theta}+cos(\phi)\hat{\phi}\tag{3}$$

$$\hat{k}=cos(\theta)\hat{r}-sin(\theta)\hat{\theta}\tag{4}$$

As for the terms $\frac{\partial T}{\partial x}$, $\frac{\partial T}{\partial y}$, and $\frac{\partial T}{\partial z}$, I can obtain them as follows:

$$\frac{\partial T}{\partial x}=\frac{\partial T}{\partial r} \frac{\partial r}{\partial x}+\frac{\partial T}{\partial \theta} \frac{\partial \theta}{\partial x}+\frac{\partial T}{\partial \phi} \frac{\partial \phi}{\partial x}\tag{5}$$

$$\frac{\partial T}{\partial y}=\frac{\partial T}{\partial r} \frac{\partial r}{\partial y}+\frac{\partial T}{\partial \theta} \frac{\partial \theta}{\partial y}+\frac{\partial T}{\partial \phi} \frac{\partial \phi}{\partial y}\tag{6}$$

$$\frac{\partial T}{\partial z}=\frac{\partial T}{\partial r} \frac{\partial r}{\partial z}+\frac{\partial T}{\partial \theta} \frac{\partial \theta}{\partial z}+\frac{\partial T}{\partial \phi} \frac{\partial \phi}{\partial z}\tag{7}$$

The partials of $r$, $\theta$, and $\phi$ with respect to $x$, $y$, and $z$ are obtained from:

$$r(x,y,z)=\sqrt{x^2+y^2+z^2}\tag{8}$$ $$\theta(x,y,z)=cos^{-1} \left ( \frac{z}{\sqrt{x^2+y^2+z^2}} \right )\tag{9}$$ $$\phi = tan^{-1} \frac{y}{x}\tag{10}$$

We can now sub in $(2)$, $(3)$, and $(4)$ in $(1)$, and then $(5)$, $(6)$, and $(7)$ in $(1)$, once we have calculated the partials in $(8)$, $(9)$, and $(10)$ and subbed them into $(5)$, $(6)$, and $(7)$. The end result is an expression for $\nabla T$ that is a function of $r$, $\theta$, and $\phi$, and $\hat{r}$, $\hat{\theta}$, and $\hat{\phi}$.

I am not sure what the result is. Though I believe it should be

$$\nabla T = \frac{\partial T}{\partial r}\hat{r}+\frac{1}{r}\frac{\partial T}{\partial \theta}\hat{\theta}+\frac{1}{rsin(\theta)}\frac{\partial T}{\partial \phi}\hat{\phi}$$

My question is, in effect, how do I perform the calculation in Maple. Secondarily, what is a good way to learn how to do this type of calculation in Maple routinely? It seems that I could look up each of the mathematical operations and call them in Maple (which I did), but they all seem to have many options which clean up the results. I am not exactly a beginner, but clearly not an expert. What are the best tools to learn how to routinely do such big calculations in Maple?

1

There are 1 best solutions below

2
On BEST ANSWER

A brief preamble:

restart;
with(VectorCalculus):
SetCoordinates( 'spherical'[r,theta,phi] ):

And now,

Gradient(T(r,theta,phi));

                               d                   d               
                              --- T(r, t, p)      --- T(r, t, p)   
        / d            \ _     dt            _     dp            _ 
        |--- T(r, t, p)| e  + -------------- e  + -------------- e 
        \ dr           /  r         r         t      r sin(t)     p

[edit, answers to followup general queries] A good modern book on Maple is, "Understanding Maple" by Ian Thompson. It is generally well-written. The author focuses on a programmatic approach, and perfers 1-D plaintext input (ie. the Maple language). He covers a lot of ground in a common-sense way. One of my few reservations is that he only uses ~ syntax for elementwise operations, and so misses that map and zip are great items for the kitbag of tools for manipulating scalar expressions (and not just acting across containers).

It's not clear which particular areas of Maple are of most use for you. You could browse the Help pages and look at overviews of the VectorCalculus and MultivariateCalculus packages. I don't know whether the Physics package is too theoretical for your goals.

I should mention that this forum is not the right place to ask Maple programming questions. If it's not primarily about mathematics then such questions are off-topic here. A great alternative is the user-forum Mapleprimes, where a significant number of Maple experts respond quickly.