<<VectorAnalysis`

<<Miscellaneous`RealOnly`

Calculus IV
Lab 2b

Non-Cartesian coordinate systems

Computations

While alternate coordinate systems can be really useful at times (especially in integration), you do have to be careful when working with them.  Standard vector operations work differently in non-Cartesian coordinate systems.  However, you can always transform everything into Cartesian coordinates and do the work there if necessary. Fortunately, Mathematica automagically does most of the grunt work for you on this.  Mathematica also has special versions of these operations that work in these different coordinate systems.

Vector operations

So, for example, to take the dot product of two vectors in spherical coordinates, we would do the following (warning: remember that these are in {ρ,ϕ,θ} form):

DotProduct[{1,(π/2),(π/6)},{2,(π/2),((2π)/3)},Spherical]

If we use Cartesian coordinates, we get:

DotProduct[{1,(π/2),(π/6)},{2,(π/2),((2π)/3)},Cartesian]

CrossProduct[{1,(π/2),(π/6)},{2,(π/2),((2π)/3)},Spherical]

CrossProduct[{1,(π/2),(π/6)},{2,0,((2π)/3)},Spherical]

Problem

Explain why the dot product in spherical coordinates is 0 above.  Why is the second dot product (in Cartesian coordinates, by default) not 0?  

What coordinate system is the answer to the cross product given in?  (This is important.  Don't continue until you have figured this out.)  How do you know?

Differentiation operators

There are also built-in functions to find the gradient, divergence, and curl (among other things):

Grad[(x^2)+y Cos[z]]

Hmmm.  Notice, we have a problem here.  The gradient of the given functions is certainly not the 0 vector.  So, what is going on?  This goes back to the issue I mentioned in the introduction.  This gradient was taken in the default coordinate system (Cartesian), but it was taken with the Mathematica default variables for that coordinate system.  Let's find out what those are:

CoordinateSystem

Coordinates[]

So, as far as Mathematica is concerned, the variables in this coordinate system are Xx, Yy, and Zz (strange but true).  That means that when we took the gradient above, it treated x, y, and z as constants.  There are two ways to fix this:

We could conform:

Grad[(Xx^2)+Yy Cos[Zz]]

Personally, I find this a bit bizarre to try to read.  The other way is to tell Mathematica to use our preferred variables:

Grad[(x^2)+y Cos[z], Cartesian[x,y,z]]

Or, if you need to do a lot of work in Cartesian coordinates with your preferred variables, you could set the default coordinate system this way:

SetCoordinates[Cartesian[x,y,z]]

Grad[(x^2)+y Cos[z]]

Grad[(x^2)+y Cos[z], Cartesian[x,y,z]]

Thus, it is extremely important that, before you start doing computations in any coordinate system using Mathematica's built-in functions, you are aware of what variables Mathematica is expecting (or you set them like you want them).

Of course, a more interesting question is, how do these things work in other coordinate systems?  Let's look at the gradient in spherical coordinates:

Coordinates[Spherical]

SetCoordinates[Spherical[ρ,ϕ,θ]]

Warning:  The default coordinate system is now set to spherical until you change it again.  The safe thing to do is to always specify the coordinate system when you perform a computation.  Also, notice that I am taking this opportunity to rename the variables so they fit the ones we are used to (though they still need to be entered in {ρ,ϕ,θ} order).

Grad[(ρ^2)Sin[ϕ]Cos[θ]]

Or, we can get a general formula for the gradient of a function f[ρ,ϕ,θ] whose coordinates are in spherical coordinates:

Grad[f[ρ,ϕ,θ]]

In this expression, Derivative[1,0,0][f][ρ,ϕ,θ] stands for the partial derivative of f with respect to the first coordinate (ρ), etc.  Notice that, in addition to the expected partial derivatives, you get some extra coefficients, in this case (1/ρ) and ((Csc[ϕ])/ρ) (usually written as (1/(ρ Sin[ϕ]))).  A complete treatment of where these factors come from is beyond the scope of this lab, but basically they are the reciprocals of the coefficients needed to convert a change in that variable into an actual change in arc-length (called the "Scale Factors").  So, in other words, if you increase ρ by dρ, then it just gets longer by dρ, so the scale factor is 1.  However, if you increase ϕ by dϕ, the actual change in distance (i.e., arc-length) covered is ρ dϕ, so the scale factor is ρ.  (This is easier to see in polar coordinates.  If you increase θ by dθ, the actual change in arc-length is r dθ, so the scale factor would be r.)  To see the scale factors for a particular coordinate system, you can use:

ScaleFactors[Spherical[ρ,ϕ,θ]]

ScaleFactors[Cylindrical[r,θ,z]]

Now, you only have to deal with this when you need your output vectors given in your non-Cartesian coordinate system.  In the cases we looked at above, the gradients are given as vectors in spherical coordinates (i.e., these are the components of unit vectors in the ρ, ϕ, and θ directions, respecitvely).  This is mainly useful if you are doing all your work in that coordinate system.  (The good news is that all the built-in differential operators, like grad, div, and curl, automatically take care of this for you, if you specify your coordinate system.)

On the other hand, if you really needed to work with a function from an alternate coordinate system in Cartesian coordinates (for example if you wanted to actually graph the function or its gradient vector field or tangent plane in Mathematica), one way to handle this is to convert the function to Cartesian coordintes to begin with.

If you had the function (in spherical coordinates):

f[{ρ_,ϕ_,θ_}]:=(ρ^2)Sin[ϕ]Cos[θ]

You could first transform it into a function of {x,y,z}:

fCart[{x_,y_,z_}]=f[CoordinatesFromCartesian[{x,y,z},Spherical]]//FullSimplify

From then on, you would treat this as a standard Cartesian function (admittedly ugly).  Notice the liberal use of FullSimplify in this work; it is used to automatically apply things like trig identities, etc.

Grad[fCart[{x,y,z}],Cartesian[x,y,z]]//FullSimplify

This gives you the gradient in terms of your standard i, j, and k unit vectors.  You can get a much nicer looking gradient by taking it directly in spherical:

sphGrad=Grad[f[{ρ,ϕ,θ}],Spherical[ρ,ϕ,θ]]//FullSimplify

But this gives you the gradient vector in terms of the unit vectors in the ρ, ϕ, and θ directions (and remember that the unit vectors in the ϕ and θ directions rotate, depending on what angle they are at, so they are not all parallel to each other).  Which method you use depends on what you are trying to do.  (Of course, with spherical and cylindrical coordinates, Mathematica is perfectly capable of graphing them "as-is", but that isn't true about other more esoteric coordinate systems.  Also, if you were working with different functions in different coordinate systems, converting everything to Cartesian makes it possible to work with them all together.)

SetCoordinates[Cartesian[x,y,z]]

Integration operations

If you are computing a change of variables for a new coordinate system (i.e., in a triple integral), Mathematica has some built in functions that are useful for that as well:

JacobianDeterminant[Spherical[ρ,ϕ,θ]]

JacobianDeterminant[Cylindrical]

As usual, be sure you know what the default variables of your coordinate system are before using this:

JacobianDeterminant[Cylindrical[r,θ,z]]

SetCoordinates[Cartesian[x,y,z]]

Also, if you are doing a path integral, you will need to be able to find the "arc length factor", which is the factor you have to introduce to convert an integral ds into an integral dt (or whatever your independent variable is).  Of course, since we know that ds=|(Overscript[c, ->])'(t)|dt, this "arc length factor" is just |(Overscript[c, ->])'(t)|.  Now, you could certainly compute that yourself, but Mathematica has a built-in function for this:

ArcLengthFactor[{2Sin[t],2Cos[t],t},t]//FullSimplify

Now, even though we haven't really discussed this possibility in class, there isn't any reason you can't have curves defined in other coordinate systems.  So, for example, you could define a parametric curve in cylindrical coordinates as:  r=1, θ=t, z=t or, in vector form:

curveCylindrical={2,t,t}

Now, if you just apply the ArcLengthFactor directly to this curve, you get:

ArcLengthFactor[{2,t,t},t]

Notice, that this is actually the same curve I defined above in Cartesian coordinates, a helix with a radius of 2 about the z axis (moving at the same "speed").  Therefore, they ought to have the same factors.  The way to fix this, of course, is to tell Mathematica that your curve is actually specified in cylindrical coordinates (the above command assumed Cartesian):

ArcLengthFactor[{2,t,t},t,Cylindrical]

If you are curious about the actual formula:

ArcLengthFactor[{x[t],y[t],z[t]},t,Cartesian]

ArcLengthFactor[{r[t],θ[t],z[t]},t,Cylindrical]

Graphing

You can also graph functions and parametric equations in these coordinate systems.  In Lab 1, you wrote your own translation functions to do this for spherical and cylindrical coordinates.  Let's look at another way this could be done, using the built-in Mathematica coordinate systems.

Let's graph ρ=Sin[θ]Cos[ϕ] (in spherical coordinates):

ρ=Sin[θ]Cos[ϕ]

plotSurface=ParametricPlot3D[Evaluate[CoordinatesToCartesian[{ρ,ϕ,θ},Spherical]],{ϕ,0,π},{θ,0,2π},PlotPoints->40]

To find the equation of a tangent plane to a surface at a point, remember that if you can express the equation as f[x,y,z]=0, you can find the equation of the tangent plane by setting ∇f[(Subscript[x, 0]),(Subscript[y, 0]),(Subscript[z, 0])].{x-(Subscript[x, 0]),y-(Subscript[y, 0]),z-(Subscript[z, 0])}=0. (The . stands for the dot product in Mathematica.)

So, for example, the above spherical equation could be written as:

fSpherical[{ρ_,ϕ_,θ_}]:=ρ-Sin[θ]Cos[ϕ]

Converting this in Cartesian coordinates:

fCartesian[{x_,y_,z_}]=fSpherical[CoordinatesFromCartesian[{x,y,z},Spherical]]

So, to find the tangent plane at a point {((Sqrt[3])/2),(π/6),(π/2)} (in spherical coordinates), you first have to translate the point to Cartesian:

ptCartesian=CoordinatesToCartesian[{((Sqrt[3])/2),(π/6),(π/2)},Spherical]

Find the gradient (again, in Cartesian):

fCartesian[{x,y,z}]

Grad[fCartesian[{x,y,z}],Cartesian[x,y,z]]

gradfCartesian[{x_,y_,z_}]=Grad[fCartesian[{x,y,z}],Cartesian[x,y,z]]

It is very important that you use = above and not := or gradCartesian won't work correctly.  This is a suble difference between = and :=

= evaluates the right hand side immediately, so it goes ahead and takes the gradient right away (before you plug in any values for x, y, and z.

:= doesn't evaluate the right hand side until later, so the gradient doesn't get computed until after you plug in for x, y, and z, which is a problem since we want to plug in numbers (to evaluate it at a point).

gradfCartesian[ptCartesian]

Now find the tangent plane:

tangentPlane=gradfCartesian[ptCartesian].({x,y,z}-ptCartesian)//N//FullSimplify

Let's graph this.  There are a number of possibilities here.  The easiest way is to use ContourPlot3D:

plotPlane=ContourPlot3D[tangentPlane==0,{x,-1,1},{y,-1,1},{z,-1,1}]

So, if this worked, we should be able to display them together:

Show[plotSurface,plotPlane]

Problems

Find equations in Cartesian coordinates for planes through the following set of points (in the given coordinate system):  {1,2,2}, {2,3,5}, {3,6,3} (ParabolicCylindrical)

Graph the following surface:   u=v Cos[ϕ+v] in Paraboloidal coordinates

Find the equation for the tangent plane to the above surface at the point {((-7π)/12),((7π)/6),(π/6)} in {u,v,ϕ}.  Graph that plane and the surface on the same coordinate axes (as I did in the example), to make sure you aren't hallucinating.

Graph the following curve:

{t Sin[t],t Cos[t],t}in Paraboloidal and Toroidal coordinates for 0.5≤t≤π.   (Assume the parameter a=1 in the definition.)  

Find the arc-length of this curve over this interval in each coordinate system.  
Should the two arc-lengths be the same?  Why or why not?  (Hint: use NIntegrate to work the integrals.  Trying to work them exactly is a really bad idea...)

Integration

Double and Triple integrals

When working a triple integral, you sometimes have to work in alternate coordinate systems. You can use some of the techniques from above to make the computations easier.

For example, if you had to do the following integral:

(Underscript[∫∫∫, R])(x^3)(Sqrt[(x^2)+(y^2)])dV, where R is the region defined by R={(u,v,ϕ}|1≤u≤(v^2),2≤v≤3, 0≤ϕ≤(π/6)} in Paraboloidal coordinates.

First, let's examine the region by graphing it:

Coordinates[Paraboloidal]

CoordinatesToCartesian[{u,v,ϕ},Paraboloidal]

Okay, in order to match the inequalities given for the region R, we need a formula for u, v, and ϕ in terms of x, y, z so we can graph it.  An easy trick to get this would be:

{uCoord,vCoord,ϕCoord}=CoordinatesFromCartesian[{x,y,z},Paraboloidal]

Notice that I did NOT call these just u, v, ϕ; that's because I want to use those as variables later, so I don't want to redefine them now.  So, for example, this tells me that u is:

uCoord

The first inequality would look like:

1≤uCoord≤(vCoord^2)

Now I just translate the inequalities into Cartesian coordinates:

RegionPlot3D[1≤uCoord≤(vCoord^2)&&2≤vCoord≤3&& 0≤ϕCoord≤(π/6),{x,-1,40},{y,-10,30},{z,-10,40},AxesLabel->Automatic,PlotPoints->100]

So, not a great candidate for integration in Cartesian coordinates. (You can see the weakness of RegionPlot3D here; it depends on sampling points within the box to determine what satisfies the inequality; if we needed a really accurate picture, we would have to graph the "sides" of the region parametrically.)  

Let's convert everything into Paraboloidal:

fCartesian[{x_,y_,z_}]:=(x^3)(Sqrt[(x^2)+(y^2)])

fParaboloidal[{u_,v_,ϕ_}]=fCartesian[CoordinatesToCartesian[{u,v,ϕ},Paraboloidal[u,v,ϕ]]]//FullSimplify

jDet=JacobianDeterminant[Paraboloidal[u,v,ϕ]]

(∫_0^(π/6))(∫_2^3)(∫_1^(v^2))fParaboloidal[{u,v,ϕ}]jDet\[DifferentialD]u\[DifferentialD]v\[DifferentialD]ϕ

Find (Underscript[∫∫∫, R])(x^3)(Sqrt[(x^2)+(y^2)])dV, where R is the region defined by R={(u,v,z}|0≤u≤1,2≤v≤(u^2)+3, 0≤z≤u v} in ParabolicCylindrical coordinates.  Graph the region of integration as well.

Path integrals

If you need to integrate a scalar-valued function over a curve, it is pretty straight-forward.  For example, to integrate f(x,y,z)=(x^2)(y^3)(e^z) over the curve (Overscript[c, ->])(t)={t,Sin[t],Tan[t]}, 0≤t≤ (π/4), you need to simply use ArcLengthFactor to convet ds to dt and compose f  and c:

f[{x_,y_,z_}]:=(x^2)(y^3)(E^z)

c[t_]:={t,Sin[t],Tan[t]}

f[c[t]]

ArcLengthFactor[c[t],t,Cartesian]

NIntegrate[f[c[t]]ArcLengthFactor[c[t],t,Cartesian],{t,0,(π/4)}]

If your curve (and function) is in some other coordinate system, you simply have to specify that in the ArcLengthFactor term.  (Be careful that you specify your variables in the order Mathematica expects them in for your coordinate system, both in f and in c.)

Find (∫_(Overscript[c, ->]))(u^3)(Sqrt[(v^2)+(z^2)])ds, where (Overscript[c, ->])is the curve {(t^2),Sin[t],Cos[t]}, 0≤t≤π, where both the curve and the function are in ParabolicCylindrical coordinates.  Graph the curve.  Work the problem twice, once in Parabolic Cylindrical coordinates and once by converting everything to Cartesian.  Should the answers be the same?  (Use NIntegrate to evaulate the integral.)