Skip to content
DeepForgeby svx
All problems
MediumCalculusca-253

Directional Derivative in 3D

Problem

The directional derivative of a differentiable function f at a point in the direction v is the gradient dotted with the unit vector v / ||v||.

Given the gradient components as the list g and the direction as the list v with ||v|| > 0, return that scalar.

Hint

The direction must be normalized before taking the dot product with the gradient.

Test cases

case 1
in: [[1,2,3],[1,0,0]]
expected: 1
case 2
in: [[1,1,1],[1,1,1]]
expected: 1.7320508075688774
case 3
in: [[2,0,-1],[0,0,5]]
expected: -1
case 4
in: [[1,2,2],[2,-1,2]]
expected: 1.3333333333333333
Starter codePython
def directional_derivative_3d(g, v):
    # Your code here
    pass

4 test cases · run your code against them in the editor