D 
Details and Options
- D is also known as derivative for univariate functions.
- By using the character ∂, entered as
pd
or \[PartialD], with subscripts, derivatives can be entered as follows: -
D[f,x] ∂xf D[f,{x,n}] ∂{x,n}f D[f,x,y] ∂x,yf D[f,{{x,y}}] ∂{{x,y}}f - The comma can be made invisible by using the character \[InvisibleComma] or
,
. - The partial derivative D[f[x],x] is defined as
, and higher derivatives D[f[x,y],x,y] are defined recursively as
etc. - The order of derivatives n and m can be symbolic and they are assumed to be positive integers.
- The derivative D[f[x],{x,n}] for a symbolic f is represented as Derivative[n][f][x].
- For some functions f, Derivative[n][f][x] may not be known, but can be approximated by applying N. »
- New derivative rules can be added by adding values to Derivative[n][f][x]. »
- For lists, D[{f1,f2,…},x] is equivalent to {D[f1,x],D[f2,x],…} recursively. »
- D[f,{array}] effectively threads D over each element of array.
- D[f,{array,n}] is equivalent to D[f,{array},{array},…], where {array} is repeated n times.
- D[f,{array1},{array2},…] is normally equivalent to First[Outer[D,{f},array1,array2,…]]. »
- Common array derivatives include:
-
D[f,{{x1,x2,…}}] gradient {D[f,x1],D[f,x2],…} D[f,{{x1,x2,…},2}] Hessian {{D[f,x1,x1],D[f,x1,x2],…},{D[f,x2,x1],D[f,x2,x2],…},…} D[{f1,f2,…},{{x1,x2,…}}] Jacobian {{D[f1,x1],D[f1,x2],…},
{D[f2,x1],D[f2,x2],…},…} - If f is a scalar and x={x1,…}, then the multivariate Taylor series at x0={x01,…} is given by:
,- where fi=D[f,{x,i}]/.{x1x01,…} is an array with tensor rank
. » - If f and x are both arrays, then D[f,{x}] effectively threads first over each element of f, and then over each element of x. The result is an array with dimensions Join[Dimensions[f],Dimensions[x]]. »
- VectorSymbol, MatrixSymbol or ArraySymbol can be used to indicate that variables or function values are vectors, matrices or arrays.
- D can formally differentiate operators such as integrals and sums, taking into account scoped variables as well as the structure of the particular operator.
- Examples of operator derivatives include:
-

is not scoped by the integral

is scoped by the integral

is not scoped by the integral transform

