Grad Div Curl

Download as pdf or txt
Download as pdf or txt
You are on page 1of 13

The Gradient, Divergence, and Curl https://docs.juliahub.com/CalculusWithJulia/AZHbv/0.0.5/integral_vec...

The Gradient, Divergence, and Curl


The gradient of a scalar function f : Rn → R is a vector field of partial derivatives. In R2 , we have:

∂f ∂f
∇f = ⟨ , ⟩.
∂x ∂y

It has the interpretation of pointing out the direction of greatest ascent for the surface z = f(x, y).

We move now to two other operations, the divergence and the curl, which combine to give a language to describe vector fields in R3 .

using CalculusWithJulia
using Plots

The divergence
Let F : R3 → R3 = ⟨Fx , Fy , Fz ⟩ be a vector field. Consider now a small box-like region, R, with surface, S , on the cartesian grid, with sides of length Δx, Δy, and Δz with (x, y, z) being
j , and ±^k.
one corner. The outward pointing unit normals are ±^i, ±^

^ , could be approximated by
Consider the sides with outward normal ^i. The contribution to the surface integral, ∮S (F ⋅ N)dS

(F (x + Δx, y, z) ⋅ ^i) ΔyΔz,

whereas, the contribution for the face with outward normal −^i could be approximated by:

(F (x, y, z) ⋅ (−^i)) ΔyΔz.

The functions are being evaluated at a point on the face of the surface. For Riemann integrable functions, any point in a partition may be chosen, so our choice will not restrict the
generality.

The total contribution of the two would be:

(F (x + Δx, y, z) ⋅ ^i) ΔyΔz + (F (x, y, z) ⋅ (−^i)) ΔyΔz = (Fx (x + Δx, y, z) − Fx (x, y, z)) ΔyΔz,

as F ⋅ ^i = Fx .

Were we to divide by ΔV = ΔxΔyΔz and take a limit as the volume shrinks, the limit would be ∂F /∂x.

If this is repeated for the other two pair of matching faces, we get a definition for the divergence:

^ = ∂Fx + ∂Fy + ∂Fz .


The divergence of a vector field F : R3 → R3 is given by divergence(F ) = lim 1 ∮S F ⋅ NdS
ΔV ∂x ∂y ∂z

The limit expression for the divergence will hold for any smooth closed surface, S , converging on (x, y, z), not just box-like ones.

General n
The derivation of the divergence is done for n = 3, but could also have easily been done for two dimensions (n = 2) or higher dimensions n > 3. The formula in general would be: for
F (x1 , x2 , … , xn ) : Rn → Rn :
n
∂Fi
divergence(F ) = ∑ .
i=1 ∂xi

In Julia , the divergence can be implemented different ways depending on how the problem is presented. Here are two functions from the CalculusWithJulia package for when the
problem is symbolic or numeric:

1 of 13 11/19/2022, 3:01 PM
The Gradient, Divergence, and Curl https://docs.juliahub.com/CalculusWithJulia/AZHbv/0.0.5/integral_vec...

divergence(F::Vector{Sym}, vars) = sum(diff.(F, vars))


divergence(F::Function, pt) = sum(diag(ForwardDiff.jacobian(F, pt)))

The latter being a bit inefficient, as all n2 partial derivatives are found, but only the n diagonal ones are used.

The curl
Before considering the curl for n = 3, we derive a related quantity in n = 2. The "curl" will be a measure of the microscopic circulation of a vector field. To that end we consider a
microscopic box-region in R2 :

Let F = ⟨Fx , Fy ⟩. For small enough values of Δx and Δy the line integral, ∮C F ⋅ d→
r can be approximated by 4 terms:

(F (x, y) ⋅ ^i) Δx + (F (x + Δx, y) ⋅ ^j) Δy + (F (x, y + Δy) ⋅ (−^i)) Δx + (F (x, y) ⋅ (−^j)) Δx


= Fx (x, y)Δx + Fy (x + Δx, y)Δy + Fx (x, y + Δy)(−Δx) + Fy (x, y)(−Δy)
= (Fy (x + Δx, y) − Fy (x, y))Δy − (Fx (x, y + Δy) − Fx (x, y))Δx.

The Riemann approximation allows a choice of evaluation point for Riemann integrable functions, and the choice here lends itself to further analysis. Were the above divided by ΔxΔy, the
area of the box, and a limit taken, partial derivatives appear to suggest this formula:

1 ∂Fy ∂Fx
lim ∮ F ⋅ d→
r = − .
ΔxΔy C ∂x ∂y
The scalar function on the right hand side is called the (two-dimensional) curl of F and the left-hand side lends itself as a measure of the microscopic circulation of the vector field,
F : R2 → R2 .

Consider now a similar scenario for the n = 3 case. Let F = ⟨Fx , Fy , Fz ⟩ be a vector field and S a box-like region with side lengths Δx, Δy, and Δz, anchored at (x, y, z).

^, designated as S1 . The curve C1 traces around S1 in a counter clockwise manner, consistent with the right-hand rule
The box-like volume in space with the top area, with normal k
^ looks like:
pointing in the outward normal direction. The face S1 with unit normal k

