Examples in Physics
Vectors and Analytical Geometry
Vectorial equation of a line
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.
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.
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_
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
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
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
Thus the vectorial equation for these particular points A and B is
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
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.
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:
Now construct the appropriate input for the spacecurve command, say for z from -4 to 4
Some options for improving the visualization are
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.
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_
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
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:
A_ ≔ 2 _i − 3 _j + 4 _k
B_ ≔ 5 _i + 4 _j − 7 _k
C_ ≔ 304 A_ + 907 B_
For r→ we always have
The vectorial equation for these particular points A, B, and C is thus:
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:
The following shows that, for these points A→,B→,C→, the equation is satisfied:
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.
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
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
Expand both expressions to use them together.
mapu → u^2, key
So simplify one with respect to the other one, eliminating B→ (see simplify/siderels)
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
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.
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
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
From which the value of
can be computed directly, using the value command
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
So, the answer introduced in (30) becomes:
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
The parametric equations for this curve are
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
The curve C can also be passed in vector form
The equations of circle of radius a on the (x,y) plane can be written as
In vector notation,
Changing the basis of this vector, for example to cylindrical, we get
The same result can be obtained by specifying the basis
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.
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:
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
and two types of volume integrals
The line element dr→ in path integrals is expressed in terms of a parameter t as
Using indexed notation for derivatives r→u=∂∂ur→⁡u,v, the surface element dS→ in surface integrals is expressed in terms of parameters as
and the volume element dV in volume integrals as
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
Consider the following scalar function F, path C and integration limits A→ and B→
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
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
To see the integral after being parametrized and before performing the integration you can use the option inert
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)
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.
The integration path and the limits of integration can be expressed in vector notation as well
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
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.
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
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
r→⁡θ,φ⁢will now be displayed as⁢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
Introduce this value of r→ into the expression for n→ and change basis to spherical
Putting all together, the area of a sphere of radius a is given by this closed surface integral
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⁢π
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
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
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
To compute the line element dr→ in spherical coordinates, the starting point is the transformation
tr ≔ X =~ ChangeCoordinatesX,spherical
⁢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
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
The line element
simplifysubsconvertlhs =~ rhs,set,
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)
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
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
The scale-factors hj do not constitute a tensor, so on the right-hand side we do not sum over j. Also, from
it follows that,
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.
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
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
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
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_φ
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
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
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:
The gradient of a function f, in Cartesian and spherical coordinates respectively, is given by
%Nabla = NablafX
%Nabla = NablafS
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)
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__c1,A__c2,A__c3 =~ diff⁡f⁡X,x,diff⁡f⁡X,y,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) .
subsconvertlhs =~ rhs,set,