Grad
Details
- Grad is also known as the raised covariant derivative.
- Grad[f,x] can be input as ∇xf. The character ∇ can be typed as
del
or \[Del]. The list of variables x is entered as a subscript. - An empty template ∇ can be entered as
grad
, and
moves the cursor from the subscript to the main body. - All quantities that do not explicitly depend on the variables given are taken to have zero partial derivative.
- If f is an array of dimensions {n1,…,nk}, then Grad[f,{x1,…,xm}] yields an array of dimensions {n1,…,nk,m}.
- If f is a scalar, Grad[f,{x1,x2,…,xn},chart] returns a vector in the orthonormal basis associated with chart.
- In Grad[f,{x1,…,xn},chart], if f is an array, it must have dimensions {n,…,n}. The components of f are interpreted as being in the orthonormal basis associated with chart.
- For coordinate charts on Euclidean space, Grad[f,{x1,…,xn},chart] can be computed by transforming f to Cartesian coordinates, computing the ordinary gradient and transforming back to chart. »
- A key property of Grad is that if chart is defined with metric g, expressed in the orthonormal basis, then Grad[g,{x1,…,xn},chart] gives zero. »
- Coordinate charts in the third argument of Grad can be specified as triples {coordsys,metric,dim} in the same way as in the first argument of CoordinateChartData. The short form in which dim is omitted may be used.
- Grad[f,VectorSymbol[…]] computes the gradient with respect to the vector symbol. »
- Grad works with SparseArray and structured array objects.
Examples
open all close allBasic Examples (4)
The gradient in three-dimensional Cartesian coordinates:
Grad[f[x, y, z], {x, y, z}]The gradient using an orthonormal basis for three-dimensional cylindrical coordinates:
Grad[f[r, θ, z], {r, θ, z}, "Cylindrical"]The gradient in two dimensions:
Grad[Sin[x ^ 2 + y ^ 2], {x, y}]Use
del
to enter ∇ and
to enter the list of subscripted variables:
Subscript[∇, {x, y}]f[x, y]Use
grad
to enter the template ∇; press
to move between inputs:
Subscript[∇, {x, y}]f[x, y]Scope (8)
The gradient of a vector field in Cartesian coordinates, the Jacobian matrix:
Grad[{f[x, y, z], g[x, y, z], h[x, y, z]}, {x, y, z}]Compute the Hessian of a scalar function:
grad = Grad[x * y * z, {x, y, z}]Grad[grad, {x, y, z}]In a curvilinear coordinate system, a vector with constant components may have a nonzero gradient:
Grad[{1, 1, 1}, {r, θ, ϕ}, "Spherical"]Gradient specifying metric, coordinate system, and parameters:
Grad[f[ϕ, ψ], {ϕ, ψ}, {{"Confocal", {a, b}}, "Euclidean"}]//SimplifyGrad works on curved spaces:
Grad[f[u, v, w], {u, v, w}, {"Stereographic", {"Sphere", r}}]The gradient of the norm
with respect to
is the unit vector in the direction of
:
x = VectorSymbol["x", n, Reals];Grad[Sqrt[x.x], x]The gradient of
with respect to itself is SymbolicIdentityArray[{n}]:
Grad[x, x]The power rule for vectors gives a matrix whose diagonal follows the normal power rule:
Grad[x ^ k, x]//ArraySimplifyWrite out this result in three dimensions:
Block[{n = 3}, ComponentExpand[%]]//MatrixFormThe gradient of the coordinates with respect to themselves:
Grad[Inactive[Table][Subscript[x, i], {i, n}], Inactive[Table][Subscript[x, i], {i, n}]]This is the identity matrix in n dimensions:
Activate[% /. n -> 3]//MatrixFormThe gradient of the norm in n dimensions:
Grad[Sqrt[Sum[(Subscript[x, i])^2, {i, n}]], Inactive[Table][Subscript[x, j], {j, n}]]Specialize to the result in three dimensions:
Activate[% /. n -> 3]Applications (4)
Compute the force from a potential function:
-Grad[k q / r, {r, θ, ϕ}, "Spherical"]Find the critical points of a function of two variables:
f[x_, y_] := x ^ 4 + y ^ 4 - 20x ^ 2 - 10x y - 25grad = Grad[f[x, y], {x, y}]sol = NSolve[grad == {0, 0}, {x, y}, Reals]Compute the signs of
and the Hessian determinant at the three critical points:
hessian = Grad[grad, {x, y}]Sign[hessian[[1, 1]] /. sol]Sign[Det[hessian] /. sol]By the second derivative test, the first two points—red and blue in the plot—are minima, and the third—green in the plot—is a saddle point:
Show[Plot3D[f[x, y], {x, -5, 5}, {y, -5, 5}, PlotRange -> 200, ClippingStyle -> None, Mesh -> {5, 0}, PlotStyle -> Opacity[.65], BoxRatios -> {1, 1, 3 / 4}, ViewPoint -> {1.2, -2.5, 0}], Graphics3D[{PointSize[.04], Riffle[{StandardRed, StandardBlue, StandardGreen}, Point[{x, y, f[x, y]}] /. sol]}]]Find the critical points of a function of three variables:
f[x_, y_, z_] := 25 - x^2 + 2 x^4 - x y - y^2 + 4 x^2 y^2 + 2 y^4 - 2 x z - 2 y z - z^2 + 4 x^2 z^2 + 4 y^2 z^2 + 2 z^4grad = Grad[f[x, y, z], {x, y, z}]sol = NSolve[grad == {0, 0, 0}, {x, y, z}, Reals]Compute the Hessian matrix of
:
hessian = Grad[grad, {x, y, z}]When the eigenvalues of a critical point all have the same sign, the point is a local extremum; if there are both positive and negative values, it is a saddle point:
Sign[Eigenvalues[hessian] /. sol]Since the first two points have all positive eigenvalues, they are local minima; the global minimum is found by evaluating
at those two points:
f[x, y, z] /. Take[sol, 2]For this function, any three of the critical points are linearly dependent, so they all lie in a single plane:
Minors[{x, y, z} /. sol, 3]//Quiet//ChopCompute the normal to that plane:
normal = Apply[Cross, {x, y, z} /. sol[[{1, 3}]]]Visualize the function, with the minima yellow and the non-extreme critical points cyan:
Show[SliceContourPlot3D[f[x, y, z], {{x, y, z}.normal == 0}, {x, -1, 1}, {y, -1, 1}, {z, -1, 1}, Contours -> 15, ViewVertical -> {-0.2, 0.7, 0.6}, ViewPoint -> {-1.2, -1.2, 2.9}], Graphics3D[{Riffle[{StandardYellow, StandardYellow, StandardCyan, StandardCyan, StandardCyan}, Sphere[{x, y, z}, 0.05] /. sol]}]]Compute the gradients at the origin of a vector-valued function up to order 6:
f[x_, y_, z_] := {Sin[x z], Sinh[y] + Cos[ z]}
grads = NestList[Grad[#, {x, y, z}]&, f[x, y, z], 6] /. {x -> 0, y -> 0, z -> 0};View the value of the function and its first three derivatives at the origin:
MatrixForm /@ Take[grads, 4]Compute the third-order Maclaurin series of f by hand:
𝕏 = {x, y, z};
(1/0!)grads[[1]] + (1/1!)grads[[2]].𝕏 + (1/2!)grads[[3]].𝕏.𝕏 + (1/3!)grads[[4]].𝕏.𝕏.𝕏Programmatically compute the sixth-order Maclaurin series:
Sum[(1/(k - 1)!)Dot[grads[[k]], ##]&@@Table[𝕏, {k - 1}] , {k, 7}]Properties & Relations (6)
Grad[f,vars] is effectively equivalent to D[f,{vars}]:
Grad[x * y * Sin[z], {x, y, z}]D[x * y * Sin[z], {{x, y, z}}]Grad[{x * y, y * z, z * x}, {x, y, z}]D[{x * y, y * z, z * x}, {{x, y, z}}]Grad adds a new tensor slot at the end, corresponding to a new innermost dimension:
postgrad = Grad[{f1[x, y], f2[x, y]}, {x, y}]To add the new slot at the beginning, use Transpose to exchange the first and last slots:
pregrad = Transpose[{{f1^(1, 0)[x, y], f1^(0, 1)[x, y]}, {f2^(1, 0)[x, y], f2^(0, 1)[x, y]}}]This is relevant when working with directional derivatives of arrays:
postgrad.{v1, v2}{v1, v2}. pregradCompute Grad in a Euclidean coordinate chart c by transforming to and then back from Cartesian coordinates:
TransformedField["Polar" -> "Cartesian", f[r, θ], {r, θ} -> {x, y}]Grad[%, {x, y}]FullSimplify[TransformedField["Cartesian" -> "Polar", %, {x, y} -> {r, θ}], r > 0 && -π < θ < π]The result is the same as directly computing Grad[f,{x1,…,xn},c]:
Grad[f[r, θ], {r, θ}, "Polar"]The gradient of an array equals the gradient of its components only in Cartesian coordinates:
Grad[{f[x, y], g[x, y]}, {x, y}, "Cartesian"] == Map[Grad[#, {x, y}, "Cartesian"]&, {f[x, y], g[x, y]}]Grad[{f[x, y], g[x, y]}, {x, y}, "Polar"] == Map[Grad[#, {x, y}, "Polar"]&, {f[x, y], g[x, y]}]//SimplifyIf chart is defined with metric g, expressed in the orthonormal basis, Grad[g,{x1,…,xn},chart] is zero:
Grad[IdentityMatrix[3], {r, θ, φ}, "Spherical"]Grad preserves the structure of SymmetrizedArray objects:
sa = SymmetrizedArray[{{1, 1, 1} -> x ^ 2, {1, 1, 2} -> y ^ 2, {2, 1, 2} -> x y}, {2, 2, 2}, Symmetric]The gradient has an additional dimension but the same symmetry as the input:
grad = Grad[sa, {x, y}]Interactive Examples (2)
The normal vectors to the level contours of a function equal the normalized gradient of the function:
f[x_, y_] := (x ^ 2/4) - 2x ^ 2y - 3x y + y ^ 4 / 16grad[x_, y_] := Grad[f[x, y], {x, y}]normal[x_, y_] = Simplify[(grad[x, y]/Sqrt[grad[x, y].grad[x, y]])]Create an interactive contour plot that displays the normal at a point:
Manipulate[ContourPlot[f[x, y], {x, -2, 2}, {y, -2, 2}, Epilog -> Arrow[{pt, pt + normal@@pt}], PerformanceGoal -> "Quality", Contours -> 20, PlotRange -> {{-2, 2}, {-2, 2}, {-30, 30}}, ImageSize -> Medium], {{pt, {.01, -0.1}}, Locator}, FrameLabel -> "Click a point to see its normal", SaveDefinitions -> True]View expressions for the gradient of a scalar function in different coordinate systems:
systems = {{"Cartesian", "Polar", "Bipolar", "PlanarParabolic"}, {"Cartesian", "Cylindrical", "Spherical", "CircularParabolic", "BipolarCylindrical"}, {"Cartesian", "Hyperspherical"}, {"Cartesian", "Hyperspherical"}};Manipulate[
If[Not@MemberQ[systems[[dimension - 1]], system], system = "Cartesian"];
DynamicModule[{varNames, vars},
varNames = CoordinateChartData[{system, dimension}, "StandardCoordinateNames"];
vars = ToExpression /@ varNames;
Inactive[Grad][f@@vars, vars] == Simplify@Grad[f@@vars, vars, system]],
{dimension, Range[2, 5]},
{{system, "Cartesian"}, systems[[dimension - 1]], ControlType -> SetterBar}, SaveDefinitions -> True]See Also
Div Curl Laplacian CoordinateChartData D DSolve NDSolve NDEigensystem NDEigenvalues NetPortGradient
Characters: \[Del]
Function Repository: DirectionalD
Tech Notes
Text
Wolfram Research (2012), Grad, Wolfram Language function, https://reference.wolfram.com/language/ref/Grad.html (updated 2024).
CMS
Wolfram Language. 2012. "Grad." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2024. https://reference.wolfram.com/language/ref/Grad.html.
APA
Wolfram Language. (2012). Grad. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Grad.html
BibTeX
@misc{reference.wolfram_2026_grad, author="Wolfram Research", title="{Grad}", year="2024", howpublished="\url{https://reference.wolfram.com/language/ref/Grad.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_grad, organization={Wolfram Research}, title={Grad}, year={2024}, url={https://reference.wolfram.com/language/ref/Grad.html}, note=[Accessed: 13-June-2026]}