2 of 13 11/19/2022, 3:01 PM
The Gradient, Divergence, and Curl https://docs.juliahub.com/CalculusWithJulia/AZHbv/0.0.5/integral_vec...

Now we compute the line integral. Consider the top face, S1 , connecting (x, y, z + Δz), (x + Δx, y, z + Δz), (x + Δx, y + Δy, z + Δz), (x, y + Δy, z + Δz), Using the right hand rule,
parameterize the boundary curve, C1 , in a counter clockwise direction so the right hand rule yields the outward pointing normal (^
k). Then the integral ∮C F ⋅ T^ds is approximated by the
1
following Riemann sum of 4 terms:

F (x, y, z + Δz) ⋅ ^iΔx + F (x + Δx, y, z + Δz) ⋅ ^jΔy + F (x, y + Δy, z + Δz) ⋅ (−^i)Δx + F (x, y, z + Δz) ⋅ (−^j)Δy.

(The points ci are chosen from the endpoints of the line segments.)

∮ F ⋅ T^ds ≈ (Fy (x + Δx, y, z + Δz) − Fy (x, y, z + Δz))Δy − (Fx (x, y + Δy, z + Δz) − Fx (x, y, z + Δz))Δx
C1

As before, were this divided by the area of the surface, we have after rearranging and cancellation:

1 Fy (x + Δx, y, z + Δz) − Fy (x, y, z + Δz) Fx (x, y + Δy, z + Δz) − Fx (x, y, z + Δz)


∮ F ⋅ T^ds ≈ − .
ΔS1 C1 Δx Δy

In the limit, as ΔS → 0, this will converge to ∂Fy /∂x − ∂Fx /∂y.

Had the bottom of the box been used, a similar result would be found, up to a minus sign.

Unlike the two dimensional case, there are other directions to consider and here the other sides will yield different answers. Consider now the face connecting
(x, y, z), (x + Δx, y, z), (x + Δx, y, z + Δz), and (x, y, z + Δz) with outward pointing normal −^j. Let S2 denote this face and C2 describe its boundary. Orient this curve so that the right
hand rule points in the −^j direction (the outward pointing normal). Then, as before, we can approximate:

^ + F (x, y, z + Δz) ⋅ (−^i)Δx + F (x, y, z) ⋅ (−^k)Δz


∮ F ⋅ T^ds ≈ F (x, y, z) ⋅ ^iΔx + F (x + Δx, y, z) ⋅ kΔz
C2
= (Fz (x + Δx, y, z) − Fz (x, y, z))Δz − (Fx (x, y, z + Δz) − F (x, y, z))Δx.

Dividing by ΔS = ΔxΔz and taking a limit will give:

1 ∂Fz ∂Fx
lim ∮ F ⋅ T^ds = − .
ΔS C2 ∂x ∂z

Had, the opposite face with outward normal ^j been chosen, the answer would differ by a factor of −1.

Similarly, let S3 be the face with outward normal ^i and curve C3 bounding it with parameterization chosen so that the right hand rule points in the direction of ^i. This will give

1 ∂Fz ∂Fy
lim ∮ F ⋅ T^ds = − .
ΔS C3 ∂y ∂z

In short, depending on the face chosen, a different answer is given, but all have the same type.

∂Fz ∂Fy ∂Fx ∂Fz ∂Fy ∂Fx


Define the curl of a 3-dimensional vector field F = ⟨Fx , Fy , Fz ⟩ by: curl(F ) = ⟨ − , − , − ⟩.
∂y ∂z ∂z ∂x ∂x ∂y

If S is some surface with closed boundary C oriented so that the unit normal, N^, of S is given by the right hand rule about C , then

1
N^ ⋅ curl(F ) = lim ∮ F ⋅ T^ds.
ΔS C
The curl has a formal representation in terms of a 3 × 3 determinant, similar to that used to compute the cross product, that is useful for computation:

⎡ ^i ^j ^k ⎤
curl(F ) = det ⎢⎢⎢ ∂x
∂ ∂
∂y
∂ ⎥

∂z ⎥
⎣F Fy F ⎦
x z

In Julia , the curl can be implemented different ways depending on how the problem is presented. We will use the Jacobian matrix to compute the required partials. If the Jacobian is
known, this function from the CalculusWithJulia package will combine the off-diagonal terms appropriately:

3 of 13 11/19/2022, 3:01 PM
The Gradient, Divergence, and Curl https://docs.juliahub.com/CalculusWithJulia/AZHbv/0.0.5/integral_vec...

function curl(J::Matrix)
Mx, Nx, Px, My, Ny, Py, Mz, Nz, Pz = J
[Py-Nz, Mz-Px, Nx-My] # ∇×VF
end

The computation of the Jacobian differs whether the problem is treated numerically or symbolically. Here are two functions:

curl(F::Vector{Sym}, vars=free_symbols(F)) = curl(F.jacobian(vars))


curl(F::Function, pt) = curl(ForwardDiff.jacobian(F, pt))

The ∇ (del) operator


