 Learn all about Computer Science  1. Introduction
In this tutorial, we’ll explore the concepts of gradient, divergence, and curl, learn the underlying math, and learn about their real-world applications.
2. Scalars, Vectors, Fields, and the Cartesian Coordinate System
In physics and math, quantities fall into scalars and vectors.
A scalar has only its magnitude (like time, mass, or temperature) while a vector includes both magnitude and direction, e.g., velocity or force.
Extending these to space, a field assigns values to every point in a region. Scalar fields provide a single value per point (e.g., room temperature), whereas vector fields assign direction and magnitude: imagine electromagnetic waves moving through the air.
To describe fields mathematically, we often use the Cartesian Coordinate System (CCS), which represents a 2D or 3D space with coordinates ( and in 2D and , , and in 3D). Vector fields are defined using unit vectors , , , corresponding to , , and directions:
3. The Del Operator in Vector Calculus
To analyze scalar and vector fields, we use a mathematical tool called the Del operator, denoted as (nabla). It acts like a vector differential operator.
In a Cartesian system, the Del operator is defined as:
![Rendered by QuickLaTeX.com \[\large\nabla = \begin{bmatrix}\frac{\partial}{\partial x} & \frac{\partial}{\partial y} & \frac{\partial}{\partial z}\end{bmatrix}\]](https://www.baeldung.com/wp-content/ql-cache/quicklatex.com-55c8364bc4d4d877e935976eb868fe38_l3.svg)
This means that operates on functions by taking their partial derivatives with respect to , and . Depending on how we apply it, we get different insights into scalar and vector fields:
- Gradient
measures the rate and direction of change in a scalar field 
- Divergence
tells us how much a vector field spreads out from or converges to a point.
- Curl
captures the rotational tendency of a vector field .
4. The Concept of Gradient in a Scalar Field
Say you’re in a large building, looking for the strongest Wi-Fi signal. Since signal strength varies by location, it forms a scalar field, assigning a value (but not a direction) to every point.
Here’s the key question: how do we know which direction to walk in to get the strongest signal as quickly as possible? This is where the gradient comes in. It reveals two things: the direction in which the signal increases most rapidly, and how quickly that happens in that direction.
So, if at a spot with a weak signal, we should walk in the direction pointed to by the gradient of the signal.
Using the log-distance path loss model, we calculate how signal strength changes across space, and from there, compute the gradient to find the best direction for a stronger connection.
We begin with the formula for the signal strength at distance from the router:
![Rendered by QuickLaTeX.com \[P(d) = P_0 - 10n \log_{10} \left( \frac{d}{d_0} \right)\]](https://www.baeldung.com/wp-content/ql-cache/quicklatex.com-0ef144c7000cf8846dd00ee73bdd619c_l3.svg)
Here, is the signal strength at reference distance , and is the path loss exponent (typically 2 to 4).
To understand how Wi-Fi signal strength varies across space, we calculate the gradient of the signal strength function :
![Rendered by QuickLaTeX.com \[\nabla P =\begin{bmatrix}\frac{\partial P}{\partial x} & \frac{\partial P}{\partial y} & \frac{\partial P}{\partial z}\end{bmatrix}\]](https://www.baeldung.com/wp-content/ql-cache/quicklatex.com-a533f8ee07a472b1708443dbdf575ffc_l3.svg)
Since the signal strength depends on distance , and depends on spatial coordinates , we apply the chain rule.
First, we compute the derivative of with respect to distance :
![Rendered by QuickLaTeX.com \[\frac{\partial P}{\partial d} = -\frac{10n}{\ln(10)} \cdot \frac{1}{d}\]](https://www.baeldung.com/wp-content/ql-cache/quicklatex.com-5af06861d89f2cbf605df57f34b58a19_l3.svg)
Since depends on , and on , we’ll need partial derivatives of w.r.t. for the chain rule:
![Rendered by QuickLaTeX.com \[\frac{\partial d}{\partial x} = \frac{x}{d}, \quad \frac{\partial d}{\partial y} = \frac{y}{d}, \quad \frac{\partial d}{\partial z} = \frac{z}{d}\]](https://www.baeldung.com/wp-content/ql-cache/quicklatex.com-ab52558e24995f0f758626e144fa2deb_l3.svg)
.
By combining these, we get:
![Rendered by QuickLaTeX.com \[\nabla P = \left[-\frac{10n}{\ln(10)} \cdot \frac{x}{d^2}, -\frac{10n}{\ln(10)} \cdot \frac{y}{d^2}, -\frac{10n}{\ln(10)} \cdot \frac{z}{d^2} \right] = - \frac{10n}{\ln(10)}\frac{1}{d^2}[x, y, z]\]](https://www.baeldung.com/wp-content/ql-cache/quicklatex.com-425b5ec57265749e69bfee7e8746941d_l3.svg)
4.2. Worked Example
Suppose the router is at the origin (0, 0, 0), and we measure the signal at point (3, 4, 5). Given dBm, meter, and , we first find the distance:
![Rendered by QuickLaTeX.com \[d = \sqrt{3^2 + 4^2 + 5^2} \approx 7.07 \text{m}\]](https://www.baeldung.com/wp-content/ql-cache/quicklatex.com-80dc609e10214abb74ca0e9658d3d484_l3.svg)
Next, using the signal strength model:
![Rendered by QuickLaTeX.com \[P = -30 - 10 \cdot 3 \cdot \log_{10}(7.07) = -55.5 \, \text{dBm}.\]](https://www.baeldung.com/wp-content/ql-cache/quicklatex.com-c586b65cf0e829bf147e3af9521873ea_l3.svg)
We compute the spatial gradient to examine how the signal strength changes with respect to position. First, we calculate the partial derivative of with respect to :
![Rendered by QuickLaTeX.com \[\frac{\partial P}{\partial x} = -\frac{10n}{\ln(10)} \cdot \frac{x}{d^2} = -\frac{30}{\ln(10)} \cdot \frac{3}{50} \approx -0.7822\]](https://www.baeldung.com/wp-content/ql-cache/quicklatex.com-378de20dcafb910dbed36ba225c8839b_l3.svg)
Using the same method, we compute the and components of the gradient as well:
![Rendered by QuickLaTeX.com \[\nabla P(3, 4, 5) \approx\begin{bmatrix}-0.7822 & -1.0424 & -1.3030\end{bmatrix}\ \text{dBm/m}\]](https://www.baeldung.com/wp-content/ql-cache/quicklatex.com-483eaa9ba684463ce3bef5346bf83537_l3.svg)
Let’s interpret these results.
4.3. Interpretation
Negative values mean the signal strength weakens as we move away from the origin, whereas positive values mean the signal strengthens as we approach the origin.
In our example, all the values are negative, and the most rapid drop occurs along the z-axis, indicating that vertical shifts affect the signal strength the most. To improve the connection, we should move toward the origin of the router.
Here’s a 3D figure showing the scalar field of the signal strength:
The corresponding gradient vectors are pointing towards the router:
The gradient of a scalar field points in the direction of steepest increase, and moving in the opposite direction leads to the fastest decrease. This is the idea behind the gradient descent algorithm (GDA), a key method in machine learning used to minimize loss functions.
5. Divergence in a Vector Field
Let’s imagine this: drop a positive charge in space, and electric field lines instantly radiate outward like invisible arrows bursting from a source. With a negative charge, those arrows collapse inward toward it. That’s divergence at play.
Divergence reveals how much a vector field, such as an electric field, spreads from a point (a source) or converges into it (a sink).
The following figure illustrates this behavior:
Mathematically, for a vector field , the divergence is given by:
![Rendered by QuickLaTeX.com \[\mathbf{\nabla} \cdot \mathbf{F} = \frac{\partial F_x}{\partial x} + \frac{\partial F_y}{\partial y} + \frac{\partial F_z}{\partial z}\]](https://www.baeldung.com/wp-content/ql-cache/quicklatex.com-5abf9a86ce3d79eb36d3c00f7ce6fd3a_l3.svg)
This expression is the dot product of the del operator and the vector field in CCS.
When the divergence at a point is positive, the vector field behaves like a source at that specific location. If it’s negative, the point acts like a sink. And when the divergence is zero, the field is locally balanced there.
Let’s illustrate this concept.
5.1. A Smooth Polynomial Field Vector
Let’s consider a vector field . Let’s find the divergence at the point (1, -2, 3).
We apply the divergence formula component-wise:
![Rendered by QuickLaTeX.com \[\nabla \cdot \mathbf{A} = \frac{\partial A_x}{\partial x} + \frac{\partial A_y}{\partial y} + \frac{\partial A_z}{\partial z}\]](https://www.baeldung.com/wp-content/ql-cache/quicklatex.com-f0f3f15a04c6a7629f94eed091d52c66_l3.svg)
Let’s compute each term:
![Rendered by QuickLaTeX.com \[A_x = yz \Rightarrow \frac{\partial A_x}{\partial x} = 0 \quad \text{(no } x \text{ dependence)}\]](https://www.baeldung.com/wp-content/ql-cache/quicklatex.com-cb3ec1f93cb92c627a440bf0c5625327_l3.svg)
![Rendered by QuickLaTeX.com \[A_y = 4xy \Rightarrow \frac{\partial A_y}{\partial y} = 4x\]](https://www.baeldung.com/wp-content/ql-cache/quicklatex.com-81bc7ab8925a776d03263ee1a682d610_l3.svg)
![Rendered by QuickLaTeX.com \[A_z = yz \Rightarrow \frac{\partial A_z}{\partial z} = y\]](https://www.baeldung.com/wp-content/ql-cache/quicklatex.com-623907a1fc0e9faf35880fdc5d284626_l3.svg)
Now plug in the point :
![Rendered by QuickLaTeX.com \[\nabla \cdot \mathbf{A} = 0 + 4(1) + (-2) = 2\]](https://www.baeldung.com/wp-content/ql-cache/quicklatex.com-c04d0da09679486aa2dac4522d387641_l3.svg)
So, the divergence at this point is 2, which means the field is acting like a source there.
6. The Curl of a Vector Field
Let’s say we’re beside a river and place a small paddlewheel in the water. If the water pushes evenly from all directions, the wheel stays still. However, if one side experiences a stronger flow, the wheel spins. That spin reflects the curl: it measures how much a vector field “swirls” around a point.
Mathematically, curl captures the field’s local rotation. For a vector field , the curl is defined as:
![Rendered by QuickLaTeX.com \[\mathbf{\nabla} \times \mathbf{F} = \begin{vmatrix} \mathbf{i} & \mathbf{j} & \mathbf{k} \\ \frac{\partial}{\partial x} & \frac{\partial}{\partial y} & \frac{\partial}{\partial z} \\ F_1 & F_2 & F_3 \end{vmatrix}\]](https://www.baeldung.com/wp-content/ql-cache/quicklatex.com-728d9d0907dc61a0889ee5e8f800c20c_l3.svg)
Expanding this determinant, we get:
![Rendered by QuickLaTeX.com \[\mathbf{\nabla} \times \mathbf{F} = \left( \frac{\partial F_3}{\partial y} - \frac{\partial F_2}{\partial z} \right)\mathbf{i} + \left( \frac{\partial F_1}{\partial z} - \frac{\partial F_3}{\partial x} \right)\mathbf{j} + \left( \frac{\partial F_2}{\partial x} - \frac{\partial F_1}{\partial y} \right)\mathbf{k}\]](https://www.baeldung.com/wp-content/ql-cache/quicklatex.com-98add87e3fd886545683a87d426242c2_l3.svg)
A zero curl means no rotation, i.e., the flow is smooth and straight. In contrast, a nonzero curl reveals spinning around the corresponding axis.
To determine the direction of that curl vector, we apply the right-hand rule. We point the fingers of our right hand in the direction of the flow that’s curving around, and the thumb will point in the direction of the curl:
The curl’s magnitude tells us the rotation speed. The larger the magnitude, the faster the field swirls around that axis. If the curl is zero at a point, there’s no local spinning, just smooth, straight flow.
Let’s apply what we’ve just learned.
6.1. Case 1: A Field with No Curl
Consider the vector field:
![Rendered by QuickLaTeX.com \[\mathbf{F} =\begin{bmatrix}yz & xz & xy\end{bmatrix}\]](https://www.baeldung.com/wp-content/ql-cache/quicklatex.com-af78e9a39eb4ac9dacb79a09b76765c7_l3.svg)
To compute the curl, we evaluate:
![Rendered by QuickLaTeX.com \[\frac{\partial F_3}{\partial y} - \frac{\partial F_2}{\partial z} = x - x = 0\]](https://www.baeldung.com/wp-content/ql-cache/quicklatex.com-d8076cc611ca437fe3abf9966f7f7dbe_l3.svg)
![Rendered by QuickLaTeX.com \[\frac{\partial F_1}{\partial z} - \frac{\partial F_3}{\partial x} = y - y = 0\]](https://www.baeldung.com/wp-content/ql-cache/quicklatex.com-c746219770ced7522c6df0a29ce38ea5_l3.svg)
![Rendered by QuickLaTeX.com \[\frac{\partial F_2}{\partial x} - \frac{\partial F_1}{\partial y} = z - z = 0\]](https://www.baeldung.com/wp-content/ql-cache/quicklatex.com-15f6e00ed5f0150e37c442047c70b610_l3.svg)
As a result, every component of the curl vanishes:
![Rendered by QuickLaTeX.com \[\mathbf{\nabla} \times \mathbf{F} = \mathbf{0}\]](https://www.baeldung.com/wp-content/ql-cache/quicklatex.com-4c8045f04fc2eab0cd89dc1204e680d7_l3.svg)
This means the field has no rotational effect. While the flow exists, it’s entirely non-rotational. So, placing a paddlewheel anywhere in this field leaves it motionless:
In this field, the arrows neither swirl nor form loops around any axis. Using the right-hand rule, we cannot establish a definite circular path. This tells us the field is irrotational, meaning its curl is zero.
6.2. Case 2: A Rotating Field
Now, let’s tweak the field to introduce rotation:
![Rendered by QuickLaTeX.com \[\mathbf{F} =\begin{bmatrix}-y & x & 0\end{bmatrix}\]](https://www.baeldung.com/wp-content/ql-cache/quicklatex.com-5045181959e8a727963ad968995eab4b_l3.svg)
Computing the curl yields:
![Rendered by QuickLaTeX.com \[\frac{\partial F_3}{\partial y} - \frac{\partial F_2}{\partial z} = 0 - 0 = 0\]](https://www.baeldung.com/wp-content/ql-cache/quicklatex.com-cb571a8c8319ccc746ccb4f2f037f3bf_l3.svg)
![Rendered by QuickLaTeX.com \[\frac{\partial F_1}{\partial z} - \frac{\partial F_3}{\partial x} = 0 - 0 = 0\]](https://www.baeldung.com/wp-content/ql-cache/quicklatex.com-170cc2ce36516ac247f4e76d7aea1705_l3.svg)
![Rendered by QuickLaTeX.com \[\frac{\partial F_2}{\partial x} - \frac{\partial F_1}{\partial y} = 1 - (-1) = 2\]](https://www.baeldung.com/wp-content/ql-cache/quicklatex.com-9d63499b654cd93f7ea8ce977e4084cb_l3.svg)
So, we get:
![Rendered by QuickLaTeX.com \[\mathbf{\nabla} \times \mathbf{F} = 2\mathbf{k}\]](https://www.baeldung.com/wp-content/ql-cache/quicklatex.com-012facf1dae0f542fd5171179e971112_l3.svg)
Clearly, the field rotates about the z-axis, much like a whirlpool swirling on a lake’s surface.
The next figure shows this in action:
When we apply the right-hand rule, our thumb points upward along the Z-axis.
7. Conclusion
In this article, we explored the meaning behind three core vector calculus tools: the gradient, curl, and divergence.
The gradient points in the direction of the steepest increase of a scalar field, the divergence tells us how much a vector field spreads out from or converges to a point, and the curl measures the local rotation of a field. The post What Are Gradient, Divergence, and Curl in Vector Calculus? first appeared on Baeldung on Computer Science.
Content mobilized by FeedBlitz RSS Services, the premium FeedBurner alternative. |