# Directional derivative of function at specific point

If I've a function (in this case also differentiable):

x^3/3 - x*y^2 - x/8 + y^2


how can I find quickly the directional derivative of the function in (1,1) with respect to the unit vector v(sqrt(3)/2, 1/2). Finding the gradient, and run the dot product. But what if the function had not been differentiable?

• Here is an example of such sort: {D[Sqrt[RealAbs[x^2 - x*y]], x], D[Sqrt[RealAbs[x^2 - x*y]], y]} /. {x -> 0, y -> 0} produces {Indeterminate, Indeterminate} and D[Sqrt[RealAbs[x^2 - x*y]] /. {x -> t, y -> sqrt[2]*t}, t] /. t -> 0 performs Indeterminate too. Commented Sep 2, 2020 at 18:25
• There's a ResourceFunction: DirectionalD Commented Sep 2, 2020 at 19:36
• @user64494, sorry but I do not understand... how can use this instruction to find the directional derivate?
– Teo7
Commented Sep 2, 2020 at 20:17
• Try it:(Grad[x^3/3 - x*y^2 - x/8 + y^2, {x, y}] /. {x -> 1, y -> 1}).Normalize[{Sqrt[3]/2, 1/2}]. Commented Sep 3, 2020 at 0:57

Here is an example, where a function of two variables

f[x_,y_]:=Sqrt[RealAbs[x^2 - x*y]]


is not differentiable at the origin, but its directional derivative at the origin for many directions exists.

We consider the restriction of the function f[x,y] on the ray from the origin along a vector {a,b}, preserving the scale by

g[t] := f[x, y] /. {x -> a/Norm[{a, b}]*t, y -> b/Norm[{a, b}]*t}


assuming t>=0. Now

D[g[t],t]
(*(((2 a^2 t)/(Abs[a]^2 + Abs[b]^2) - (2 a b t)/(   Abs[a]^2 + Abs[b]^2)) ((a^2 t^2)/
(Abs[a]^2 + Abs[b]^2) - (a b t^2)/(Abs[a]^2 + Abs[b]^2)))/(2 RealAbs[(a^2 t^2)/
( Abs[a]^2 + Abs[b]^2) - (a b t^2)/(Abs[a]^2 + Abs[b]^2)]^(3/2))*)


and

Limit[%, t -> 0, Direction -> "FromAbove"] // Simplify


$$\begin{cases} \sqrt{-\frac{a (a-b)}{a^2+b^2}} & a\neq 0\land a^20\land (a\geq b\lor a\leq 0)) \\ \text{Indeterminate} & \text{True} \\ \end{cases}$$ It should be noticed that

ResourceFunction["DirectionalD"][Sqrt[RealAbs[x^2 - x*y]], {a, b}, {x, y}]
(*-((b x (x^2 - x y))/(2 RealAbs[x^2 - x y]^(3/2))) +(a (2 x - y) (x^2 - x y))/(2 RealAbs[x^2 - x y]^(3/2))*)


, but

Limit[%, {x, y} -> {0, 0}]
(*Indeterminate*)

• The command Limit[ResourceFunction["DirectionalD"][Sqrt[RealAbs[x^2 - x*y]], Normalize[{a, b}], {x, y}] /. y -> b/a*x, x -> 0, Direction -> "FromAbove"] results in $$\begin{array}{cc} \{ & \begin{array}{cc} \frac{\sqrt{-\frac{a}{a-b}} (b-a)}{\sqrt{a^2+b^2}} & (a>0\land a<b\land b>0)\lor (a<0\land a>b\land b<0) \\ \frac{a \sqrt{1-\frac{b}{a}}}{\sqrt{a^2+b^2}} & (b\leq 0\land a>0)\lor (b\geq 0\land a<0)\lor (b>0\land a\geq b)\lor (b<0\land a\leq b) \\ \text{Indeterminate} & \text{True} \\ \end{array} \\ \end{array}$$ Commented Sep 3, 2020 at 7:53

Use the definition of the directional derivative: Let f,z,v be vectors and t a scalar, the directional derivative of f[z] along v is

Limit[(f[z + t v]-f[z])/t,t->0]


For the above example with f[x,y]=Sqrt[RealsAbs[x^2-x y]]

Limit[((f[x, y] /. {Thread[{x, y} -> {x, y} + t {1, 1/2}]}) -
f[x, y])/t, t -> 0, Direction -> "FromAbove"]

• Unfortunately. Limit[((f[x, y] /. {Thread[{x, y} -> {x, y} + t {1, 1/2}]}) - f[x, y])/t, t -> 0, Direction -> "FromAbove"] /. {x -> 0, y -> 0} performs Indeterminate. Also up to the common definition, the vector {1, 1/2} should be normalized. Commented Sep 3, 2020 at 11:15
• Compare the results of f[x_, y_] := x*y; Limit[((f[x, y] /. {Thread[{x, y} -> {x, y} + t {1, 1/2}]}) - f[x, y])/t, t -> 0, Direction -> "FromAbove"] which performs {1/2 (x + 2 y)} and Limit[((f[x, y] /. {Thread[{x, y} -> {x, y} + t {2, 1}]}) - f[x, y])/ t, t -> 0, Direction -> "FromAbove"] which results in {x + 2 y} though the directions are identical. Commented Sep 3, 2020 at 11:40
• If you interpret the directional derivative as velocity of change of f[] if you pass {x,y} with the velocity v, then it is clear that the larger Abs[v], the larger the derivative. Commented Sep 3, 2020 at 16:55
• Is this your personal point of view? Can you give an available reference to that interpretation? Wiki (see en.wikipedia.org/wiki/Directional_derivative) says nothing about such interpretation. Commented Sep 3, 2020 at 18:22
• There are two different notions: the directional derivative and the derivative along a vector. Commented Sep 4, 2020 at 10:11