Gradient, Divergence and Curl

In this post, we are going to study three important tools for the analysis of electromagnetic fields: the gradient, divergence and curl. We will see a clear definition and then do some practical examples that you can follow by downloading the Matlab code available here. This code obtains the gradient, divergence and curl of electromagnetic fields. First, let’s have a look at the definition of the 3 tools.¬†If you want to review the theoretical definitions in relation to the Maxwell’s equations, have a look at our previous post here.

Ready? Let’s get in to it! ūüôā


The gradient is a vector that indicates the direction where the field values increase. In other words, if we place ourselves in any point of the space, x, the gradient in that point will tell us the direction where we are going to find higher values of the field.

Watch out! It doesn’t indicate the direction towards other point where the field takes the highest value! It indicates the direction where the field increases the most, taking into account the values that surround the given point. The module of the gradient tells us how much the field increases in that direction.

The gradient can be applied to scalar fields (it can’t be applied to vector fields), like¬†the temperatures distribution in a body, and it’s always perpendicular to the equipotential lines, like the isotherm and isobar lines.

The following picture shows a representation of the gradient of a scalar field and its relation with the equipotential surface (note that “Cte” means “constant”).




The divergence can only be applied to vector fields. It is a vector that indicates the direction where the field lines are more separated; this is the direction where the density of the field lines decreases by unit of volume. The module of the divergence tells us how much that density decreases. The divergence can be high even if the field is very low at that point.

A high divergence means that in the area, the field lines are “opening” like the light rays that come out from a punctual source. A null divergence indicates that in that area, the lines are parallel, like the speeds of a fluid in a tube, without turbulence, even if the tube is curved, all the fluid will be moving uniformly.



The curl is a vector that indicates the how “curl” the field or lines of force¬†are around a point. It can be only applied to vector fields.

A curl equal to zero means that in that region, the lines of field are straight (although they don’t need to be parallel, because they can be opened symmetrically if there is divergence at¬†that point).

A curl different than zero indicates that in the area around that point, the field lines are arcs, therefore, this is a region where the field is being curved. The direction of the curl vector is normal to the curve plane and its intensity indicates the amount of curl that the field experiences.

Even when¬†the curl of a field around a point is different from zero, this doesn’t mean that the field lines are turning around the point and enclosing it. For example, the field of a fluid speeds that travels through a pipe (the Poiseuille profile) have a curl which is different from zero at some points, but not in the central axis, even when the current travels in a straight line.




Exercise 1:

Input a scalar for the gradient: x^2+ 3*y^4-z


grad =

[ 2*x, 12*y^3, -1]


Input the x component of the vector: x^2-z

Input the y component of the vector: z+y

Input the y component of the vector: y-3*z

The vector is:

F =

[ x^2 – z, y + z, y – 3*z]

The divergence is:

div =

2*x – 2

The curl is:

rot =

[ 0, -1, 0]



Exercise 2:

Input a scalar for the gradient: 5*x^3-z


grad =

[ 15*x^2, 0, -1]


Input the x component of the vector: 9-y

Input the y component of the vector: 2*z-2*y^3

Input the z component of the vector: -y+2*x

The vector is:

F =

[ 9 – y, 2*z – 2*y^3, 2*x – y]


The divergence is:

div =


The curl is:

rot =

[ -3, -2, 1]




Add a Comment

Your email address will not be published. Required fields are marked *