Directional Derivative and the Gradient Vector
Author: Joseph Lo

y_0 = %v

x_0 = %v

θ

Trace along a chosen direction

Normal Vector at (x0, y0)

Tangent plane at (x0, y0)

fx

∇f

show θ

u

u

∇f

Angle

> 0.5π

< 0.5π

D_u f > 0

D_u f < 0

D_u f = 0

Angle between ∇f and u = 0.5π

b = 16
a = 4 (slider from -5 to 5, step 1)
y0 = -2.5 (slider from -2.5 to -2.5, step 0.1)
x0 = -1.7 (slider from -2.5 to 2.5, step 0.1)
tanDirSize = 1
angle = 0 (slider from 0 to 2, step 0.025)
theta: (angle * π)
Psin: sin(theta)
f(x, y) = (a * ℯ^(((-x^(2))) / b - (2 * y^(2) / b)))
Pcos: cos(theta)
fy = Derivative(f(x, y), y)
fx = Derivative(f(x, y), x)
Point: (x0, y0)
xP: x(Point)
yP: y(Point)
fP: f(xP, yP)
fyP: fy(xP, yP)
fxP: fx(xP, yP)
fsP: (Pcos * fxP) + (Psin * fyP)
tanPlaneSize = 1
tracecheck = false
PointSurface: (xP, yP, fP)
dy: tanPlaneSize / sqrt(1 + fyP^(2))
dx: tanPlaneSize / sqrt(1 + fxP^(2))
P4: (xP + dx, yP + dy, fP + (fxP * dx) + (fyP * dy))
P5: (xP - dx, yP + dy, fP - (fxP * dx) + (fyP * dy))
P6: (xP - dx, yP - dy, fP - (fxP * dx) - (fyP * dy))
P7: (xP + dx, yP - dy, fP + (fxP * dx) - (fyP * dy))
TanPlane = Surface(xP + s, yP + t, fP + (s * fxP) + (t * fyP), s, (-dx), dx, t, (-dy), dy)
Plane = Surface((s * Pcos) + xP, (s * Psin) + yP, t, s, -3, 3, t, -2, 2)
tanDirLenNorm: tanDirSize / sqrt(1 + fxP^(2) + fyP^(2))
tanDirLenx: tanDirSize / sqrt(1 + fxP^(2))
tanDirLeny: tanDirSize / sqrt(1 + fyP^(2))
tanDirLen: tanDirSize / sqrt(1 + fsP^(2))
tanArrow = Vector((xP, yP, fP), (xP + (tanDirLen * Pcos), yP + (tanDirLen * Psin), fP + (tanDirLen * fsP)))
tanNorm = Vector((xP, yP, fP), (xP - (tanDirLenNorm * fxP), yP - (tanDirLenNorm * fyP), fP + tanDirLenNorm))
tangent = Line((xP, yP, fP), tanArrow)
normalcheck = false
tanplanecheck = false
Arrow = Vector((xP, yP), (xP + (tanDirSize * Pcos), yP + (tanDirSize * Psin)))
B = Point(Arrow)
m = Segment((xP, yP), (xP + tanDirSize, yP))
tracey = CurveCartesian(xP, t, f(xP, t), t, -1.5, 1.5)
text1: "At point (" + x0 + ", " + y0 + ")"
text2: "Direction of the trace:
θ = " + angle + "π"
text6: "Tangent plane at (" + x0 + ", " + y0 + ")"
text5: "Normal vector at (" + x0 + ", " + y0 + ")"
line = Line((xP, yP), Arrow)
Ponplane: (xP, yP, 0)
e = Segment(PointSurface, Ponplane)
r0: sqrt(x0^(2) + (2 * y0^(2)))
levelcurve = CurveCartesian((r0 * cos(t)), (r0 * sin(t) / sqrt(2)), t, 0, 6.283185307179586)
Surface = Surface(s, t, f(s, t), s, -6, 6, t, -6, 6)
Arrowgrad = Vector((xP, yP), (xP + fxP, yP + fyP))
levelcurvesurf = CurveCartesian((r0 * cos(t)), (r0 * sin(t) / sqrt(2)), (a * ℯ^(((-r0^(2))) / b)), t, 0, 6.28319)
poly1, c, d, g, h = Polygon((-20, 3), (20, 3), (20, 20), (-20, 20))
levelcurves = Sequence(CurveCartesian[(sqrt(((-b) * log(i / 2 / a))) * cos(t)), (sqrt(((-b) * log(i / 2 / a))) * sin(t) / sqrt(2)), t, 0, 6.28319], i, 1, 8)
levelcurvexy = CurveCartesian((r0 * cos(t)), (r0 * sin(t) / sqrt(2)), 0, t, 0, 6.28319)
Arrowgradxy = Vector((xP, yP, 0), (xP + fxP, yP + fyP, 0))
D: (xP + fxP, yP + fyP, 0.2)
C: ((0.8 * cos(theta / 2)) + xP, (0.8 * sin(theta / 2)) + yP)
Arrowu = Vector((xP, yP, 0), (xP + (tanDirSize * Pcos), yP + (tanDirSize * Psin), 0))
A: (xP + 1, yP)
α = Angle(A, Point, B)
text4: "u = < cos(" + angle + "π), sin(" + angle + "π) >"
anglelabel = false
E: (xP + (tanDirSize * Pcos), yP + (tanDirSize * Psin), 0.2)
F: (xP + ((1.25 * tanDirSize) * Pcos), yP + ((1.25 * tanDirSize) * Psin))
gradfP: sqrt(fxP^(2) + fyP^(2))
G: (xP + fxP + (0.25 / gradfP * fxP), yP + fyP + (0.25 / gradfP * fyP))
ugradfanglecheck = false
ugradfangle: acos(((Pcos * fxP) + (Psin * fyP)) / gradfP) / π
β = Angle(F, Point, G)
text11: "Angle between ∇f and u ≈ " + ugradfangle + "π"
trace = CurveCartesian((t * Pcos) + xP, (t * Psin) + yP, f((t * Pcos) + xP, (t * Psin) + yP), t, -9, 9)
H: (x0 - fyP / gradfP, y0 + fxP / gradfP)
j: line(Point)
i = Segment(Point, H)
k = Segment(Point, G)
γ = Angle(H, Point, G)
leveltangent = Line(Point, H)