The divergence, gradient, and curl all involve partial derivatives. There is a notation employed that can express the operations more succinctly. Let the Del operator
(https://en.wikipedia.org/wiki/Del) be defined in Cartesian coordinates by the formal expression:

∂ ∂ ∂
∇=⟨ , , ⟩.
∂x ∂y ∂z

This is a vector differential operator that acts on functions and vector fields through the typical notation to yield the three operations:

∂f ∂f∂f
∇f = ⟨, ,
⟩, the gradient;
∂x ∂z∂y
∂ ∂ ∂ ∂ ∂ ∂ ∂Fx ∂Fy ∂Fz
∇⋅F = ⟨ , ,
⟩⋅F =⟨ , , ⟩ ⋅ ⟨Fx , Fy , Fz ⟩ = + + , the divergence;
∂x ∂z∂y ∂x ∂y ∂z ∂x ∂y ∂z
⎡ ^i ^j ^k ⎤
∂ ∂ ∂
∇×F =⟨ , , ⟩ × F = det ⎢⎢⎢ ∂x
∂ ∂
∂y
∂ ⎥
∂z ⎥
⎥ , the curl.
∂x ∂y ∂z
⎣F Fy Fz ⎦
x

Mathematically operators have not been seen previously, but the concept of an operation on a function that returns another function is a common one when using Julia . We have
seen many examples ( plot , D , quadgk , etc.). In computer science such functions are called higher order functions, as they accept arguments which are also functions.

In the CalculusWithJulia package, the constant \nabla[\tab] , producing ∇ implements this operator for functions and symbolic expressions.

f(x,y,z) = x*y*z
f(v) = f(v...)
F(x,y,z) = [x, y, z]
F(v) = F(v...)

@vars x y z
∇(f(x,y,z)) # symbolic operation on the symbolic expression f(x,y,z)

⎡ yz ⎤
⎢ xz ⎥
⎣ xy ⎦

This usage of ∇ takes partial derivatives according to the order given by:

free_symbols(f(x,y,z))

⎡ x⎤
⎢ y⎥
⎣ z⎦

which may not be as desired. In this case, the variables can be specified using a tuple to pair up the expression with the variables to differentiate against:

∇( (f(x,y,z), [x,y,z]) )

⎡ yz ⎤
⎢ xz ⎥
⎣ xy ⎦

For numeric expressions, we have:

4 of 13 11/19/2022, 3:01 PM
The Gradient, Divergence, and Curl https://docs.juliahub.com/CalculusWithJulia/AZHbv/0.0.5/integral_vec...

∇(f)(1,2,3) # a numeric computation. Also can call with a point [1,2,3]

3-element Array{Int64,1}:
6
3
2

(The extra parentheses are unfortunate. Here ∇ is called like a function.)

The divergence can be found symbolically:

∇ ⋅ F(x,y,z)

Or numerically:

(∇ ⋅ F)(1,2,3) # a numeric computation. Also can call (∇ ⋅ F)([1,2,3])

3.0

Similarly, the curl. Symbolically:

∇ × F(x,y,z)

⎡0⎤
⎢0⎥
⎣0⎦

and numerically:

(∇ × F)(1,2,3) # numeric. Also can call (∇ × F)([1,2,3])

3-element Array{Float64,1}:
0.0
0.0
0.0

There is a subtle difference in usage. Symbolically the evaluation of F(x,y,z) first is desired, numerically the evaluation of ∇ ⋅ F or ∇ × F first is desired. As ⋅ and × have lower
precedence than function evaluation, parentheses must be used in the numeric case.

As mentioned, for the symbolic evaluations, a specification of three variables (here x , y , and z ) is necessary. This use takes free_symbols to identify three free symbols which
may not always be the case. (It wouldn't be for, say, F(x,y,z) = [a*x,b*y,0] , a and b constants.) In those cases, the notation accepts a tuple to specify the function or vector
field and the variables, e.g. ( ∇( (f(x,y,z), [x,y,z]) ) , as illustrated; ∇ × (F(x,y,z), [x,y,z]) ; or ∇ ⋅ (F(x,y,z), [x,y,z]) where this is written using function calls to
produce the symbolic expression in the first positional argument, though a direct expression could also be used. In these cases, the named versions gradient , curl , and
divergence may be preferred.

Interpretation
The divergence and curl measure complementary aspects of a vector field. The divergence is defined in terms of flow out of an infinitesimal box, the curl is about rotational flow around an
infinitesimal area patch.

Let F (x, y, z) = [x, 0, 0], a vector field pointing in just the ^i direction. The divergence is simply 1. If V is a box, as in the derivation, then the divergence measures the flow into the side
with outward normal −^i and through the side with outward normal ^i which will clearly be positive as the flow passes through the region V , increasing as x increases, when x > 0.

The radial vector field F (x, y, z) = ⟨x, y, z⟩ is also an example of a divergent field. The divergence is:

F(x,y,z) = [x,y,z]
@vars x y z real=true
∇ ⋅ F(x,y,z)

There is a constant outward flow, emanating from the origin. Here we picture the field when z = 0:

5 of 13 11/19/2022, 3:01 PM
The Gradient, Divergence, and Curl https://docs.juliahub.com/CalculusWithJulia/AZHbv/0.0.5/integral_vec...

Consider the limit definition of the divergence:

1
∇ ⋅ F = lim ∮ F ⋅ N^dA.
ΔV S

In the vector field above, the shape along the curved edges has constant magnitude field. On the left curved edge, the length is smaller and the field is smaller than on the right. The flux
across the left edge will be less than the flux across the right edge, and a net flux will exist. That is, there is divergence.

Now, were the field on the right edge less, it might be that the two balance out and there is no divergence. This occurs with the inverse square laws, such as for gravity and electric field:

@vars x y z real=true
R = [x,y,z]
Rhat = R/norm(R)
VF = (1/norm(R)^2) * Rhat
∇ ⋅ VF |> simplify

The vector field F (x, y, z) = ⟨−y, x, 0⟩ is an example of a rotational field. It's curl can be computed symbolically through:

curl([-y,x,0], [x,y,z])

⎡0⎤
⎢0⎥
⎣2⎦

This vector field rotates as seen in this figure showing slices for different values of z:

The field has a clear rotation about the z axis (illustrated with a line), the curl is a vector that points in the direction of the right hand rule as the right hand fingers follow the flow with
magnitude given by the amount of rotation.

This is a bit misleading though, the curl is defined by a limit, and not in terms of a large box. The key point for this field is that the strength of the field is stronger as the points get farther
away, so for a properly oriented small box, the integral along the closer edge will be less than that along the outer edge.

Consider a related field where the strength gets smaller as the point gets farther away but otherwise has the same circular rotation pattern

6 of 13 11/19/2022, 3:01 PM
The Gradient, Divergence, and Curl https://docs.juliahub.com/CalculusWithJulia/AZHbv/0.0.5/integral_vec...

R = [-y, x, 0]
VF = R / norm(R)^2
curl(VF, [x,y,z]) .|> simplify

⎡0⎤
⎢0⎥
⎣0⎦

Further, the curl of R/norm(R)^3 now points in the opposite direction of the curl of R . This example isn't typical, as dividing by norm(R) with a power greater than 1 makes the vector field
discontinuous at the origin.

The curl of the vector field F (x, y, z) = ⟨0, 1 + y 2 , 0⟩ is 0, as there is clearly no rotation as seen in this slice where z = 0:

ERROR: UndefVarError: .. not defined

Algebraically, this is so:

curl(Sym[0,1+y^2,0], [x,y,z])

⎡0⎤
⎢0⎥
⎣0⎦

Now consider a similar field F (x, y, z) = ⟨0, 1 + x2 , 0, ⟩. A slice is somewhat similar, in that the flow lines are all in the ^j direction:

ERROR: UndefVarError: .. not defined

However, this vector field has a curl:

curl([0, 1+x^2,0], [x,y,z])

⎡ 0⎤
⎢ 0⎥
⎣ 2x ⎦

^ direction (out of the figure). A useful visualization is to mentally place a small paddlewheel at a point and imagine if it will turn. In the constant field case, there is
The curl points in the k
equal flow on both sides of the axis, so it any forces on the wheel blades will balance out. In the latter example, if x > 0, the force on the right side will be greater than the force on the left
^ direction, as seen algebraically in the curl.
so the paddlewheel would rotate counter clockwise. The right hand rule for this rotation will point in the upward, or k

Following Strang, in general the curl can point in any direction, so the amount the paddlewheel will spin will be related to how the paddlewheel is oriented. The angular velocity of the
wheel will be (1/2)(∇ × F ) ⋅ N^, N^ being the normal for the paddlewheel.

If a→ is some vector and r^ = ⟨x, y, z⟩ is the radial vector, then a→ × r→ has a curl, which is given by:

@vars x y z a1 a2 a3
a = [a1, a2, a3]
r = [x, y, z]
curl(a × r, [x,y, z])

⎡ 2a1 ⎤
⎢ 2a2 ⎥
⎣ 2a ⎦
3

The angular velocity then is a→ ⋅ N^. The curl is constant. As the dot product involves the cosine of the angle between the two vectors, we see the turning speed is largest when N^ is
parallel to a→. This gives a similar statement for the curl like the gradient does for steepest growth rate: the maximum rotation rate of F is (1/2)∥∇ × F ∥ in the direction of ∇ × F .

The curl of the radial vector field, F (x, y, z) = ⟨x, y, z⟩ will be →


0 :

curl([x,y,z], [x,y,z])

⎡0⎤
⎢0⎥
⎣0⎦

We will see that this can be anticipated, as F = (1/2)∇(x2 + y 2 + z 2 ) is a gradient field.

In fact, the curl of any radial field will be →


0 . Here we represent a radial field as a scalar function of r→ time r^:

7 of 13 11/19/2022, 3:01 PM
The Gradient, Divergence, and Curl https://docs.juliahub.com/CalculusWithJulia/AZHbv/0.0.5/integral_vec...

H = SymFunction("H")
R = sqrt(x^2 + y^2 + z^2)
Rhat = [x, y, z]/R
curl(H(R) * Rhat, [x, y, z])

⎡0⎤
⎢0⎥
⎣0⎦

Were one to represent the curl in spherical (https://en.wikipedia.org/wiki/Del_in_cylindrical_and_spherical_coordinates) coordinates (below), this follows algebraically from the formula
easily enough. To anticipate this, due to symmetry, the curl would need to be the same along any ray emanating from the origin and again by symmetry could only possible point along the
ray. Mentally place a paddlewheel along the x axis oriented along ^i. There will be no rotational forces that could make the wheel spin around the x-axis, hence the curl must be 0.

The Maxwell equations


The divergence and curl appear in Maxwell (https://en.wikipedia.org/wiki/Maxwell%27s_equations)'s equations describing the relationships of electromagnetism. In the formulas below the
notation is E is the electric field; B is the magnetic field; ρ is the charge density (charge per unit volume); J the electric current density (current per unit area); and ϵ0 , μ0 , and c are
universal constants.

The equations in differential form are:

Gauss's law: ∇ ⋅ E = ρ/ϵ0 .

That is, the divergence of the electric field is proportional to the density. We have already mentioned this in integral form.

Gauss's law of magnetism: ∇ ⋅ B = 0

The magnetic field has no divergence. This says that there no magnetic charges (a magnetic monopole) unlike electric charge, according to Maxwell's laws.

Faraday's law of induction: ∇ × E = −∂B/∂t.

The curl of the time-varying electric field is in the direction of the partial derivative of the magnetic field. For example, if a magnet is in motion in the in the z axis, then the electric field has
rotation in the x − y plane induced by the motion of the magnet.

Ampere's circuital law: ∇ × B = μ0 J + μ0 ϵ0 ∂E/∂t

The curl of the magnetic field is related to the sum of the electric current density and the change in time of the electric field.

In a region with no charges (ρ = 0) and no currents (J = →


0 ), such as a vacuum, these equations reduce to two divergences being 0: ∇ ⋅ E = 0 and ∇ ⋅ B = 0; and two curl relationships
with time derivatives: ∇ × E = −∂B/∂t and ∇ × B = μ0 ϵ0 ∂E/∂t.

We will see later how these are differential forms are consequences of related integral forms.

Algebra of vector calculus


The divergence, gradient, and curl satisfy several algebraic properties (https://en.wikipedia.org/wiki/Vector_calculus_identities).

Let f and g denote scalar functions, R3 → R and F and G be vector fields, R3 → R3 .

Linearity
As with the sum rule of univariate derivatives, these operations satisfy:

∇(f + g) = ∇f + ∇g
∇ ⋅ (F + G) = ∇ ⋅ F + ∇ ⋅ G
∇ × (F + G) = ∇ × F + ∇ × G.

Product rule
The product rule (uv)′ = u′ v + uv′ has related formulas:

∇(fg) = (∇f)g + f∇g = g∇f + f∇g


∇ ⋅ fF = (∇f) ⋅ F + f(∇ ⋅ F )
∇ × fF = (∇f) × F + f(∇ × F ).

Rules over cross products


The cross product of two vector fields is a vector field for which the divergence and curl may be taken. There are formulas to relate to the individual terms:

∇ ⋅ (F × G) = (∇ × F ) ⋅ G − F ⋅ (∇ × G)
∇ × (F × G) = F (∇ ⋅ G) − G(∇ ⋅ F + (G ⋅ ∇)F − (F ⋅ ∇)G
= ∇ ⋅ (BAt − ABt ).

8 of 13 11/19/2022, 3:01 PM
The Gradient, Divergence, and Curl https://docs.juliahub.com/CalculusWithJulia/AZHbv/0.0.5/integral_vec...

The curl formula is more involved.

Vanishing properties
Surprisingly, the curl and divergence satisfy two vanishing properties. First

The curl of a gradient field is →


0 ∇ × ∇f = →
0 ,

if the scalar function f is has continuous second derivatives (so the mixed partials do not depend on order).

Vector fields where F = ∇f are conservative. Conservative fields have path independence, so any line integral, ∮ F ⋅ T^ds, around a closed loop will be 0. But the curl is defined as a limit
of such integrals, so it too will be →
0 . In short, conservative fields have no rotation.
What about the converse? If a vector field has zero curl, then integrals around infinitesimally small loops are 0. Does this also mean that integrals around larger closed loops will also be 0
, and hence the field is conservative? The answer will be yes, under assumptions. But the discussion will wait for later.

The combination ∇ ⋅ ∇f is defined and is called the Laplacian. This is denoted Δf . The equation Δf = 0 is called Laplace's equation. It is not guaranteed for any scalar function f , but the f
for which it holds are important.

Second,

The divergence of a curl field is 0: ∇ ⋅ (∇ × F ) = 0.

This is not as clear, but can be seen algebraically as terms cancel. First:

∂ ∂ ∂ ∂F ∂Fy ∂Fx ∂Fz ∂Fy ∂Fx ∂ 2 Fz ∂ 2 Fy ∂ 2 Fx ∂ 2 Fz ∂ 2 Fy ∂ 2 Fx


∇ ⋅ (∇ × F ) = ⟨ , , ⟩⋅⟨ z − , − , − ⟩=( − )+( − )+( − )
∂x ∂y ∂z ∂y ∂z ∂z ∂x ∂x ∂y ∂y∂x ∂z∂x ∂z∂y ∂x∂y ∂x∂z ∂y∂z

Focusing on one component function, Fz say, we see this contribution:

∂ 2 Fz ∂ 2 Fz
− .
∂y∂x ∂x∂y
This is zero under the assumption that the second partial derivatives are continuous.

From the microscopic picture of a box this can also be seen. Again we focus on just the appearance of the Fz component function. Let the faces with normals ^i, ^j, −^i, −^j be labeled
A, B, C , and D. This figure shows A (enclosed in blue) and B (enclosed in green):

We will get from the approximate surface integral of the approximate curl the following terms:

@vars x y z Δx Δy Δz
p1, p2, p3, p4=(x, y, z), (x + Δx, y, z), (x + Δx, y + Δy, z), (x, y + Δy, z)
F_z = SymFunction("F_z")
ex = (-F_z(p2...) + F_z(p3...))*Δz + # face A
(-F_z(p3...) + F_z(p4...))*Δz + # face B
(F_z(p1...) - F_z(p4...))*Δz + # face C
(F_z(p2...) - F_z(p1...))*Δz # face D

Δz (− Fz (x, y, z) + Fz (x + Δx, y, z)) + Δz (Fz (x, y, z) − Fz (x, y + Δy, z)) + Δz (Fz (x, y + Δy, z) − Fz (x + Δx, y + Δy, z)) + Δz (− Fz (x + Δx, y, z) + Fz (x + Δx, y + Δy, z))

The term for face A, say, should be divided by ΔyΔz for the curl approximation, but this will be multiplied by the same amount for the divergence calculation, so it isn't written.

The expression above simplifies to:

simplify(ex)

9 of 13 11/19/2022, 3:01 PM
The Gradient, Divergence, and Curl https://docs.juliahub.com/CalculusWithJulia/AZHbv/0.0.5/integral_vec...

This is because of how the line integrals are oriented so that the right-hand rule gives outward pointing normals. For each up stroke for one face, there is a downstroke for a different face,
and so the corresponding terms cancel each other out. So providing the limit of these two approximations holds, the vanishing identity can be anticipated from the microscopic picture.
❆ Example
The invariance of charge (https://en.wikipedia.org/wiki/Maxwell%27s_equations#Charge_conservation) can be derived as a corollary of Maxwell's equation. The divergence of the curl of
the magnetic field is 0, leading to:

∂E ∂ ∂ρ
0 = ∇ ⋅ (∇ × B) = μ0 (∇ ⋅ J + ϵ0 ∇ ⋅ ) = μ0 (∇ ⋅ J + ϵ0 (∇ ⋅ E)) = μ0 (∇ ⋅ J + ).
∂t ∂t ∂t
That is ∇ ⋅ J = −∂ρ/∂t. This says any change in the charge density in time (∂ρ/∂t) is balanced off by a divergence in the electric current density (∇ ⋅ J ). That is, charge can't be created or
destroyed in an isolated system.

Fundamental theorem of vector calculus


The divergence and curl are complementary ideas. Are there other distinct ideas to sort a vector field by? The Helmholtz decomposition says not really. It states that vector fields that
decay rapidly enough can be expressed in terms of two pieces: one with no curl and one with no divergence.

From Wikipedia (https://en.wikipedia.org/wiki/Helmholtz_decomposition) we have this formulation:

Let F be a vector field on a bounded domain V which is twice continuously differentiable. Let S be the surface enclosing V . Then F can be decomposed into a curl-free component and
a divergence-free component:

F = −∇(ϕ) + ∇ × A.

Without explaining why, these values can be computed using volume and surface integrals:

′ 1 ∇ ⋅ F (→
r ) 1 F (→ r ) ^
ϕ(→
r )= ∫ ′
dV − ∮ ′
⋅ NdS
4π V ∥→
r − r→∥ 4π S ∥→r − r→∥
′ 1 ∇ × F (→r ) 1 F (→ r ) ^
A(→
r )= ∫ ′
dV + ∮ ′
× NdS.
4π V ∥→
r − r→∥ 4π S ∥→ r − r→∥

If V = R3 , an unbounded domain, but F vanishes faster than 1/r, then the theorem still holds with just the volume integrals:

′ 1 ∇ ⋅ F (→
r )
ϕ(→
r )= ∫ ′
dV
4π V ∥→
r − r→∥
′ 1 ∇ × F (→r )
A(→
r )= ∫ dV .
r ′ − r→∥
4π V ∥→

Change of variable
The divergence and curl are defined in a manner independent of the coordinate system, though the method to compute them depends on the Cartesian coordinate system. If that is
inconvenient, then it is possible to develop the ideas in different coordinate systems.

Some details are here (https://en.wikipedia.org/wiki/Curvilinear_coordinates), the following is based on some lecture notes (https://www.jfoadi.me.uk/documents
/lecture_mathphys2_05.pdf).

We restrict to n = 3 and use (x, y, z) for Cartesian coordinates and (u, v, w) for an orthogonal curvilinear coordinate system, such as spherical or cylindrical. If r→ = ⟨x, y, z⟩, then

d→
r = ⟨dx, dy, dz⟩ = J⟨du, dv, dw⟩
∂→r ∂→r ∂→ r
=[ ⋮ ⋮ ] ⟨du, dv, dw⟩
∂u ∂v ∂w
∂→
r ∂→r ∂→
r
= du + dv dw.
∂u ∂v ∂w
The term ∂→
r /∂u is tangent to the curve formed by assuming v and w are constant and letting u vary. Similarly for the other partial derivatives. Orthogonality assumes that at every point,
these tangent vectors are orthogonal.

As ∂→
r /∂u is a vector it has a magnitude and direction. Define the scale factors as the magnitudes:

∂→
r ∂→
r ∂→
r
hu = ∥ ∥, hv = ∥ ∥, hw = ∥ ∥.
∂u ∂v ∂w
and let e^u , e^v , and e^w be the unit, direction vectors.

This gives the following notation:

r = hu due^u + hv dve^v + hw dwe^w .


d→
From here, we can express different formulas.

For line integrals, we have the line element:

dl = √d→ r = √(hu du )2 + (hv dv )2 + (hw dw )2 .


r ⋅ d→

Consider the surface for constant u. The vector e^v and e^w lie in the surface's tangent plane, and the surface element will be:

dSu = ∥hv dve^v × hw dwe^w ∥ = hv hw dvdw∥e^v ∥ = hv hw dvdw.

This uses orthogonality, so e^v × e^w is parallel to e^u and has unit length. Similarly, dSv = hu hw dudw and dSw = hu hv dudv .

r onto the e^u , e^v , e^w coordinate system through (d→


The volume element is found by projecting d→ r ⋅ e^u )e^u , (d→
r ⋅ e^v )e^v , and (d→
r ⋅ e^w )e^w . Then forming the triple scalar product to
compute the volume of the parallelepiped:

r ⋅ e^u )e^u ] ⋅ ([(d→


[(d→ r ⋅ e^v )e^v ] × [(d→
r ⋅ e^w )e^w ]) = (hu hv hw )(dudvdw)(e^u ⋅ (e^v × e^w ) = hu hv hw dudvdw,

10 of 13 11/19/2022, 3:01 PM
The Gradient, Divergence, and Curl https://docs.juliahub.com/CalculusWithJulia/AZHbv/0.0.5/integral_vec...

r ⋅ e^u = hu du, etc.


as the unit vectors are orthonormal, their triple scalar product is 1 and d→

Example
We consider spherical coordinates with

F (r, θ, ϕ) = ⟨r sin(ϕ) cos(θ), r sin(ϕ) sin(θ), r cos(ϕ)⟩.

The following figure draws curves starting at (r0 , θ0 , ϕ0 ) formed by holding 2 of the 3 variables constant. The tangent vectors are added in blue. The surface Sr formed by a constant value
of r is illustrated.

The tangent vectors found from the partial derivatives of r→:

∂→r
= ⟨cos(θ) ⋅ sin(ϕ), sin(θ) ⋅ sin(ϕ), cos(ϕ)⟩,
∂r
∂→r
= ⟨−r ⋅ sin(θ) ⋅ sin(ϕ), r ⋅ cos(θ) ⋅ sin(ϕ), 0⟩,
∂θ
∂→
r
= ⟨r ⋅ cos(θ) ⋅ cos(ϕ), r ⋅ sin(θ) ⋅ cos(ϕ), −r ⋅ sin(ϕ)⟩.
∂ϕ
With this, we have hr = 1, hθ = r sin(ϕ), and hϕ = r. So that

dl = √dr2 + (r sin(ϕ)dθ2 ) + (rdϕ)2 , dSr = r2 sin(ϕ)dθdϕ, dSθ = rdrdϕ, dSϕ = r sin(ϕ)drdθ, and dV = r2 sin(ϕ)drdθdϕ.

The following visualizes the volume and the surface elements.

The gradient in a new coordinate system


If f is a scalar function then df = ∇f ⋅ d→
r by the chain rule. Using the curvilinear coordinates:

∂f ∂f ∂f 1 ∂f 1 ∂f 1 ∂f
df = du + dv + dw = hu du + hv dv + hw dw.
∂u ∂v ∂w hu ∂u hv ∂v hw ∂w

r ⋅ e^u = hu du, etc. so df can be re-expressed as:


But, as was used above, d→

1 ∂f 1 ∂f 1 ∂f
df = ( e^u + e^v + e^w ) ⋅ d→
r = ∇f ⋅ d→
r .
hu ∂u hv ∂v hw ∂w
The gradient is the part within the parentheses.

As an example, in cylindrical coordinates, we have hr = 1, hθ = r, and hz = 1, giving:

11 of 13 11/19/2022, 3:01 PM
The Gradient, Divergence, and Curl https://docs.juliahub.com/CalculusWithJulia/AZHbv/0.0.5/integral_vec...

∂f 1 ∂f ∂f
∇f = e^r + e^θ + e^z
∂r r ∂θ ∂z

The divergence in a new coordinate system


The divergence is a result of the limit of a surface integral,

1
∇ ⋅ F = lim ∮ F ⋅ N^dS.
ΔV S
Taking V as a box in the curvilinear coordinates, with side lengths hu du, hv dv, and hw dw the surface integral is computed by projecting F onto each normal area element and multiplying
by the area. The task is similar to how the the divergence was derived above, only now the terms are like ∂(Fu hv hw )/∂u due to the scale factors (Fu is the u component of F .) The result
is:

1 ∂(Fu hv hw ) ∂(hu Fv hw ) ∂(hu hv Fw )


∇⋅F = [ + + ].
hu hv hw ∂u ∂v ∂w

For example, in cylindrical coordinates, we have

1 ∂Fr r ∂Fθ ∂Fx


∇⋅F = [ + + ].
r ∂r ∂θ ∂z

The curl in a new coordinate system


The curl, like the divergence, can be expressed as the limit of an integral:

1
(∇ × F ) ⋅ N^ = lim ∮ F ⋅ d→
r ,
ΔS C

where S is a surface perpendicular to N^ with boundary C . For a small rectangular surface, the derivation is similar to above, only the scale factors are included. This gives, say, for the e^u
∂(hz Fz ) ∂(hy Fy )
normal, − ∂z
. The following determinant form combines the terms compactly:
∂y

⎡ hu e^u hv e^v hw e^w ⎤


∇ × F = det ⎢⎢ ∂u∂ ∂
∂v

∂w ⎥
⎥.
⎣h F hv Fv hw Fw ⎦
u u

For example, in cylindrical coordinates, the curl is:

⎡ r^ rθ^ k^ ⎤
det ⎢⎢ ∂ ∂ ∂ ⎥
∂r ∂θ ∂z ⎥
⎣F rFθ F ⎦
r z

Applying this to the function F (r, θ, z) = θ^ we get:

⎡ r^ rθ^ k^ ⎤ ∂ ∂
curl(F ) = det ⎢⎢ ∂ ∂ ∂ ⎥
= k^ det [ ∂r ∂θ ] = ^k.
∂r ∂θ ∂z ⎥
⎣ 0 0 r
r 0 ⎦
^ direction, as we found.
As F represents a vector field that rotates about the z axis at a constant rate, the magnitude of the curl should be a constant and it should point in the k

Questions
❂ Question

Numerically find the divergence of F (x, y, z) = ⟨xy, yz, zx⟩ at the point ⟨1, 2, 3⟩.

❂ Question

Numerically find the curl of F (x, y, z) = ⟨xy, yz, zx⟩ at the point ⟨1, 2, 3⟩. What is the x component?

❂ Question

Let F (x, y, z) = ⟨sin(x), exy , xyz⟩. Find the divergence of F symbolically.

xy + xexy + cos (x)


xy + xexy
xexy + cos (x)
❂ Question

Let F (x, y, z) = ⟨sin(x), exy , xyz⟩. Find the curl of F symbolically. What is the x component?

−yz
xz
yexy

12 of 13 11/19/2022, 3:01 PM
The Gradient, Divergence, and Curl https://docs.juliahub.com/CalculusWithJulia/AZHbv/0.0.5/integral_vec...

❂ Question

Let ϕ(x, y, z) = x + 2y + 3z. We know that ∇ × ∇ϕ is zero by the vanishing property. Compute ∇ ⋅ ∇ϕ.

6
0

0
❂ Question

In two dimension's the curl of a gradient field simplifies to:

∂f
∂f
∂f ∂f ∂ ∂ ∂x
∂y
∇ × ∇f = ∇ × ⟨ , ⟩= − .
∂x ∂y ∂x ∂y
This is 0 for any f , as ∇ × ∇ is 0 since the cross product of vector with itself is the 0 vector.

This is 0 if the partial derivatives are continuous by Schwarz's (Clairault's) theorem

❂ Question

Based on this vector-field plot

ERROR: UndefVarError: .. not defined

which seems likely

The field is incompressible (divergence free)

The field is irrotational (curl free)

The field has a non-trivial curl and divergence

❂ Question

Based on this vectorfield plot

ERROR: UndefVarError: .. not defined

which seems likely

The field is incompressible (divergence free)

The field is irrotational (curl free)

The field has a non-trivial curl and divergence

❂ Question

The electric field E (by Maxwell's equations) satisfies:

The field is incompressible (divergence free)

The field is irrotational (curl free)

The field has a non-trivial curl and divergence

❂ Question

The magnetic field B (by Maxwell's equations) satisfies:

The field is incompressible (divergence free)

The field is irrotational (curl free)

The field has a non-trivial curl and divergence

❂ Question

For spherical coordinates, Φ(r, θ, ϕ) = r⟨sin ϕ cos θ, sin ϕ sin θ, cos ϕ⟩, the scale factors are hr = 1, hθ = r sin ϕ, and hϕ = r.

The curl then will then be

⎡ e^r r sin ϕe^θ re^ϕ ⎤


∇ × F = det ⎢⎢ ∂r
∂ ∂ ∂ ⎥
∂θ ∂phi ⎥
.
⎣ Fr r sin ϕFθ rFϕ ⎦

For a radial function F = h(r)er . (That is Fr = h(r), Fθ = 0, and Fϕ = 0. What is the curl of F ?


0
reϕ
rh′ (r)eϕ

13 of 13 11/19/2022, 3:01 PM

You might also like