Examples in Physics
Vectors and Analytical Geometry
Vectorial equation of a line
Problem
Derive the vectorial equation of a straight line which passes through two generic points, A and B.
Choose two concrete points A and B, and use that vectorial equation to obtain the parametric equation of the line.
Generate a 3D plot of this line.
Solution
The vectorial equation of a line is the equation which is satisfied by the position vector of any point on this line. We want to express this equation in terms of the position vectors of the points A and B. The parametric equation can then be constructed from the vectorial equation by taking the coefficients of the unit vectors.
restart:withPhysics:withPhysicsVectors:
1. To construct the vectorial equation of the line, let A→ and B→ be vectors pointing to A and B. The vector difference A→ - B→ is parallel to the line we want to represent.
A_ − B_
A→−B→
Now let r→ be the position vector of any point of this line; the vector r→−A→ is also parallel to the line so their cross product is equal to 0 (you can use &x, or the×operator from the palette of Common Symbols)
Eq ≔ r_ − A_× = 0
Eq≔r→−A→×A→−B→=0
This is the vectorial equation of the line which passes through A and B. The position vector r→ of any point belonging to this line satisfies this equation.
2. To construct the parametric representation of this line, turn the generic points A and B into concrete points; that is, give values to the components of A→ and B→. For example:
A_ ≔ 2 _i − 3 _j + 4 _k
A→≔2⁢i∧−3⁢j∧+4⁢k∧
B_ ≔ −4 _i + 2 _j − _k
B→≔−4⁢i∧+2⁢j∧−k∧
Regardless of the values of A→ and B→, the position vector of a point is
r_ ≔ x _i + y _j +z _k
r→≔x⁢i∧+y⁢j∧+z⁢k∧
Thus the vectorial equation for these particular points A and B is
Eq
5⁢y−5+5⁢z⁢i∧+6⁢z−14−5⁢x⁢j∧+−5⁢x−8−6⁢y⁢k∧=0
Since the unit vectors [i∧,j∧,k∧] are independent, their Coefficients in the vectorial equation constitute the parametric equations; you can get those coefficients by taking the scalar product
_i,_j,_k . Eq
5⁢y−5+5⁢z=0,6⁢z−14−5⁢x=0,−5⁢x−8−6⁢y=0
We now have a system of three equations in terms of three unknowns x, y, and z, but it still represents the equation of a line, so two of the variables can be expressed in terms of the third one, which acts as the parameter of the parametric equations. Thus, by solving the system you get the following parametric equations
solve, x, y, z
Warning, solve may be ignoring assumptions on the input variables.
x=−145+6⁢z5,y=1−z,z=z
The interpretation is: given a value for z, the values of x and y are those you see above.
3. To plot this parametric representation (see plots[spacecurve]), first select the curve's parameter:
select⁡evalb,1
z=z
Now construct the appropriate input for the spacecurve command, say for z from -4 to 4
input≔op⁡map⁡rhs,1,lhs⁡1=−4..4
input≔−145+6⁢z5,1−z,z,z=−4..4
Some options for improving the visualization are
opts≔axes=boxed,scaling=constrained,orientation=−130,70,labels=x,y,z
plotsspacecurveinput,opts
Vectorial equation of a plane
Derive the vectorial equation of a plane which passes through three generic points A, B, and C.
Choose three concrete points A, B, and C on this plane and plot it.
The vectorial equation of a plane is the equation which is satisfied by the position vector of any point on the plane.
restart:withPhysicsVectors:
1. To construct this equation, let A→, B→, and C→ be the vectors pointing to A, B, and C, and let r→ be the position vector of any point on this plane. The differences A→−C→ and A→−B→ are vectors parallel to the plane we want to represent, and also the difference between r→ and any of A→,B→, or C→ is a vector parallel to the plane. So the equation of the plane can be obtained by first taking the cross product of any difference involving A→,B→, and C→ to construct a vector perpendicular to the plane (you can use &x, or the×operator from the palette of Common Symbols)
G_ ≔ A_ − B_×A_ − C_
G→≔A→−B→×A→−C→
then taking the scalar product of G→ with any of the differences parallel to the plane involving r→ and equating it to zero. So for instance, one way of writing this vectorial equation of the plane is
Eq ≔ r_ − A_ . G_ = 0
Eq≔r→−A→·A→−B→×A→−C→=0
2. To plot this plane, turn the generic points A, B, and C into concrete points; that is, give values to the components of A→, B→, and C→. For example:
B_ ≔ 5 _i + 4 _j − 7 _k
B→≔5⁢i∧+4⁢j∧−7⁢k∧
C_ ≔ 304 A_ + 907 B_
C→≔555⁢i∧7+405⁢j∧14−60⁢k∧
For r→ we always have
The vectorial equation for these particular points A, B, and C is thus:
−1355⁢x14−4607⁢y7−6233⁢z14=0
To verify that the surface represented by this equation contains the points A, B, and C, you can substitute the values of the coordinates of these points and check if the equation is satisfied. For example, these are the coordinates of the first point:
i∧,j∧,k∧·A→
2,−3,4
The following shows that, for these points A→,B→,C→, the equation is satisfied:
forPinA→,B→,C→doeval⁡Eq,x=i∧·P,y=j∧·P,z=k∧·Penddo
0=0
That this surface is a plane is clear from the fact that Eq is linear in all of x, y, and z. One way of plotting this plane is with the command implicitplot3d.
opts≔axes=boxed,scaling=constrained,orientation=125,65,style=surface
plotsimplicitplot3dEq, x=−2..2, y=−2..2, z=−2..2, opts
Vectorial equation of a plane tangent to a sphere of radius a
Derive the vectorial equation of a plane tangent to a sphere of radius a.
The vectorial equation of this plane is the equation satisfied by the position vector of any point on it.
Let r→ represent the position vector of any point on the plane, A→ be a vector pointing to the center of the sphere, and B→ be a vector pointing to the point B where the plane is tangent to the sphere. So the difference r→−B→ is a vector on the plane, and the difference B→−A→ is a vector from the center of the sphere to the point of contact between the sphere and the tangent plane (that is, a vector perpendicular to the plane). Hence, these two vectors are perpendicular, and so their scalar product is equal to zero.
Eq ≔ r_ − B_ . B_ − A_ = 0
Eq≔r→−B→·B→−A→=0
This is already the vectorial equation of the tangent plane, only it is not yet expressed in terms of the radius of the sphere. Now since B→−A→ is a vector from the center of the sphere to the point of contact with the plane, the norm of this vector is the radius a of the sphere.
key ≔ NormB_ − A_ = a
Norm⁡B_−A_=a
Expand both expressions to use them together.
expandEq
`.`⁡r_,B_−`.`⁡r_,A_−Norm⁡B_2+`.`⁡B_,A_=0
mapu → u^2, key
Norm⁡B_−A_2=a2
expand
Norm⁡B_2−2⁢`.`⁡B_,A_+Norm⁡A_2=a2
So simplify one with respect to the other one, eliminating B→ (see simplify/siderels)
simplify,,NormB_
Norm⁡A_2−a2+`.`⁡r_,B_−`.`⁡r_,A_−`.`⁡B_,A_=0
After collecting terms in the above, the requested vectorial equation can be more compactly rewritten as B→−A→·r→−A→=a2.
rhs=lhsexpandB_ − A_ . r_ − A_ = a^2
a2=`.`⁡r_,B_−`.`⁡B_,A_−`.`⁡r_,A_+Norm⁡A_2
subs,
As an exercise, consider choosing three concrete values for the positions of A, B, and the radius a of the sphere, then insert these values into the derived equation and plot the sphere and tangent plane together (see plots[display] to merge the plots).
Volume element of a sphere
Determine the infinitesimal volume element of a sphere, expressed in spherical coordinates.
Let r→=R→⁡u,v,w be the vectorial equation, parameterized by u, v, and w, of a generic 3-D geometric object; in this case, we are dealing with a sphere of generic radius r. The volume element is derived from the equation as d3⁢r→=∂∂ur→·∂∂vr→×∂∂wr→ du dv dw.
restart:withPhysics:-Vectors:
We want this volume element to be expressed in spherical coordinates (r,φ,θ); we can always choose these coordinates themselves as parameters u, v, w. Therefore, we are interested in the explicit form of (note the use of %diff, the inert form diff, and for the cross product you can use &x, or the × operator from the palette of Common Symbols)
answer ≔ %diffr_,r . %diffr_,theta×%diffr_,phi
`.`⁡%diff⁡r_,r,&x⁡%diff⁡r_,θ,%diff⁡r_,φ
The first step is to write the vectorial equation r→=R→⁡r,φ,θ for a sphere of radius r; that is the equation satisfied by the position vector r→ of any point of the sphere. In spherical coordinates, with the origin of the reference system at the center of the sphere, this vectorial equation has its simplest form R→r,φ,θ=r⁢r∧,where r→ points to any point of the sphere, r is the radial coordinate (constant over the sphere) and ⁢r∧ is the radial unit vector. So
r_ ≔ r _r
r→≔r⁢r∧
From which the value of
answer
`.`⁡%diff⁡r⁢_r,r,&x⁡%diff⁡r⁢_r,θ,%diff⁡r⁢_r,φ
can be computed directly, using the value command
valueanswer
r2⁢sin⁡θ
Alternatively, one could compute this result one step at a time by making it explicit that r∧ depends on ϕ and θ. For this purpose, change the basis in the vectorial equation to the Cartesian basis (i∧,j∧,k∧), where all the unit vectors are constant and so the partial derivatives can be performed directly.
r_ ≔ ChangeBasisr_, 1
r→≔r⁢sin⁡θ⁢cos⁡φ⁢i∧+r⁢sin⁡φ⁢sin⁡θ⁢j∧+r⁢cos⁡θ⁢k∧
So, the answer introduced in (30) becomes:
`.`⁡%diff⁡r⁢sin⁡θ⁢cos⁡φ⁢_i+r⁢sin⁡φ⁢sin⁡θ⁢_j+r⁢cos⁡θ⁢_k,r,&x⁡%diff⁡r⁢sin⁡θ⁢cos⁡φ⁢_i+r⁢sin⁡φ⁢sin⁡θ⁢_j+r⁢cos⁡θ⁢_k,θ,%diff⁡r⁢sin⁡θ⁢cos⁡φ⁢_i+r⁢sin⁡φ⁢sin⁡θ⁢_j+r⁢cos⁡θ⁢_k,φ
Hence the volume element is d3⁢r→=sinθ⁢r2⁢d⁢r⁢d⁢θ⁢d⁢ϕ.
Parametrization of Curves, Surfaces and Volumes
Consider the following C representing a curve in space
restart;withPhysics:-Vectors
&x,`+`,`.`,Assume,ChangeBasis,ChangeCoordinates,CompactDisplay,Component,Curl,DirectionalDiff,Divergence,Gradient,Identify,Laplacian,∇,Norm,ParametrizeCurve,ParametrizeSurface,ParametrizeVolume,Setup,Simplify,`^`,diff,int
C≔y=x2,z=0
The parametric equations for this curve are
ParametrizeCurve⁡C
x⁡t=t,y⁡t=t2,z⁡t=0,t
The right-hand sides of equations above are the components of the position vector r→ in cartesian coordinates, from where a vectorial form of these equations is
ParametrizeCurve⁡C,output=vector
t2⁢j∧+t⁢i∧,t
The curve C can also be passed in vector form
C≔x⁢_i+x2⁢_j
C≔x2⁢j∧+x⁢i∧
The equations of circle of radius a on the (x,y) plane can be written as
C≔z=0,x2+y2=a2
x⁡φ=a⁢cos⁡φ,y⁡φ=a⁢sin⁡φ,z⁡φ=0,φ
In vector notation,
a⁢cos⁡φ⁢i∧+a⁢sin⁡φ⁢j∧,φ
Changing the basis of this vector, for example to cylindrical, we get
ChangeBasis⁡1,cylindrical
a⁢ρ∧
The same result can be obtained by specifying the basis
ParametrizeCurve⁡C,output=vector,basis=cylindrical
a⁢ρ∧,φ
To parametrize surfaces and volumes you can use ParametrizeSurface and ParametrizeVolume, which work in the same way as ParametrizeCurve, only with two and three parameters respectively.
C__2≔x2+y2+z2=a2
ParametrizeSurface⁡C__2
x⁡θ,φ=a⁢sin⁡θ⁢cos⁡φ,y⁡θ,φ=a⁢sin⁡θ⁢sin⁡φ,z⁡θ,φ=a⁢cos⁡θ,θ,φ
C__3≔x2+y2+z2=r2
ParametrizeVolume⁡C__3
x⁡r,θ,φ=r⁢sin⁡θ⁢cos⁡φ,y⁡r,θ,φ=r⁢sin⁡θ⁢sin⁡φ,z⁡r,θ,φ=r⁢cos⁡θ,r,θ,φ
ParametrizeVolume⁡C__3,basis=spherical,output=vector
r⁢r∧,r,θ,φ
ParametrizeVolume⁡C__3,basis=cylindrical,output=vector
k∧⁢z+ρ⁢ρ∧,ρ,φ,z
Integral Vector Calculus
Integral vector calculus is about computing path, surface and volume vector integrals. Those are integrals where the integrand is a scalar or vector function, and the computation is done from any description (algebraic, parametric, vectorial) of the region of integration - a path, surface of volume.
There are three kinds of line or path integrals:
∫A→B→F⁢ⅆr→path=C
∫A→B→F→ ·ⅆr→path=C
∫A→B→F→ ×ⅆr→path=C
where A→ and B→ are points in space, the limits of integration, that belong to the curve C over which the integral is performed. In the first integral, F is a scalar function and the result of the integration is thus a vector. In the second and third integrals the integrand F→ is a vector function, so that the dot product F→·dr→ is a scalar and so is the integral, while in the third one F→×dr→ is a vector and so is its integration over the region C.
Likewise, there are three kinds of surface integrals
∫F⁢ⅆS→surface=C,parameters=u=a..b,v=c..d
∫F→ ·ⅆS→surface=C,parameters=u=a..b,v=c..d
∫F→ ×ⅆS→surface=C,parameters=u=a..b,v=c..d
and two types of volume integrals
∫F⁢ⅆVvolume=C,parameters=u=a..b,v=c..d,w=f..g
∫F→⁢ⅆVvolume=C,parameters=u=a..b,v=c..d,w=f..g
The line element dr→ in path integrals is expressed in terms of a parameter t as
d⁢r→=ⅆⅆtr→⁡t⁢dt
Using indexed notation for derivatives r→u=∂∂ur→⁡u,v, the surface element dS→ in surface integrals is expressed in terms of parameters as
dS→=r→u×r→v⁢du⁢dv
and the volume element dV in volume integrals as
dV=r→u·r→v×r→w⁢du⁢dv⁢dw
The integrals in the three cases are computed by first expressing the integrand and the integration element in terms of the parameters using the parametric equations derived with ParametrizeCurve, ParametrizeSurface and ParametrizeVolume, then performing the vector product operations, then the integration.
Vectorial Path integrals
restart; withPhysics:-Vectors;
Consider the following scalar function F, path C and integration limits A→ and B→
F≔x⁢y
A_≔0,0,0
A→≔0,0,0
B_≔1,1,0
B→≔1,1,0
The line or path integral, shown here in inert form on the left-hand side and active, computed to the end on the right-hand side, is
Int=int⁡F,r_=A_..B_,path=C
Int⁡x⁢y,r_=0,0,0..1,1,0,path=y=x2,z=0=25⁢_j+14⁢_i
The output on the right-hand side is a vector. Within int, to perform this integration the curve C=y=x2,z=0 is first parametrized using ParametrizeCurve
The output above is a sequence, first the parametric equations as an ordered list (order x,y,z) then the parameter, in this case t. For the formulation of the integral to make sense, the limits of integration A→ and B→ must belong to this curve, i.e. satisfy the parametric equations for some value of the parameter, in this case t=0 and t=1
A_=Eval⁡1,t=0
0,0,0=x⁡t=t,y⁡t=t2,z⁡t=0t=0|x⁡t=t,y⁡t=t2,z⁡t=0t=0
B_=Eval⁡1,t=1
1,1,0=x⁡t=t,y⁡t=t2,z⁡t=0t=1|x⁡t=t,y⁡t=t2,z⁡t=0t=1
To see the integral after being parametrized and before performing the integration you can use the option inert
Int=int⁡F,r_=A_..B_,path=C,inert
Int⁡x⁢y,r_=0,0,0..1,1,0,path=y=x2,z=0,inert=Int⁡2⁢_j⁢t4+_i⁢t3,t=0..1
Since there is a relation one-to-one between the integration limits A→ and B→ and the parameter's range, instead of indicating A→ and B→ you can also indicate the range of t itself, getting the same result (7)
Int=int⁡F,r_,path=C,parameter=t=0..1
Int⁡x⁢y,r_,path=y=x2,z=0,parameter=t=0..1=25⁢_j+14⁢_i
When the parameter's range is passed, you can also use a shortcut notation, passing the second argument as an equation r_ = C, making more explicit that r_ is the vector representation of the region of integration C, so the line element dr→ is the differential of the parametric equations of C. In this case indicating path = C is redundant and can be omitted.
Int=int⁡F,r_=C,parameter=t=0..1
Int⁡x⁢y,r_=y=x2,z=0,parameter=t=0..1=25⁢_j+14⁢_i
The integration path and the limits of integration can be expressed in vector notation as well
C_≔x⁢_i+x2⁢_j
C→≔x2⁢j∧+x⁢i∧
A_≔0
A→≔0
B_≔_i+_j
B→≔i∧+j∧
Int=int⁡F,r_=A_..B_,path=C_
Int⁡x⁢y,r_=0.._i+_j,path=_j⁢x2+_i⁢x=25⁢_j+14⁢_i
Vectorial Surface and Volume integrals
The case of surface and volume integrals is analogous to that of line (path) integrals, but for two things: instead of one, there are two or three parameters, and instead of indicating integration limits, it is required that you indicate the parameter's ranges.
The following C represents the surface of a sphere of radius a centered at the origin
with⁡Physics,Assume,CompactDisplay
Assume,CompactDisplay
Assume⁡0<a
a::0,∞
From the definition of the vectorial surface element as
dS→ is a vector perpendicular to the surface of the sphere with magnitude equal to the radius a. Hence, the vectorial surface integral of dS→ over the upper half of the sphere should be a vector perpendicular to the plane x,y in the k∧ direction, with modulus equal to half the surface of a sphere specified by C2. Also, checking the form of the parametrization returned by ParametrizeSurface is useful to understand what the ranges for the parameters θ and φ need to be in order to represent the desired region.
Int=int⁡1,S_,surface=C__2,parameters=θ=0..π2,φ=0..2⁢π
Int⁡1,S_,surface=x2+y2+z2=a2,parameters=θ=0..12⁢π,φ=0..2⁢π=a2⁢_k⁢π
From symmetry considerations, the integral of dS→ over the lower half of the sphere should have the same magnitude but opposite direction (−k∧), from where the integral over the whole sphere, so for θ=0..π, should be equal to 0
Int=int⁡1,S_,surface=C__2,parameters=θ=0..π,φ=0..2⁢π
Int⁡1,S_,surface=x2+y2+z2=a2,parameters=θ=0..π,φ=0..2⁢π=0
From this example we see that to get the area computing the integral of dS→ over the whole surface it is necessary to take as integrand the modulus of dS→, that is its scalar product with a unit vector parallel to it. By definition of surface element (see after ) that unit vector is given by
CompactDisplay⁡r_⁡θ,φ
r→⁡θ,φ⁢will now be displayed as⁢r→
n_≔diff⁡r_⁡θ,φ,θ&xdiff⁡r_⁡θ,φ,φNorm⁡diff⁡r_⁡θ,φ,θ&xdiff⁡r_⁡θ,φ,φ
&x⁡diff⁡r_⁡θ,φ,θ,diff⁡r_⁡θ,φ,φNorm⁡&x⁡diff⁡r_⁡θ,φ,θ,diff⁡r_⁡θ,φ,φ
where r→ is the vectorial form of the parametric equations of the surface. It is easy to see this vector is the radial unit vector r∧. For that purpose you can use the option output = vector of ParametrizeSurface to get the vectorial form of the parametric equations for C2
ParametrizeSurface⁡C__2,output=vector
a⁢sin⁡θ⁢cos⁡φ⁢i∧+a⁢sin⁡θ⁢sin⁡φ⁢j∧+a⁢cos⁡θ⁢k∧,θ,φ
Introduce this value of r→ into the expression for n→ and change basis to spherical
n_≔eval⁡n_,r_⁡θ,φ=1
n→≔a2⁢sin⁡θ2⁢cos⁡φ⁢i∧+a2⁢sin⁡θ2⁢sin⁡φ⁢j∧+k∧⁢a2⁢cos⁡θ⁢sin⁡θa4⁢sin⁡θ4⁢cos⁡φ2+a4⁢sin⁡θ4⁢sin⁡φ2+a4⁢cos⁡θ2⁢sin⁡θ2
n_≔ChangeBasis⁡n_,spherical
n→≔r∧
Putting all together, the area of a sphere of radius a is given by this closed surface integral
Int=int⁡n_,S_,surface=C__2,parameters=θ=0..π,φ=0..2⁢π
Int⁡_r,S_,surface=x2+y2+z2=a2,parameters=θ=0..π,φ=0..2⁢π=4⁢a2⁢π
In the case of the volume of a sphere, an algebraic representation of the region is
from where the volume of a sphere of radius a is equal to the integral of the corresponding dV=r→u·r→v×r→w⁢du⁢dv⁢dw with parameters r=0..a, θ=0..π and φ=0..2⁢π
Int=int⁡1,V,volume=C__3,parameters=r=0..a,θ=0..π,φ=0..2⁢π
Int⁡1,V,volume=x2+y2+z2=r2,parameters=r=0..a,θ=0..π,φ=0..2⁢π=43⁢a3⁢π
Using ParametrizeVolume one can also see that the vectorial representation of this region is just the position vector r→ written in spherical coordinates and basis
Vectors in Spherical Coordinates using Tensor Notation (advanced)
The following is a topic that appears frequently in formulations: given a 3D vector in spherical (or any curvilinear) coordinates, how do you represent and relate, in simple terms, the vector and the corresponding vectorial operations Gradient, Divergence, Curl and Laplacian using tensor notation?
I. The line element in spherical coordinates and the scale-factors
Start by setting the spacetime to be 3-dimensional, Euclidean, and use Cartesian coordinates
Setupdimension=3,coordinates=cartesian,metric= Euclidean,spacetimeindices=lowercaselatin:
The dimension and signature of the tensor space are set to 3,⁢⁡+ + +
⁢Systems of spacetime coordinates are:⁢X=x,y,z
⁢_______________________________________________________
⁢The Euclidean metric in coordinates ⁢x,y,z
g_μ,ν=100010001
_______________________________________________________
In vector calculus,the line element dr→ is at the root of everything, and in Cartesian coordinates it has the simple form
dr_ = dx _i + dy _j + dz _k
dr→=dx⁢i∧+dy⁢j∧+dz⁢k∧
To compute the line element dr→ in spherical coordinates, the starting point is the transformation
tr ≔ X =~ ChangeCoordinatesX,spherical
tr≔x=r⁢sin⁡θ⁢cos⁡φ,y=r⁢sin⁡θ⁢sin⁡φ,z=r⁢cos⁡θ
CoordinatesS=r,θ,φ:
⁢Systems of spacetime coordinates are:⁢S=r,θ,φ,X=x,y,z
Since in dx, dy, dz are just symbols with no relationship to x,y,z, start transforming these differentials using the chain rule, computing the Jacobian of the transformation (87). In this Jacobian J, the first line is ∂x∂r⁢dr,∂x∂⁢θ⁢d⁢θ,∂x∂⁢φ⁢d⁢φ
J ≔ VectorCalculus:-Jacobianmaprhs, ,S:
So in matrix notation,
Vectordx, dy,dz = J . Vectordr, dtheta, dphi
dxdydz=sin⁡θ⁢cos⁡φ⁢dr+r⁢cos⁡θ⁢cos⁡φ⁢dtheta−r⁢sin⁡θ⁢sin⁡φ⁢dphisin⁡θ⁢sin⁡φ⁢dr+r⁢cos⁡θ⁢sin⁡φ⁢dtheta+r⁢sin⁡θ⁢cos⁡φ⁢dphicos⁡θ⁢dr−r⁢sin⁡θ⁢dtheta
To complete the computation of dr→ in spherical coordinates we can now use ChangeBasis, provided that we next substitute (89) in the result, expressing the abstract objects dx, dy, dz in terms of dr,dθ,dφ.
In two steps:
lhs = ChangeBasisrhs,spherical
dr→=dx⁢sin⁡θ⁢cos⁡φ+dy⁢sin⁡θ⁢sin⁡φ+dz⁢cos⁡θ⁢r∧+dx⁢cos⁡φ⁢cos⁡θ+dy⁢sin⁡φ⁢cos⁡θ−dz⁢sin⁡θ⁢θ∧+cos⁡φ⁢dy−sin⁡φ⁢dx⁢φ∧
The line element
simplifysubsconvertlhs =~ rhs,set,
dr→=φ∧⁢dφ⁢r⁢sin⁡θ+θ∧⁢dθ⁢r+r∧⁢dr
This result is important: it gives us the so-called scale factors, the key that connects 3D vectors with the related covariant and contravariant tensors in curvilinear coordinates. The scale factors are computed from (91) by taking the scalar product with each of the unit vectors r∧,θ∧,φ∧, then taking the coefficients of the differentials dr,dθ,dφ (just substitute them by the number 1)
h≔subs⁡dr,dθ,dφ =~1,seq⁡rhs·q,q=r∧,θ∧,φ∧
h≔1,r,r⁢sin⁡θ
The scale factors are relevant because the components of the 3D vector and the corresponding tensor are not the same in curvilinear coordinates. For instance, representing the differential of the coordinates as the tensor dS j=dr,dθ,dφ, we see that the corresponding vector, the line element in spherical coordinates dS→, is not constructed by directly equating its components to the components of dSj=dr,dθ,dφ, so
dS→ ≠ dr r∧+dθ ⁢θ∧+dφ ⁢φ∧
The vector dS→ is constructed multiplying these contravariant components dr,dθ,dφ by the scaling factors
dS→=h__r dr r∧+h__θ dθ ⁢θ∧+h__φ dφ ⁢φ∧
This rule applies in general. The vectorial components of a 3D vector in an orthogonal system (curvilinear or not) are always expressed in terms of the contravariant components Aj the same way we did in the line above with the line element, using the scale-factors h__j, so that
A→=∑j=13hj⁢ Aje__jˆ
where on the right-hand side we see the contravariant components Aj and the scale-factors hj. Because the system is orthogonal, each vector component A__(j) satisfies
A__(j)=hj⁢A⁢j⁢j
The scale-factors hj do not constitute a tensor, so on the right-hand side we do not sum over j. Also, from
A→=Aj⁢A⁢j⁢j
it follows that,
A__(j)=A__jh__j
where on the right-hand side we now have the covariant tensor components A__j.
This relationship between the components of a 3D vector and the contravariant and covariant components of a tensor representing the vector is key for translating vector-component to corresponding tensor-component formulas.
II. Transformation of contravariant and covariant tensors (can skip)
Define two representations for the same tensor: A__c will represent A in Cartesian coordinates, while A__s will represent A in spherical coordinates.
DefineA__cj,A__sj, quiet
A__cj,A__sj,γa,σa,∂a,ga,b,εa,b,c,Sa,Xa
Transformation rule for a contravariant tensor
We know, by definition, that the transformation rule for the components of a contravariant tensor is Aμ⁡y=∂yμ∂xν⁢⁢Aνx, the same as the rule for the differential of the coordinates. Thus, the transformation rule from A__c⁢j⁢j to A__s⁢j⁢j, computed using TransformCoordinates, should return the same relation as (89). However, the application of the command requires one to pay attention because, just like in (89), we want to isolate the Cartesian (not the spherical) components. This is like performing a reversed transformation. So we will use
TensorArray⁡A__c⁢j⁢j=TransformCoordinates⁡tr,A__s⁢j⁢j,X,S
where on the left-hand side we isolate the three components of A in Cartesian coordinates, and on the right-hand side we transform the spherical components A__s⁢j⁢j from spherical S=r,θ,φ (4th argument) to Cartesian X=x,y,z (3rd argument), which according to the 5th bullet of TransformCoordinates will result in a transformation expressed in terms of the old coordinates (here the spherical S). Expand things to compare with (89)
VectorcolumnTensorArrayA__c~j = TransformCoordinatestr, A__s~j,X,S,simplifier=expand
A__c~1A__c~2A__c~3=sin⁡θ⁢cos⁡φ⁢A__s~1+r⁢cos⁡θ⁢cos⁡φ⁢A__s~2−r⁢sin⁡θ⁢sin⁡φ⁢A__s~3sin⁡θ⁢sin⁡φ⁢A__s~1+r⁢cos⁡θ⁢sin⁡φ⁢A__s~2+r⁢sin⁡θ⁢cos⁡φ⁢A__s~3cos⁡θ⁢A__s~1−r⁢sin⁡θ⁢A__s~2
We see that the transformation rule for a contravariant vector A__c⁢j⁢j is, indeed, like the transformation (89) for the differential of the coordinates.
Transformation rule for a covariant tensor
For the transformation rule for the components of a covariant tensor A__cj, we know by definition that it is Aμ⁡y=∂xν∂yμ⁢⁢Aνx, and so the same transformation rule for the gradient ∂x,∂y,∂z, where ∂x=u →diffu,x and so on. We can directly experiment with this by changing variables in the differential operators ∂x,∂y,∂z
d_x = PDEtools:-dchangetr, u → diffu,x,simplify
∂x=u↦1r⁢sin⁡θ⁢cos⁡φ⁢ⅆuⅆr⁢r+cos⁡φ⁢cos⁡θ⁢ⅆuⅆθ−ⅆuⅆφ⁢sin⁡φ⁢csc⁡θ
This result, and the equivalent ones replacing x by y or z in the input above, can be computed in one go, in matrix and simplified form, using the Jacobian of the transformation computed after (88). Now we need to take the transpose of the inverse of J (because we are now transforming the components of the gradient ∂x,∂y,∂z)
H ≔ simplifyJ−1+:
Vectord_x, d_y,d_z = H . Vectord_r, d_θ,d_φ
d_xd_yd_z=sin⁡θ⁢cos⁡φ⁢d_r+cos⁡φ⁢cos⁡θ⁢d_θr−sin⁡φ⁢csc⁡θ⁢d_φrsin⁡θ⁢sin⁡φ⁢d_r+sin⁡φ⁢cos⁡θ⁢d_θr+cos⁡φ⁢csc⁡θ⁢d_φrcos⁡θ⁢d_r−sin⁡θ⁢d_θr
The corresponding transformation equations relating the tensors A__c and A__s in Cartesian and spherical coordinates is computed with TransformCoordinates as in (94), just lower the indices on the left and right hand sides, i.e., remove the tilde ~
VectorcolumnTensorArrayA__cj = TransformCoordinatestr, A__sj,X,S,simplifier=expand
A__c1A__c2A__c3=sin⁡θ⁢cos⁡φ⁢A__s1+cos⁡θ⁢cos⁡φ⁢A__s2r−sin⁡φ⁢csc⁡θ⁢A__s3rsin⁡θ⁢sin⁡φ⁢A__s1+cos⁡θ⁢sin⁡φ⁢A__s2r+cos⁡φ⁢csc⁡θ⁢A__s3rcos⁡θ⁢A__s1−sin⁡θ⁢A__s2r
We see that the transformation rule for a covariant vector A__cj is, indeed, just like the transformation rule (96) for the gradient.
Side Note: once the computation of these transformation rules is understood, we can also perform the inverse of (97) as follows
VectorcolumnTensorArrayA__sj = TransformCoordinatestr, A__cj,S,X,simplifier=expand
A__s1A__s2A__s3=sin⁡θ⁢cos⁡φ⁢A__c1+sin⁡θ⁢sin⁡φ⁢A__c2+cos⁡θ⁢A__c3r⁢cos⁡θ⁢cos⁡φ⁢A__c1+r⁢cos⁡θ⁢sin⁡φ⁢A__c2−r⁢sin⁡θ⁢A__c3−r⁢sin⁡θ⁢sin⁡φ⁢A__c1+r⁢sin⁡θ⁢cos⁡φ⁢A__c2
III. Deriving the transformation rule for the Gradient using TransformCoordinates (can skip)
Turn the CompactDisplay notation for derivatives ON, so that the differentiation variable is displayed as an index:
ON
The gradient of a function f, in Cartesian and spherical coordinates respectively, is given by
%Nabla = NablafX
%Nabla⁡f⁡X=diff⁡f⁡X,x⁢_i+diff⁡f⁡X,y⁢_j+diff⁡f⁡X,z⁢_k
%Nabla = NablafS
%Nabla⁡f⁡S=diff⁡f⁡S,r⁢_r+diff⁡f⁡S,θ⁢_θr+diff⁡f⁡S,φ⁢_φr⁢sin⁡θ
What we want now is to depart from (99) in Cartesian coordinates and obtain (100) in spherical coordinates using the transformation rule for a covariant tensor we previously computed with TransformCoordinates in (97). (An equivalent derivation which is simpler and has less steps is done in Sec. IV.)
Start by changing the vector basis in the gradient (99)
%Nabla⁡f⁡X=diff⁡f⁡X,x⁢sin⁡θ⁢cos⁡φ+diff⁡f⁡X,y⁢sin⁡θ⁢sin⁡φ+diff⁡f⁡X,z⁢cos⁡θ⁢_r+diff⁡f⁡X,x⁢cos⁡φ⁢cos⁡θ+diff⁡f⁡X,y⁢sin⁡φ⁢cos⁡θ−diff⁡f⁡X,z⁢sin⁡θ⁢_θ+−diff⁡f⁡X,x⁢sin⁡φ+cos⁡φ⁢diff⁡f⁡X,y⁢_φ
We can see that in this result the coefficients of r∧,θ∧,φ∧ are the three lines in the right-hand side of (98) after replacing the covariant components A__j by the derivatives of f with respect to the jth coordinate, shown here using indexed notation due to CompactDisplay being ON
A__s1,A__s2,A__s3 =~ diff⁡fS,r,diff⁡fS,θ,diff⁡fS,φ
A__s1=diff⁡f⁡S,r,A__s2=diff⁡f⁡S,θ,A__s3=diff⁡f⁡S,φ
A__c1,A__c2,A__c3 =~ diff⁡f⁡X,x,diff⁡f⁡X,y,diff⁡f⁡X,z
A__c1=diff⁡f⁡X,x,A__c2=diff⁡f⁡X,y,A__c3=diff⁡f⁡X,z
So since (97) is the inverse of (98), replace A by ∂f in (97) (the formula computed using TransformCoordinates), then insert the result in (101) to relate the gradient in Cartesian and spherical coordinates. We expect to arrive at the formula for the gradient in spherical coordinates (100) .
subs,,
∂∂x⁢f⁡x,y,z∂∂y⁢f⁡x,y,z∂∂z⁢f⁡x,y,z=sin⁡θ⁢cos⁡φ⁢∂∂r⁢f⁡r,θ,φ+cos⁡θ⁢cos⁡φ⁢∂∂θ⁢f⁡r,θ,φr−sin⁡φ⁢csc⁡θ⁢∂∂φ⁢f⁡r,θ,φrsin⁡θ⁢sin⁡φ⁢∂∂r⁢f⁡r,θ,φ+cos⁡θ⁢sin⁡φ⁢∂∂θ⁢f⁡r,θ,φr+cos⁡φ⁢csc⁡θ⁢∂∂φ⁢f⁡r,θ,φrcos⁡θ⁢∂∂r⁢f⁡r,θ,φ−sin⁡θ⁢∂∂θ⁢f⁡r,θ,φr
subsconvertlhs =~ rhs,set,
%Nabla⁡f⁡X=sin⁡θ⁢cos⁡φ⁢diff⁡f⁡S,r+cos⁡θ⁢cos⁡φ⁢diff⁡f⁡S,θr−sin⁡φ⁢csc⁡θ⁢diff⁡f⁡S,φr⁢sin⁡θ⁢cos⁡φ+sin⁡θ⁢sin⁡φ⁢diff⁡f⁡S,r+cos⁡θ⁢sin⁡φ⁢diff⁡f⁡S,θr+cos⁡φ⁢csc⁡θ⁢diff⁡f⁡S,φr⁢