is scoped by by the integral transform
- All expressions that do not explicitly depend on the variables given are taken to have zero partial derivative.
- The setting NonConstants{u1,…} specifies that ui depends on all variables x, y, etc. and does not have zero partial derivative. »
Examples
open all close allBasic Examples (7)
D[x ^ n, x]Fourth derivative with respect to x:
D[Sin[x] ^ 10, {x, 4}]Derivative of order n with respect to x:
D[Cos[x], {x, n}]Derivative with respect to x and y:
D[Sin[x y] / (x ^ 2 + y ^ 2), x, y]Derivative involving a symbolic function f:
D[x f[x]f'[x], x]Evaluate derivatives numerically:
N[Zeta'[2]]Enter ∂ using
pd
, and subscripts using
:
Subscript[∂, x, x]ArcTan[x]Scope (89)
Basic Uses (12)
Derivative of an expression with respect to x:
D[x ^ 2 Sin[a x], x]D[x ^ 2 Sin[a x], {x, 2}]Derivative of an expression at a point:
D[Sin[x] + Cos[2x], {x, 2}] /. x -> 0Derivative of a function at a general point x:
f[x_] := x ^ 5 + 6x ^ 3D[f[x], x]This can also be achieved using fluxion notation:
f'[x]D[f[x], x] /. x -> 5This can be found more easily using fluxion notation:
f'[5]The third derivative at the point x==-1:
D[f[x], {x, 3}] /. x -> -1f'''[-1]Derivative involving symbolic functions:
D[x f'[x] + g[x] ^ 2, x]Partial derivatives of an expression with respect to x and y:
D[x ^ 2 E ^ (5y), x]D[x ^ 2 E ^ (5y), y]The mixed partial derivative
:
D[x ^ 2 E ^ (5y), x, y]The mixed partial derivative
:
D[x ^ 2 E ^ (5y), {x, 2}, {y, 3}]Differentiate with respect to a compound expression:
D[Subscript[x, 1] ^ 2 + Sin[Subscript[x, 1]Subscript[x, 2]], Subscript[x, 1]]Differentiate with respect to different compound expressions:
D[Sin[f[x]] + f''[x], x]D[Sin[f[x]] + f''[x], f[x]]D[Sin[f[x]] + f''[x], f''[x]]Derivative of a vector expression:
D[{3t ^ 2, 4t, Sin[t]}, t]D[{{Cos[θ], -Sin[θ]}, {Sin[θ], Cos[θ]}}, θ]D[{x ^ n, {Exp[x], Log[x]}, {Sin[x], Cos[x], Tan[x]}}, x]Vector derivative of an expression, also known as the gradient:
D[x ^ 2 + 5y ^ 3, {{x, y}}]Second vector derivative, also known as the Hessian:
D[x ^ 2 + 5y ^ 3, {{x, y}, 2}]D[E ^ (-w)(x ^ 2 + 5y ^ 3 + z ^ 4), {{{x, y}, {z, w}}}]Create a table of basic derivatives:
makeDerivativeTable[funs_List, x_] := Grid[Prepend[Transpose[{funs, D[funs, x]}], {HoldForm[f[x]], HoldForm[f'[x]]}], IconizedObject[«Grid options»]]//TraditionalFormmakeDerivativeTable[{c, x, x ^ n, a ^ x, E ^ x, Log[a, x]}, x]Symbolic Functions (9)
Derivative of a symbolic function:
D[f[x]f'[x], x]Substitute in a pure function for f to get a particular result:
% /. f -> (Exp[# ^ 2]&)D[f[x] + g[x], x]D[f[x] g[x], x]Together[D[f[x] / g[x], x]]The chain rule for composite functions:
D[f[g[x]], x]Product rule for three functions:
D[f[x]g[x]h[x], x]State the rule using an Inactive derivative:
Inactivate[D[f[x] g[x]h[x], x], D] == D[f[x]g[x]h[x], x]Partial derivative of a symbolic function:
D[f[x, y], x, y]Substitute in for f a pure function in two variables:
% /. f -> (Exp[5#1]#2 ^ 3&)Derivative of a pure function with respect to non-argument parameters:
f = Sin[a#]&;df = D[f, a]The result is the function that at point x gives the derivative of
with respect to a:
df[x] == D[f[x], a]Local variables are independent from the differentiation variable:
f = Function[{x}, Sin[a x]];D[f, x]Derivative of a symbolic function at a point:
f[x_] := x g[x] - h[x]D[f[x], x] /. x -> 5The same, using prime notation:
f'[5]Derivative of an inverse function:
D[InverseFunction[f][x], x]Product rule for derivatives of order n:
D[f[x] g[x], {x, n}]% /. {n -> 1}//ActivateD[f[g[x]], {x, n}]% /. {n -> 1}//ActivateElementary Functions (6)
Polynomial and rational functions:
D[a x ^ 4 + b x ^ 3 + c, x]D[(x - 7) / (2x ^ 2 + 3x + 11), x]//TogetherD[Sqrt[1 + x ^ 3], x]D[(1 + x ^ (3 / 5)) ^ (1 / 2) / (3x + 1) ^ 5, x]//TogetherTrigonometric and inverse trigonometric functions:
D[Sin[x]Cos[x + y], x, y]D[ArcTan[x], x]D[Sec[x] / (1 + Tan[x]), x]//SimplifyD[Cos[3x + 5], {x, n}]Exponential and logarithmic functions:
D[(2x + 5)E ^ (x ^ 2), x]//TogetherD[Log[(x + 1) / (x - 5)], x]//TogetherD[x E ^ (x ^ x ^ x), x]//TogetherD[Sinh[x ^ 2], x]D[ArcCoth[x], {x, 2}]Create a function that turns a list of expressions into a nicely formatted table of derivatives:
makeDerivativeTable[funs_List, x_] := Grid[Prepend[Transpose[{funs, D[funs, x]}], {HoldForm[f[x]], HoldForm[f'[x]]}], IconizedObject[«Grid options»]]//TraditionalFormCreate a table of trigonometric derivatives:
makeDerivativeTable[{Sin[x], Cos[x], Tan[x], ArcSin[x], ArcCos[x], ArcTan[x]}, x]Create a table of hyperbolic derivatives:
makeDerivativeTable[{Sinh[z], Cosh[z], Tanh[z], ArcSinh[z], ArcCosh[z], ArcTanh[z]}, z]Special Functions (8)
The logarithmic derivative of Gamma is the PolyGamma function:
D[Log[Gamma[x]], x]Derivatives of Airy functions are given in terms of AiryAiPrime and AiryBiPrime:
D[AiryAi[x], {x, 7}]D[(x + 1)AiryBi[Sin[x]], x]The derivative of Zeta has a closed-form expression at the origin:
der = D[Zeta[x], x]der /. x -> 0Derivative[1][Zeta][0]Special functions with elementary derivatives:
D[EllipticF[x, m], x]D[Erf[x ^ 2], x]Special functions with derivatives expressed in terms of the same functions:
D[BesselJ[n, x], x]D[GegenbauerC[n, m, x], x]D[Hypergeometric2F1[a, b, c, x], x]Derivative of JacobiSN:
D[JacobiSN[x, m] ^ 2, x]Derivative of JacobiCD:
D[JacobiCD[x, m], x]Derivative of LogIntegral:
D[LogIntegral[x], x]Derivative of ExpIntegralEi:
D[ExpIntegralEi[x], x]Derivative of order n for SinIntegral:
D[SinIntegral[x], {x, n}]Create a table of special function derivatives:
makeDerivativeTable[funs_List, x_] := Grid[Prepend[Transpose[{funs, D[funs, x]}], {HoldForm[f[x]], HoldForm[f'[x]]}], IconizedObject[«Grid options»]]//TraditionalFormmakeDerivativeTable[{Gamma[a, z], PolyGamma[n, z], Erf[z], FresnelS[z], EllipticK[z], AiryAiPrime[z], ChebyshevT[n, z], GegenbauerC[n, m, z], HermiteH[n, z]}, z]Piecewise and Generalized Functions (8)
Derivative of a piecewise function:
D[Max[x, x ^ 2], x]Derivative of a ConditionalExpression:
D[ConditionalExpression[x^(1/(3)), x > 0], x]Convert a symbolic function into a piecewise function over the reals to differentiate it:
D[PiecewiseExpand[Abs[x], Reals], x]D[PiecewiseExpand[Abs[x ^ 2 + x], x∈Reals], x]Compute the piecewise derivative over a finite range:
D[PiecewiseExpand[SquareWave[x / 2], -2 < x < 2], x]Classical derivatives of pointwise-defined engineering functions:
D[UnitStep[x], x]D[x UnitStep[x], x]D[UnitBox[x], x]D[UnitTriangle[x], x]Distributional derivatives of generalized functions:
D[HeavisideTheta[x], x]D[x HeavisideTheta[x - 2], x]D[x HeavisidePi[x], x]D[HeavisideLambda[x], x]Derivative of RealAbs:
D[RealAbs[x], x]D[RealSign[x], x]Their counterparts on the complex plane are nowhere differentiable:
D[Abs[x], x]D[Sign[x], x]Derivative of Floor:
D[Floor[x], x]D[Ceiling[x], x]Derivatives of functions defined procedurally:
D[If[x > 0, Sqrt[x], -Sqrt[-x]], x]D[Which[x > 0, Sin[x], x < 0, Cos[x], x == 0, (1/2), True, Indeterminate], x]Implicitly Defined Functions (3)
D threads over Equal to compute the derivatives of implicit functions:
eqn = y[x] ^ 2 + 3y[x] == x ^ 2 + 1;Solve[D[eqn, x], y'[x]]Compute a partial derivative for an implicit function of two variables:
eqn = z[x, y] ^ 3 + 4z[x, y] == y Sin[x];Solve[D[eqn, y], D[z[x, y], y]]Find partials for implicit functions defined by a system of equations:
eqn = {z[x, y] ^ 3 + 4z[x, y], u[x, y]z[x, y]} == {y Sin[x], Cos[y]};Solve[D[eqn, y], {D[z[x, y], y], D[u[x, y], y]}]Vector-Valued Functions (5)
D[{Cos[x], Sin[x], Tan[x]}, x]D[{Cos[x], Sin[x], Tan[x]}, {x, 2}]The first derivative to a vector-valued function at a general value t:
c[t_] := {t, t^2, t^3}D[c[t], t]Computing the same using prime notation:
c'[t]D[c[t], {t, 3}] /. t -> 0Computing the same using prime notation:
c'''[0]m = MatrixExp[2{{1, 1}, {0, 1}}t]D[m, t]D[m, {t, 4}]The derivative of a vector-valued function stored as a SparseArray:
v = SparseArray[{1 -> f[t], 8 -> g[t]}, {10}]D[v, t]Convert the result to a normal array:
%//NormalThe derivative of matrix represented as a SymmetrizedArray object:
m = SymmetrizedArray[{{1, 1} -> f[t], {1, 2} -> g[t], {2, 2} -> h[t]}, {2, 2}, Symmetric[{1, 2}]]D[m, t]Convert the result to a normal matrix:
%//NormalVector Argument Functions (6)
Gradient of a scalar function:
vars = Array[Subscript[x, #]&, 5];
f = (#.#)&[Differences[vars]]D[f, {vars}]MatrixForm[D[f, {vars, 2}]]Jacobian of a vector-valued function:
vars = Array[Subscript[x, #]&, 5];
f = Drop[vars, 1] Differences[vars]MatrixForm[D[f, {vars}]]Second-order derivative tensor:
D[f, {vars, 2}]Compute the derivative of the determinant with respect to the original matrix:
D[Det[{{x, y}, {u, v}}], {{{x, y}, {u, v}}}]The gradient of a vector-valued function stored as a SparseArray:
v = SparseArray[{1 -> f[Subscript[x, 1], Subscript[x, 5], Subscript[x, 10]], 8 -> g[Subscript[x, 1], Subscript[x, 7], Subscript[x, 10]]}, {10}]The result is another SparseArray, containing only the nonzero entries:
D[v, {{Subscript[x, 1], Subscript[x, 2], Subscript[x, 3], Subscript[x, 4], Subscript[x, 5], Subscript[x, 6], Subscript[x, 7], Subscript[x, 8], Subscript[x, 9], Subscript[x, 10]}}]Convert the result to a normal matrix:
Normal[%]Hessian computed as a SparseArray:
vars = Array[Subscript[x, #]&, 1000];
f = (#.#)&[Differences[vars]];D[f, {SparseArray[vars], 2}]The gradient can also be computed as a SparseArray, but in this case it is effectively dense:
D[f, {SparseArray[vars]}]Jacobian computed as a SparseArray:
vars = Array[Subscript[x, #]&, 1000];
f = Drop[vars, 1] Differences[vars];D[f, {SparseArray[vars]}]Symbolic Array Arguments and Functions (8)
Derivative of a symbolic vector-valued function with respect to a scalar argument:
D[MatrixSymbol["a", {m, n}][x].VectorSymbol["v", n][x], x]Derivative of a symbolic matrix–valued function with respect to a scalar argument:
D[Inverse[MatrixSymbol["a", {n, n}][x]], x]Derivative of a symbolic array–valued function with respect to a scalar argument:
D[TensorProduct[MatrixSymbol["a", {m, n}][x], ArraySymbol["b", {p, q, r}][x]], x]Derivatives of scalar-valued functions with respect to symbolic vector arguments:
D[VectorSymbol["v", n].VectorSymbol["v", n], VectorSymbol["v", n]]Real symbolic vector argument:
D[Variance[VectorSymbol["v", n, Reals]], VectorSymbol["v", n, Reals]]Derivatives of scalar-valued functions with respect to symbolic matrix arguments:
D[Det[MatrixSymbol["a", {n, n}]], MatrixSymbol["a", {n, n}]]Real symbolic matrix argument:
D[Norm[MatrixSymbol["a", {n, n}, Reals], "Frobenius"], MatrixSymbol["a", {n, n}, Reals]]Derivative of a scalar-valued function with respect to a symbolic array argument:
D[ArrayDot[ArraySymbol["a", {p, q, r}], ArraySymbol["a", {p, q, r}], 3], ArraySymbol["a", {p, q, r}]]Derivatives of symbolic array–valued functions with respect to symbolic array arguments:
D[ArraySymbol["a", {p, q, r}], ArraySymbol["a", {p, q, r}]]D[LinearSolve[MatrixSymbol["a", {n, n}], VectorSymbol["v", n]], MatrixSymbol["a", {n, n}]]D[Total[ArraySymbol["a", {m, n, p, q, r}], 3], ArraySymbol["a", {m, n, p, q, r}]]Derivative of a composition of symbolic array functions:
D[ArraySymbol["f", {p, q, r}][MatrixSymbol["g", {m, n}][VectorSymbol["v", d]]], VectorSymbol["v", d]]Integrals and Integral Transforms (6)
Differentiate unevaluated integrals:
D[Integrate[f[x], x], x]D[Integrate[f[t], {t, 1, x}], x]D[Integrate[f[t, a], {t, 1, x}], a]D[FourierTransform[f[t], t, ω], ω]D[InverseFourierTransform[f[ω], ω, t], t]D[FourierCosTransform[f[t], t, ω], ω]D[InverseFourierSinTransform[f[ω], ω, t], t]D[LaplaceTransform[Gamma[t], t, s] s]D[LaplaceTransform[Gamma[t], t, s], t]D[InverseLaplaceTransform[Gamma[s], s, t], t]D[Convolve[f[x], g[x], x, y], y]D[MellinConvolve[f[x], g[x], x, y], y]Differentiate the Inactive form of an integral to get the fundamental theorem of calculus:
Inactivate[Integrate[f[t], {t, a, x}], Integrate]D[%, x]A more general form of the fundamental theorem:
D[Inactive[Integrate][f[x], {x, a[x], b[x]}], x]Differentiate an inactive FourierTransform:
ft = Inactive[FourierTransform][Exp[(-x^2/2)], x, k]D[ft, k]Activate[ft]D[%, k] == Activate[%%]Sums and Summation Transforms (4)
Differentiate an unevaluated sum:
Sum[Gamma[n x], {n, 1, k}]D[%, x]Differentiation with respect to the dummy variable gives zero:
D[Sum[Gamma[n x], {n, 1, k}], n]D[DiscreteConvolve[f[n], g[n], n, z], z]Differentiate the Inactive form of a sum:
Inactive[Sum][f[k, y], {k, a, b}]D[%, y]Inactive[ZTransform][f[k], k, z]D[%, z]Differentiate an inactive GeneratingFunction:
gf = Inactive[GeneratingFunction][E ^ (-n), n, z]D[gf, z]Activate[gf]D[%, z] == Activate[%%]//SimplifyIndexed Differentiation (9)
Differentiate with respect to an indexed variable, introducing KroneckerDelta factors:
D[Sum[f[x[i]], {i, 1, n}], x[j]]Use Inactive to prevent expansion of the sum:
D[Inactive[Sum][f[x[i]], {i, 0, 3}], x[2]]Activate[%]Summation indices will be renamed if needed, to avoid name ambiguities:
D[ArcTan[Sum[f[x[i], i], {i, 1, n}]], x[i]]Differentiate an inactive table with respect to an indexed variable:
D[Inactive[Table][x[i] ^ 2, {i, 3}], x[2]]Activate the result to get the explicit vector result:
Activate[%]Differentiate an inactive table twice with respect to an indexed variable:
D[Inactive[Table][Sin[α[i] ^ 2], {i, 10}], {α[j], 2}]In this case only the j
entry is nonzero:
Activate[% /. j -> 4]Use any notation for indexed variables in sums and tables:
D[Inactive[Sum][f[Indexed[x, {α}]]g[Indexed[x, {α}]], {α, 5}], Indexed[x, {γ}]]D[Inactive[Table][f[Subscript[x, α]]g[Subscript[x, α]], {α, 5}], Subscript[x, γ]]Differentiate with respect to a symbolic table of indexed variables:
D[Sin[x[1]] + Cos[x[3]], {Inactive[Table][x[i], {i, 3}]}]Activating the result gives the explicit gradient:
Activate[%]Differentiate twice with respect to a symbolic table of indexed variables, introducing a dummy index:
D[f[x[α]], {Inactive[Table][x[β], {β, n}], 2}]Replace symbolic variables with explicit values:
Activate[% /. {n -> 3, α -> 2}]Use symbolic vector differentiation of another symbolic vector:
vars = Inactive[Table][x[j], {j, 4}]D[Inactive[Table][f[x[i]], {i, n}], {vars}]Vector differentiation of a vector with respect to itself gives the identity matrix:
D[vars, {vars}]Activate[%]Functions Defined by Derivatives (5)
Define the derivative with prime notation:
f'[x_] := fp[x]This rule is used to evaluate the derivative:
D[f[x ^ 3], x]Define the derivative at a point:
f'[a] = f0D[f[x]^2, x] /. x -> ag''[x] = gpp[x]D[g[x] ^ 3 / 4, {x, 2}]Prescribe values and derivatives of f and g:
f'[5] = 1;g[3] = 5;g'[3] = 4;Find the derivative of the composition at x=3:
D[f[g[x]], x] /. x -> 3Define a partial derivative with Derivative:
Derivative[0, 2][f][u_, v_] := fnp[u, v]D[f[a, x ^ 2], {x, 2}]Options (1)
Applications (47)
Geometry of the Derivative (5)
The derivative gives the slope of the tangent line at a point:
f[x_] := Sin[3x]tangent[h_] := f[Pi] + h f'[Pi]For small displacements h from the base point π, the tangent line gives an excellent approximate of f:
TableForm[Table[{h, tangent[h], f[Pi + h]}, {h, 0.01`4, 0.02`4, .0025`4}], TableHeadings -> {{}, {h, HoldForm@tangent[h], HoldForm@f[π + h]}}]The tangent and f are visually indistinguishable from each other over a small, and only a small, plot range:
Row[{Plot[{f[x], tangent[x - Pi]}, {x, Pi - 1, Pi + 1}], Plot[{f[x], tangent[x - Pi]}, {x, Pi - 0.01, Pi + 0.01}]}]The derivative gives the limit of the slope of the secant line connecting {x,f[x]} to {x+h,f[x+h]}:
f[x_] := x ^ 3 + 2x + 2f'[x] == Limit[(f[x + h] - f[x]/h), h -> 0]Visualize the process for the point {1,f[1]}:
dropdowns[h_] := Line[{{1, f[1]}, {1 + h, f[1]}, {1 + h, f[1 + h]}}]
points[h_] := {PointSize[Large], Point[{1, f[1]}], Point[{1 + h, f[1 + h]}]}
labels[h_] := {Text[Style["TraditionalForm(1, f(1))", 16], {1, f[1]}, {1, -1.5}], Text[Style["TraditionalForm(1 + h, f(1 + h))", 16], {1 + h, f[1 + h]}, {-1.1, 1}]}
title[h_] := StringForm["Derivative[1][f](1) == `1`, (f(1 + h) - f(1)/(1 + h) - 1) == `2`", ToBoxes[f'[1]], ToBoxes[(f[1 + h] - f[1]) / h]]Manipulate[Plot[{f[x], f[1] + (x - 1)(f[1 + h] - f[1]/h)}, {x, 0, 3}, PlotRange -> {{0, 3}, {0, 20}}, ImageSize -> Medium, LabelStyle -> Larger, Epilog -> {dropdowns[h], points[h], labels[h]}, PlotLabel -> title[h]], {{h, 1}, 0.000001, 1, Appearance -> "Labeled"}, SaveDefinitions -> True]Find an equation for the tangent line to a function:
f[x_] := x ^ 3 + 3x ^ 2 + 5x - 13General equation for the tangent line at x=a:
tangent[a_][x_] := f'[a](x - a) + f[a]tangent[4][x]//SimplifyPlot[{f[x], tangent[4][x]}, {x, 0, 8}, Epilog -> {StandardOrange, PointSize[Large], Point[{4, f[4]}]}]Find an equation for the normal line to a function:
f[x_] := +x ^ 2 - 3.5x + 2General equation for the normal line at x=a:
normal[a_][x_] := (a - x) / f'[a] + f[a]normal[1][x]//SimplifyPlot[{f[x], normal[1][x]}, {x, -1, 4}, AspectRatio -> 1, PlotRange -> {-3, 2}, Epilog -> {StandardOrange, PointSize[Large], Point[{1, f[1]}]}]Find equations for the tangent lines to a function that pass through a point:
f[x_] := x ^ 2 + 5General equation for the tangent line at x=a:
tangent[a_][x_] := f'[a](x - a) + f[a]Find the tangents to f[x] that pass through (0,-4):
sol = Solve[tangent[a][0] == -4, a]Plot[{f[x], tangent[a /. sol][x]}, {x, -6, 6}, PlotStyle -> {StandardBlue, {StandardOrange}}, PlotRange -> {-20, 40}, Epilog -> {StandardOrange, PointSize[Large], Point[{{-3, 14}, {3, 14}}]}]Characterization of Functions (5)
Find the turning points on a plane curve:
f[x_] := x ^ 3 + 3x ^ 2 - 3x - 1Plot[f[x], {x, -4, 2}]Solve[D[f[x], x] == 0, x]Find the critical points of a function:
f[x_] := Piecewise[{{2Sin[x] ^ 2Cos[x], -Pi ≤ x ≤ Pi}}, Undefined]sol = Solve[D[f[x], x] == 0, x]By the second derivative test, these are all maxima or minima:
FullSimplify[f''[x] /. sol]Visualize the critical points:
Plot[f[x], {x, -Pi, Pi}, Epilog -> {PointSize[Large], Point[{x, f[x]} /. sol]}]Find all values of c that satisfy the Mean Value theorem on an interval:
f[x_] := x ^ 3 - 3x{a, b} = {-2, 2};sol = Solve[(f[b] - f[a]/b - a) == f'[c] && a < c < b, c]Define the secant line from a to b:
secant[x_] := (f[b] - f[a])(x - a) / (b - a) + f[a]Define the tangent lines associated with the two values of c:
{tangent1[x_], tangent2[x_]} = (f[c] + f'[c](x - c)) /. sol;Visualize the two tangent lines parallel to the secant line along with the original function:
Plot[{f[x], secant[x], tangent1[x], tangent2[x]}, {x, -2.5, 2.5}, PlotLegends -> "Expressions", Epilog -> {StandardOrange, PointSize[Large], Point[{{a, f[a]}, {b, f[b]}}], StandardBlue, Point[{c, f[c]} /. sol]}]Use the first derivative to characterize a function:
f[x_] := x ^ 2 / (x - 1)Find the critical points of a function:
sol = Solve[D[f[x], x] == 0, x]Find where the function is increasing:
fi = Reduce[D[f[x], x] > 0]Find where the function is decreasing:
fd = Reduce[D[f[x], x] < 0]Plot[{Piecewise[{{f[x], fi}}, Undefined], Piecewise[{{f[x], fd}}, Undefined]}, {x, -3, 5}, Epilog -> {PointSize[Large], Point[{x, f[x]} /. sol]}, PlotLegends -> LineLegend[{"Increasing", "Decreasing"}]]Use the second derivative to characterize a function:
f[x_] := (x - 1) / (x ^ 2 + 1)Find the inflection points of a function:
sol = Solve[D[f[x], {x, 2}] == 0, x]Find where the function has positive concavity:
cp = Reduce[D[f[x], {x, 2}] > 0]Find where the function has negative concavity:
cn = Reduce[D[f[x], {x, 2}] < 0]Plot[{Piecewise[{{f[x], cp}}, Undefined], Piecewise[{{f[x], cn}}, Undefined]}, {x, -3, 6}, Epilog -> {PointSize[Large], Point[{x, f[x]} /. sol]}, PlotLegends -> LineLegend[{"Concave Up", "Concave Down"}]]Relation to Integration (2)
Perform the change of variable t=x^2 in an integral:
Integrate[x Exp[x ^ 2], {x, 0, 2}]Integrate[t ^ (1 / 2) Exp[t] D[t ^ (1 / 2), t], {t, 0, 4}]Verify the results of symbolic integration:
int = Integrate[x / (x ^ 2 + 1) ^ 3, x]D[int, x]Multivariate and Vector Calculus (6)
Find the critical points of a function of two variables:
f[x_, y_] := x ^ 4 + y ^ 4 - 20x ^ 2 - 10x y - 25sol = NSolve[D[f[x, y], {{x, y}}] == {0, 0}, {x, y}, Reals]Compute the signs of
and the determinant of the second partial derivatives:
Sign@D[f[x, y], {x, 2}] /. solSign@Det[D[f[x, y], {{x, y}, 2}]] /. solBy 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 curvature of a circular helix with radius r and pitch c:
Helix[r_, c_, t_] := {r Cos[t], r Sin[t], c t}ParametricPlot3D[Helix[1, 1 / 11, t], {t, 0, 30}, Boxed -> False, Axes -> False]Curvature[expr_, t_] := Norm[Cross[D[expr, t], D[expr, {t, 2}]]] / Norm[D[expr, t]] ^ 3FullSimplify[Curvature[Helix[r, c, t], t], 0 < t < Pi / 2 && r > 0 && c > 0]Obtain the same result using ArcCurvature:
FullSimplify[ArcCurvature[Helix[r, c, t], t], 0 < t < Pi / 2 && r > 0 && c > 0]Compute a univariate Taylor series by hand:
{f0, f1, f2, f3} = Table[D[E^x, {x, i}] /. x -> 0, {i, 0, 3}];
(f0(x - 0)^0/0!) + (f1(x - 0)/1!) + (f2 (x - 0)^2/2!) + (f3(x - 0)^3/3!)Compute a multivariate Taylor series by hand:
𝕏 = {x, y, z};
𝕏0 = {0, 0, 0};
{f0, f1, f2} = Table[D[E^x - y + z, {𝕏, i}] /. {x -> 0, y -> 0, z -> 0}, {i, 0, 2}];
(f0/0!) + (f1.(𝕏 - 𝕏0)/1!) + (f2.(𝕏 - 𝕏0).(𝕏 - 𝕏0)/2!)//ExpandWrite a function to automate the process:
multTaylorSeries[f_, x_, x0_, n_] := Underoverscript[∑, i = 0, n]((D[f, {x, i}] /. Thread[x -> x0]).Sequence@@Table[x - x0, i]/i!)Recompute the above using the new function:
multTaylorSeries[E ^ x, {x}, {0}, 3]//ExpandmultTaylorSeries[E ^ (x - y + z), {x, y, z}, {0, 0, 0}, 2]//ExpandThe gradient vector can be computed by finding the partial derivatives of a function:
Grad[f[x, y], {x, y}] == {D[f[x, y], x], D[f[x, y], y]}Find the gradient vector of the function
:
f[x_, y_] := x ^ 2 / 4 - 3x ^ 2y - 2x y + y ^ 4 / 4grad[x_, y_] = {D[f[x, y], x], D[f[x, y], y]}Visualize the direction of the gradient vector using a unit vector representation:
unitGrad[x_, y_] := grad[x, y] / Sqrt[grad[x, y].grad[x, y]]Manipulate[ContourPlot[f[x, y], {x, -2, 2}, {y, -2, 2}, Epilog -> Arrow[{p, p + unitGrad@@p}], PerformanceGoal -> "Quality", Contours -> 20, PlotRange -> {{-2, 2}, {-2, 2}, {-30, 30}}, ImageSize -> Medium], {{p, {.01, -0.1}}, Locator}, SaveDefinitions -> True]The curl of a vector field on the plane can be computed by subtracting the derivatives of its components:
Curl[{f[x, y], g[x, y]}, {x, y}] == D[g[x, y], x] - D[f[x, y], y]Find the curl of the vector field
:
v[x_, y_] := {x ^ 2y, x + y}curl[{x_, y_}] = D[x + y, x] - D[x ^ 2y, y]Visualize the 2D curl as the net "rotation" of the vector field at a point, with red and green representing clockwise and counterclockwise curl, respectively, and radius proportional to the magnitude of rotation:
Manipulate[VectorPlot[v[x, y], {x, -2, 2}, {y, -2, 2}, ImageSize -> Medium, Epilog -> {If[curl[s] > 0, Green, Red], Thick, Dashed, Point[s], Circle[s, Abs[curl[s] / 3]]}], {{s, {0, 0}}, {-2, -2}, {2, 2}}, SaveDefinitions -> True]The divergence of a vector field can be computed by summing the derivatives of its components:
Div[{f[x, y], g[x, y]}, {x, y}] == D[f[x, y], x] + D[g[x, y], y]Find the divergence of a 2D vector field:
v[x_, y_] := {x ^ 2, x ^ 3 - y ^ 2 / 2}div[{x_, y_}] = D[x ^ 2, x] + D[x ^ 3 - y ^ 2 / 2, y]Visualize 2D divergence as the net "flow" of the vector field at a point, with red and green representing outflow and inflow, respectively, and radius proportional to the magnitude of the flow:
Manipulate[Show[VectorPlot[v[x, y], {x, 0, 4}, {y, 0, 4}, ImageSize -> Medium], Graphics[{If[div[s] > 0, Green, Red], Thick, Point[s], Circle[s, Abs[div[s] / 10]]}]], {{s, {2, 2}}, {0, 0}, {4, 4}}, SaveDefinitions -> True]Differential Equations (6)
Construct the differential equation satisfied by an implicit function y[x]:
eqn = E ^ (1 - x + 1 / y[x]) / (-1 + x) + Subscript[, 1] + ExpIntegralEi[1 - x + 1 / y[x]] == 0;y'[x] == Apart[(y'[x] /. Solve[D[eqn, x], y'[x]][[1]])]Use D to specify ordinary and partial differential equations:
ode = D[y[x], x] - Sqrt[(y[x] / x)] == y[x] / x;pde = x D[g[x, y], y] + y D[g[x, y], x] == -3x y g[x, y]These can be solved using DSolve:
DSolve[ode, y, x]DSolve[{pde, g[x, 0] == E ^ (-x ^ 2)}, g, {x, y}]Define a wave equation in two spatial variables:
weqn = D[u[x, y, t], {t, 2}] == Laplacian[u[x, y, t], {x, y}];Define initial values for the function and its first time derivative:
ic = {u[x, y, 0] == (1 / 10)(x - x ^ 2)(2y - y ^ 2), D[u[x, y, t], t] == 0 /. t -> 0};bc = {u[x, 0, t] == 0, u[0, y, t] == 0, u[1, y, t] == 0, u[x, 2, t] == 0};Solve the system using DSolve:
(sol = FullSimplify[u[x, y, t] /. DSolve[{weqn, ic, bc}, u, {x, y, t}][[1]], K[1]∈PositiveIntegers && K[3]∈PositiveIntegers])//TraditionalFormExtract a few terms from the Inactive sum:
h[x_, y_, t_] = sol /. {∞ -> 3}//ActivateThe two-dimensional wave executes periodic motion in the vertical direction:
Animate[Plot3D[h[x, y, t], {x, 0, 1}, {y, 0, 2}, Ticks -> None, PlotRange -> {-1 / 36, 1 / 36}, MeshStyle -> Red, PerformanceGoal -> "Quality"], {t, 0, 8}, SaveDefinitions -> True, DefaultDuration -> 12]Specify a Laplacian operator using D:
ℒ = D[u[x, y], {x, 2}] + D[u[x, y], {y, 2}];Specify homogeneous Dirichlet boundary conditions:
ℬ = DirichletCondition[u[x, y] == 0, True];Find the 4 smallest eigenvalues and eigenfunctions of the operator in a unit disk:
{vals, funs} = DEigensystem[{ℒ, ℬ}, u[x, y], {x, y}∈Disk[], 4];vals//TraditionalFormContourPlot[#, {x, y}∈Disk[]]& /@ N[funs]Specify an integro-differential equation using D:
eqn = D[y[x], x] == 1 + Sin[a x] - Subsuperscript[∫, 0, x]y[t]ⅆt;sol1 = DSolve[eqn, y[x], x]Specify an initial condition to obtain a particular solution:
sol2 = DSolve[{eqn, y[0] == -1}, y[x], x]Plot the solutions for different values of a:
Plot[Evaluate[Table[y[x] /. sol2[[1]], {a, -3, 3, 0.9}]], {x, 0, 5}]Find a second-degree polynomial solution to the differential equation:
f[x_] := a x ^ 2 + b x + csol = Solve[ForAll[x, Exists[f[x], D[f[x], {x, 2}] + D[f[x], x] - 2f[x] == x ^ 2]], {a, b, c}, Reals]f[x] /. sol[[1]]Rates of Change (5)
The height of a projectile at time t is given by:
h[t_] := 25t - 4.905t ^ 2v[t_] = D[h[t], t]Compute the acceleration at t:
a[t_] = D[h[t], {t, 2}]Find when the projectile reaches its maximum height:
sol = Solve[v[t] == 0, t]Find the maximum height of the projectile:
h[t] /. sol[[1]]Plot[{h[t], v[t], a[t]}, {t, 0, 5.1}, PlotLegends -> "Expressions"]The area of a circle as a function of time is given by:
a[t_] := π r[t] ^ 2Compute the rate of change of area:
roc = a'[t]Find the rate of change of area at a radius of 10 m if the radius increases at a rate of 5m/s:
roc /. {r'[t] -> Quantity[5, "Meters" / "Seconds"], r[t] -> Quantity[10, "Meters"]}The position of a particle is given by:
x[t_] := t ^ 5 - 11t + Sin[3t] / 12Compute the velocity, acceleration, jerk, snap (jounce), crackle and pop of the particle:
{velocity, acceleration, jerk, snap, crackle, pop} = Table[D[x[t], {t, i}], {i, 6}];Plot[Evaluate[{x[t], velocity, acceleration, jerk, snap, crackle, pop}], {t, 0, 3}, Exclusions -> None, PlotLegends -> {"position", "velocity", "acceleration", "jerk", "snap", "crackle", "pop"}, PlotRange -> All]The total resistance in a circuit of two resistors connected in parallel is given by:
eqn = 1 / r[t] == 1 / r1[t] + 1 / r2[t]Calculate RT for the given values of R1 and R2:
rT = Solve[eqn /. {r1[t] -> 25, r2[t] -> 10}, r[t]]Find the rate of change of the total resistance:
roc = Solve[D[eqn, t], r'[t]]Calculate the rate of change of the total resistance with the given values:
roc /. {r1[t] -> 25, r1'[t] -> 5, r2[t] -> 10, r2'[t] -> -5} /. First[rT]Volume of a cube in terms of side length l is given by:
v[l_] := l ^ 3Surface area of a cube is given by:
sa[l_] := 6l ^ 2Compute the rate of change of the volume of a cube with respect to surface area using the chain rule:
D[v[l], l] / D[sa[l], l]Solve for l in terms of surface area and substitute that into the result:
% /. Last[Solve[sa == sa[l], l]]Implicit Functions (3)
Find an equation for the tangent line to an implicit function at (1,
):
{x0, y[x0]} = {1, Sqrt[2]};sol = Solve[D[2y[x] ^ 2 == 5x ^ 4 - x ^ 2, x], y'[x]]slope = y'[x] /. sol /. x -> x0tangent[x_] = slope (x - x0) + y[x0]Show[Plot[tangent[x], {x, -3, 3}, PlotStyle -> Red, PlotRange -> {-10, 10}], ContourPlot[2y ^ 2 == 5x ^ 4 - x ^ 2, {x, -3, 3}, {y, -15, 15}], Graphics[{PointSize[Large], Red, Point[{x0, y[x0]}]}]]Find the points where the slope of an implicit function equals
:
eqn = x ^ 2y[x] ^ 2 + x y[x] == 2sol = Solve[D[eqn, x], y'[x]]Solve[{(y'[x] /. sol[[1]]) == -1, eqn}, {x, y[x]}, Reals]The relationship between functions is given by:
eqn = x[t] ^ 3 + y[t] ^ 2 - 1 / z[t] == 10dz = Solve[D[eqn, t], z'[t]]Calculate z'[t] with the given values:
dz /. {x[t] -> 4, x'[t] -> -2, y[t] -> 7, y'[t] -> 13, z[t] -> 1}Optimization (3)
Find the maximum area of a rectangular fence of 2000 ft., bordered on one side by a barn:
a[l_, w_] := l wp[l_, w_] := 2l + wCompute the area in terms of width:
sol = Solve[p[l, w] == 2000, l]area = a[l, w] /. First[sol]max = Solve[D[area, w] == 0, w]a[l, w] /. First[sol] /. First[max]By the second derivative test, this value is a true maximum:
D[area, {w, 2}] /. First[max]Alternately, compute the area in terms of length:
sol = Solve[p[l, w] == 2000, w]max = Solve[D[a[l, w] /. First[sol], l] == 0, l]a[l, w] /. First[sol] /. First[max]Visualize how the area changes as the length changes:
Manipulate[Column[{Show[Plot[Piecewise[{{l, -w / 2 ≤ x ≤ w / 2}}, Undefined] /. w -> 2000 - 2l, {x, -1000, 1000}, PlotStyle -> Red, PlotRange -> {{-1100, 1100}, {0, 1000}}, ImageSize -> 240], Graphics[{Red, Line[{{-w / 2, 0}, {-w / 2, l}}] /. w -> 2000 - 2l, Line[{{w / 2, 0}, {w / 2, l}}] /. w -> 2000 - 2l}]], Row[{"Length = ", NumberForm[l, {4, 0}], " ft."}],
Row[{"Width = ", NumberForm[2000 - 2l, {4, 0}], " ft."}],
Row[{"Area = ", NumberForm[2000l - 2l^2, {6, 0}], " ft."}]}, Alignment -> Center], {{l, 500, "Length"}, 0, 1000, Appearance -> "Labeled"}, SaveDefinitions -> True]Find the shortest distance from a curve to the point (1,5):
eqn = y ^ 2 == 2xd[x_, y_] := Sqrt[(x - 1) ^ 2 + (y - 5) ^ 2]Compute the distance in terms of y:
sol = Solve[eqn, x]dis = d[x, y] /. First[sol]minpoint = Solve[{eqn, D[dis, y] == 0}, {x, y}, Reals]By the second derivative test, this is a minimum:
D[dis, {y, 2}] /. First[minpoint]//NVisualize how the distance changes with position:
Manipulate[Column[{ParametricPlot[{t ^ 2 / 2, t}, {t, -3.5, 3.5}, PlotStyle -> Red, ImageSize -> Small, PlotRange -> {{-1, 6.5}, {-4, 6}}, Epilog -> {PointSize[Large], Point[{1, 5}], Line[{{t ^ 2 / 2, t}, {1, 5}}], Red, Point[{t ^ 2 / 2, t}], Gray, Point[{x, y}] /. First[minpoint]}], {x, y} == NumberForm[N[{t ^ 2 / 2, t}], {3, 2}], "Distance" == NumberForm[N[Sqrt[(t ^ 2 / 2 - 1) ^ 2 + (t - 5) ^ 2]], {4, 2}]}, Alignment -> Center], {{t, 0, y}, -3.5, 3.5, ImageSize -> Small}, SaveDefinitions -> True]//TraditionalFormFind the dimensions of a lidless, cylindrical can with the least material that can hold up to 2 L of water:
sa[r_, h_] := Pi r(r + 2h)v[r_, h_] := Pi r ^ 2hCompute the height in terms of the radius, using the volume constraint:
hr = Solve[v[r, h] == 2000, h]Compute the surface area in terms of the radius:
sa[r_] = sa[r, h] /. First[hr]The radius corresponding to the minimum surface area:
min = Solve[D[sa[r], r] == 0, r, Reals]//NBy the second derivative test, this is a minimum:
D[sa[r], {r, 2}] /. First[min]Compute the radius, height and surface area of the minimum configuration:
{r, h /. First[hr], sa[r]} /. First[min]Visualize how the dimensions vary with radius:
Manipulate[Column[{Show[ParametricPlot3D[{r Cos[s], r Sin[s], h}, {s, 0, 2Pi}, {h, 0, 2000 / (Pi r ^ 2)}, PlotRange -> {{-12, 12}, {-12, 12}, {0, 50}}, Mesh -> None, ImageSize -> Small], ParametricPlot3D[{r t Cos[s], r t Sin[s], 0}, {s, 0, 2Pi}, {t, 0, 1}, Mesh -> None]], "Radius" == NumberForm[N[r], {5, 2}], "Height" == NumberForm[N[2000 / Pi / r ^ 2], {5, 2}], "Surface Area" == NumberForm[N[Pi r(r + 4000 / (Pi r ^ 2))], {5, 2}]}, Alignment -> Center], {{r, 4, "Radius"}, 3.5, 12, Appearance -> "Labeled", ImageSize -> Small}]//TraditionalFormL'Hôpital's Rule (3)
Find the limit of the ratio of two functions as x0:
f[x_] := Sin[4x]g[x_] := Sin[2x]Directly solving the limit leads to an indeterminate form of type
:
Limit[f[x], x -> 0] == Limit[g[x], x -> 0] == 0L'Hôpital's rule can be used because in an interval around
, both
and
are defined, and
:
Resolve[Subscript[∀, x, (-1/10) < x < (1/10)](-∞ < f'[x] < ∞ && g'[x] > 0)]Indeed,
and
are continuous, and
, so
can be computed trivially:
f'[0] / g'[0]Verify the result using Limit:
Limit[(f[x]/g[x]), x -> 0]Visualize the two functions and their ratio:
Plot[{f[x], g[x], f[x] / g[x]}, {x, -1 / 3, 1 / 3}, PlotLabels -> Automatic]Find the limit of the ratio of two functions as x∞:
f[x_] := x + x ^ 2g[x_] := 5x ^ 2 - 4x - 5Directly solving the limit leads to an indeterminate form of type
:
Limit[f[x], x -> ∞] == Limit[g[x], x -> ∞] == ∞L'Hôpital's rule can be used because for all
, both
and
are defined, and
:
Resolve[Subscript[∀, x, 10 < x](-∞ < f'[x] < ∞ && g'[x] > 0)]However, using the first derivatives also leads to an indeterminate form:
Limit[f'[x], x -> ∞] == Limit[g'[x], x -> ∞] == ∞The second derivatives are constant and obviously satisfy the conditions of L'Hôpital's rule:
{f''[x], g''[x]}Hence
can be computed trivially:
(f''[x]/g''[x])Verify the result using Limit:
Limit[f[x] / g[x], x -> ∞] == Limit[f'[x] / g'[x], x -> ∞] == (1/5)Find the limit of the product of two functions as x0:
f[x_] := x ^ 2g[x_] := 2Coth[x^2]Directly solving the limit leads to an indeterminate form of type 0×∞:
Limit[f[x], x -> 0] == 0Limit[g[x], x -> 0] == ∞g'[0]However,
exists and is positive for all
, and it also exists and is negative for all
:
Resolve[Subscript[∀, x, x < 0]g'[x] > 0 && Subscript[∀, x, x > 0]g'[x] < 0]As
is clearly defined for all real
, L'Hôpital's rule can be applied in the form:
Limit[f[x]g[x], x -> 0] == Limit[f'[x] / (-g'[x] / g[x] ^ 2), x -> 0]The quotient in the right-hand limit gives a continuous expression whose limit is simple to compute:
f'[x] / (-g'[x] / g[x] ^ 2)% /. x -> 0% == Limit[%%, x -> 0]Symbolic Array Calculus (6)
Approximate the variance for a perturbed vector:
u = RandomInteger[{-10 ^ 6, 10 ^ 6}, {7}] / 10 ^ 6;
eps = RandomInteger[{-10 ^ 6, 10 ^ 6}, {7}] / 10 ^ 16;t0 = Variance[u];N[Variance[u + eps] - t0, 20]v = VectorSymbol["v", 7, Reals];
d1 = D[Variance[v], v]t1 = t0 + (d1 /. v -> u).eps;N[Variance[u + eps] - t1, 20]d2 = D[d1, v]t2 = t1 + 1 / 2Normal[d2].eps.eps;Since the second derivative does not depend on
, the order two approximation equals the exact value:
Variance[u + eps] - t2Approximate the determinant of a perturbed matrix:
a = RandomInteger[{-10 ^ 6, 10 ^ 6}, {7, 7}] / 10 ^ 6;
eps = RandomInteger[{-10 ^ 6, 10 ^ 6}, {7, 7}] / 10 ^ 16;t0 = Det[a];N[Det[a + eps] - t0, 20]m = MatrixSymbol["m", {7, 7}];
d1 = D[Det[m], m]t1 = t0 + ArrayDot[d1 /. m -> a, eps, 2];N[Det[a + eps] - t1, 20]d2 = D[d1, m]t2 = t1 + 1 / 2ArrayDot[ArrayDot[Normal[d2 /. m -> a], eps, 2], eps, 2];N[Det[a + eps] - t2, 20]Derive a least-squares solution for data
given as a list of pairs
:
m = MatrixSymbol["m", {n, 2}]Find the vector of vertical deviations
for the data:
dev = m.{-a, 1} - bDefine the sum of squares of the vertical deviations for the data:
squareDeviations = dev.devSet up the least-squares equations:
eqna = D[squareDeviations, a] == 0eqnb = D[squareDeviations, b] == 0n = 200;data = Table[{x, 3x + 20 + RandomReal[{-15, 15}]}, {x, 1, n}];Solve the least-squares problem for this data:
a x + b /. Solve[Normal[{eqna, eqnb}] /. m -> data, {a, b}][[1]]Show[{ListPlot[data], Plot[%, {x, 0, 200}, PlotStyle -> Red]}]Find GammaDistribution parameters that best fit the given data using the maximum likelihood method:
SeedRandom[1234];data = RandomVariate[GammaDistribution[1, 2], 1000];f = Refine[PDF[GammaDistribution[α, β]][x], x > 0]Maximize the log-likelihood function
:
v = VectorSymbol["v", 1000];l = Total[Log[f /. x -> v]]dl = D[l, {{α, β}}]Find a zero of the gradient, with
replaced by
:
eqns = Thread[Expand[Normal[dl /. v -> data]] == 0]NSolve[eqns, {α, β}, MaxRoots -> 1]Show[{Histogram[data, Automatic, "PDF"], Plot[PDF[GammaDistribution[α, β] /. %[[1]]][x], {x, 0, 9}]}]Compare with the result computed using EstimatedDistribution:
EstimatedDistribution[data, GammaDistribution[α, β]]Find an optimality condition for a portfolio optimization problem with the expected return
and standard deviation
:
x = VectorSymbol["x", n];
μ = VectorSymbol["μ", n];
Σ = MatrixSymbol["Σ", {n, n}];
Subscript[μ, p] = μ.x;
Subscript[σ, p] = Sqrt[x.Σ.x];The goal is to maximize
when the vector
of asset weights satisfies Total[x]=1. The constraint can be used to represent
where the unconstrained vector variable
consists of the first
coordinates of
:
A = MatrixSymbol["A", {n, n - 1}];
y = VectorSymbol["y", n - 1];
b = UnitVector[n, n];The maximum occurs at a critical point of
:
cond = D[Subscript[μ, p] / Subscript[σ, p] /. x -> A.y + b, y] == 0Express the condition in terms of
:
cond /. A.y + b -> xCompute the gradient of the log-likelihood function of the linear regression model represented by the equation
, where
are normally distributed random variables with mean zero and variance
:
y = VectorSymbol["y", n];
X = MatrixSymbol["X", {n, k}];
β = VectorSymbol["β", k];
u = VectorSymbol["u", n];The log-likelihood function
is given by:
l = -n / 2Log[σsquared] - 1 / (2σsquared)u.uSubscript[l, β] = D[l /. u -> y - X.β, β]Express the result in terms of
:
Subscript[l, β] /. y - X.β -> uSubscript[l, σ^2] = D[l, σsquared]Other Applications (3)
Compute the coefficients of a power series:
Table[D[Exp[x ^ 3] Sin[x], {x, n}] / n!, {n, 0, 8}] /. {x -> 0}Series[Exp[x ^ 3]Sin[x], {x, 0, 8}]Derive a closed form for
by differentiating
with respect to
at
:
D[Inactive[Integrate][E ^ (a x), x], a]lhs = % /. a -> 1Now integrate
first and then differentiate with respect to
at
:
Integrate[E ^ (a x), x]D[%, a]rhs = % /. a -> 1//FullSimplifylhs == rhsActivate[%]Derive a closed form for
by differentiating
w.r.t.
at
:
D[Inactive[Sum][Exp[a k^2], {k, -∞, ∞}], a]lhs = % /. a -> -1Compute
and then differentiate:
Sum[Exp[a k^2], {k, -∞, ∞}]D[%, a]rhs = % /. a -> -1lhs == rhsActivate[%]Properties & Relations (23)
The derivative of a function is defined as a limit:
f[x_] := x ^ 2D[f[x], x] == Limit[(f[x + h] - f[x]) / h, h -> 0]The Limit of DifferenceQuotient is the derivative D:
DifferenceQuotient[Sin[x], {x, h}]Limit[%, h -> 0] == D[Sin[x], x]D is the inverse of Integrate:
D[Integrate[f[x], x], x]D[Integrate[f[t], {t, 0, x}], x]Integrate[D[f[x], x], x]The fundamental theorem of calculus:
D[Integrate[f[t], {t, 0, x}], x]Differentiation inside of Integrate:
D[Integrate[f[a, t], t], a]D returns formal results in terms of Derivative:
D[f[x], x]InputForm[%]D[f[x, y], x]InputForm[%]D differentiates expressions with respect to a given variable:
D[Sin[x], x]Derivative is an operator and returns pure-function results:
Derivative[1][Sin]The derivative of a function at a point may not be available in closed form:
Zeta'[3]An approximation to the derivative can be obtained using N:
N[%]D[f,{array1},…] is essentially equivalent to First[Outer[D,{f},array1,…]]:
u = {x, y};
v = {w, z};
D[f[x, y, w, z], {u}, {v}] == First[Outer[D, {f[x, y, w, z]}, u, v]]If f and a are arrays, Dimensions[D[f,{a}]]==Join[Dimensions[f],Dimensions[a]]:
f = {{s[x, y, z], t[x, y, z]}, {u[x, y, z], v[x, y, z]}};
a = {x, y, z};
Dimensions[D[f, {a}]]% == Join[Dimensions[f], Dimensions[a]]D[f,{{x1,x2,…,xn}}] is effectively equivalent to Grad[f,{x1,x2,…,xn}]:
D[x y Sin[z], {{x, y, z}}] == Grad[x y Sin[z], {x, y, z}]D[{x y, y z , z x}, {{x, y, z}}] == Grad[{x y, y z , z x}, {x, y, z}]Div[{f1,f2,…,fn},{x1,x2,…,xn}] is the trace of the vector derivative of f:
Div[{x ^ 2y, z x y, z ^ 3}, {x, y, z}] == Tr[D[{x ^ 2y, z x y, z ^ 3}, {{x, y, z}}]]More generally, Div[f,x] is the contraction of the last two dimensions of the vector derivative of f:
F = Array[Subscript[f, ##][x, y, z]&, {3, 3}]r = TensorRank[F]Subscript[∇, {x, y, z}].F == TensorContract[D[F, {{x, y, z}}], {{r, r + 1}}]Curl[f,x] is
times the HodgeDual of the vector derivative of f, where r is the rank of f:
f = {x ^ 2y, z x y, z ^ 3};r = TensorRank[f]Curl[f, {x, y, z}] == (-1)^r(r + 1)HodgeDual[D[f, {{x, y, z}}]]For scalar f, Laplacian[f,{x1,x2,…,xn}] is the trace of the second vector derivative of f:
Laplacian[Sin[x y]Exp[z], {x, y, z}] == Tr[D[Sin[x y]Exp[z], {{x, y, z}, 2}]]More generally, Laplacian[f,x] is the contraction of the last two dimensions of the second vector derivative of f:
F = Array[Subscript[f, ##][x, y, z]&, {3, 3}]r = TensorRank[F]Subsuperscript[∇, {x, y, z}, 2]F == TensorContract[D[F, {{x, y, z}, 2}], {{r + 1, r + 2}}]Compute the derivative of Total[a] with respect to a using symbolic arrays:
sA = ArraySymbol["A", {m, n, p}]sDTotalA = D[Total[sA], sA]Compare with the results obtained using indexed differentiation:
iA = Inactive[Table][Indexed[A, {i, j, k}], {i, m}, {j, n}, {k, p}]iTotalA = Inactive[Table][Inactive[Sum][Indexed[A, {i, j, k}], {i, m}], {j, n}, {k, p}]iDTotalA = D[iTotalA, {iA}]Block[{m = 2, n = 3, p = 4}, Activate[iDTotalA] === Normal[sDTotalA]]ArcCurvature can be defined in terms of D:
f[t_] := tg[t_] := t ^ 2Simplify[ArcCurvature[{f[t], g[t]}, t] == (-Derivative[1][g][t]Derivative[2][f][t] + Derivative[1][f][t]Derivative[2][g][t]/(Derivative[1][f][t]^2 + Derivative[1][g][t]^2)^3 / 2), t > 0]Systems of differential equations involving D can be solved with DSolve:
DSolve[{D[f[x], {x, 2}] == 15x ^ 3 - 13x ^ 2 + 5x, f[0] == 8, f[1] == 6}, f[x], x]Use D to specify a heat equation with homogeneous Dirichlet boundary conditions:
{ℒ, ℬ} = {D[u[t, x], t] == D[u[t, x], {x, 2}], DirichletCondition[u[t, x] == 0, True]};The eigensystem for this differential system can be found with DEigensystem:
{vals, funs} = DEigensystem[{ℒ, ℬ}, u[t, x], t, {x, 0, Pi}, 4];valsfunsD can be defined using DifferenceDelta:
(DifferenceDelta[Cosh[x], {x, 1, h}]/h)Limit[%, h -> 0] == D[Cosh[x], x]D can be defined using DiscreteShift:
(DiscreteShift[Log[x], {x, h}] - Log[x]/h)Limit[%, h -> 0] == D[Log[x], x]The right one-sided derivative is computed with a right-hand limit:
Limit[(Abs[h + 0] - Abs[0]) / h, h -> 0, Direction -> -1]The left one-sided derivative is computed with a left-hand limit:
Limit[(Abs[h + 0] - Abs[0]) / h, h -> 0, Direction -> 1]Note that this function is not differentiable at x==0:
D[PiecewiseExpand[Abs[x], x∈Reals], x] /. x -> 0D assumes that other variables are independent of the differentiation variable:
expr = a x ^ 2 + b x + c;D[expr, x]Dt assumes that other variables may depend on the differentiation variable:
Dt[expr, x]By manually specifying all other variables as constant, Dt can yield the same result as D:
Dt[expr, x, Constants -> {a, b, c}] == D[expr, x]Compute the derivative of an implicit function using D and Solve:
eqn = y[x] ^ 2 + 3y[x] == x ^ 2 + 1;Solve[D[eqn, x], y'[x]]Use ImplicitD to compute the derivative of an implicit function:
ImplicitD[y ^ 2 + 3y == x ^ 2 + 1, y, x]Possible Issues (5)
Results may not immediately be given in the simplest possible form:
D[Sin[x] ^ 10, {x, 4}]FullSimplify[%]Functions given in different forms can yield the same derivatives:
Simplify[D[ArcTan[x], x]]Simplify[D[-ArcTan[1 / x], x]]D returns generic results that may not account for discontinuities, cusps or other special points:
f[x_] := 1 / x
g[x_] := 10Surd[x ^ 2, 3]D[{f[x], g[x]}, x]Neither f nor g is differentiable at 0:
{f'[0], g'[0]}f is discontinuous, and g has a cusp:
Plot[{f[x], g[x]}, {x, -1, 1}, PlotLegends -> "Expressions", PlotRange -> 10]If a function can be expanded into a Piecewise expression, D will provide more accurate results:
D[PiecewiseExpand[g[x], x∈Reals], x]Cached values for D may miss changes in underlying definitions:
f'[x_] := Sin[x];
D[f[x], {x, 2}]f'[x_] := Exp[x];
D[f[x], {x, 2}]The issue can be resolved by clearing the system cache:
ClearSystemCache["Symbolic"]D[f[x], {x, 2}]The variable of differentiation is treated literally:
D[Sin[x] ^ 2, Sin[x]]The following mathematically equivalent input gives 0 because there is no Sin[x] in the first argument:
D[1 - Cos[x] ^ 2, Sin[x]]Interactive Examples (2)
Find the tangent line to a function:
f[x_] := x ^ 5 - 6x ^ 3 + xg[a_] := f[a] + f'[a](x - a)Manipulate[Show[Plot[{f[x], g[a]}, {x, -3, 3}, PlotRange -> 20], Graphics[{PointSize[Large], StandardOrange, Point[{a, f[a]}]}]], {{a, -0.5}, -3, 3, Appearance -> "Labeled"}, SaveDefinitions -> True]Visualize the secant converging to the tangent as
for different base points
:
f[x_] := x ^ 3 + 2x^2 + 2dropdowns[b_, h_] := Line[{{b, f[b]}, {b + h, f[b]}, {b + h, f[b + h]}}]points[b_, h_] := {PointSize[Large], Point[{b, f[b]}], Point[{b + h, f[b + h]}]}Manipulate[Plot[{f[x], f[b] + (f[b + h] - f[b]/h)(x - b), f[b] + f'[b](x - b)}, {x, -.5, 2.5}, PlotRange -> {0, 30}, ImageSize -> Medium, LabelStyle -> Larger, Epilog -> {dropdowns[b, h], points[b, h]}], {{h, 1}, 0.000001, 1, Appearance -> "Labeled"}, {{b, .5}, 0, 1.25, Appearance -> "Labeled"}, SaveDefinitions -> True]Neat Examples (2)
Compute the tangent and normal vectors of a 3D parametric function:
curve = KnotData[{"TorusKnot", {3, 5}}, "SpaceCurve"];tangent[t_] := curve'[t] / Sqrt[curve'[t].curve'[t]]
normal[t_] := tangent'[t] / Sqrt[tangent'[t].tangent'[t]]Animate[Show[ParametricPlot3D[curve[u], {u, 0, 2Pi}, PlotRange -> 3, ImageSize -> Medium], Graphics3D[{Thick, Sphere[{curve[t]}, 0.1], StandardBlue, Arrow[{curve[t], tangent[t] + curve[t]}], StandardRed, Arrow[{curve[t], normal[t] + curve[t]}]}]], {t, 0, 2Pi}, SaveDefinitions -> True, DefaultDuration -> 10]Create a table of n
derivatives:
flist = {E ^ ( x), x ^ 2, Log[x], Sin[x], ArcTan[x], Cosh[x], ArcCosh[x], ChebyshevT[n, x], EllipticE[x], BesselJ[0, x]};Grid[Join[{{f[x], Inactive[D][f[x], {x, n}]}}, Transpose[{flist, (Subscript[∂, {x, n}]#1&) /@ flist}]], IconizedObject[«Grid options»]]//TraditionalFormSee Also
Dt Derivative DifferenceQuotient Minimize Maximize DSolve NDSolve NDEigensystem NDEigenvalues Integrate Grad Div Curl Laplacian DifferenceDelta CoefficientArrays FractionalD CaputoD ImplicitD
Function Repository: NDerivative FractionalD ListD JacobianMatrix ChainD ProductD FiniteDifferenceStencil
Related Links
History
Introduced in 1988 (1.0) | Updated in 1996 (3.0) ▪ 2004 (5.1) ▪ 2008 (7.0) ▪ 2017 (11.1) ▪ 2024 (14.1)
Text
Wolfram Research (1988), D, Wolfram Language function, https://reference.wolfram.com/language/ref/D.html (updated 2024).
CMS
Wolfram Language. 1988. "D." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2024. https://reference.wolfram.com/language/ref/D.html.
APA
Wolfram Language. (1988). D. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/D.html
BibTeX
@misc{reference.wolfram_2026_d, author="Wolfram Research", title="{D}", year="2024", howpublished="\url{https://reference.wolfram.com/language/ref/D.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_d, organization={Wolfram Research}, title={D}, year={2024}, url={https://reference.wolfram.com/language/ref/D.html}, note=[Accessed: 12-June-2026]}