Skip to content
DeepForgeby svx
All problems
EasyCalculusca-015

Directional Derivative

Problem

Compute the directional derivative of a scalar field at a point given its gradient and a direction vector.

Normalize the direction and take the dot product: D = (grad · direction) / ||direction||.

If the direction vector is the zero vector, return 0.0.

Hint

The direction must be a unit vector before dotting it with the gradient.

Test cases

case 1
in: [[2,4,6],[1,0,0]]
expected: 2
case 2
in: [[1,1],[3,4]]
expected: 1.4
case 3
in: [[0,0],[1,1]]
expected: 0
case 4
in: [[2,-3],[0,-2]]
expected: 3
case 5
in: [[1,2],[0,0]]
expected: 0
Starter codePython
def directional_derivative(grad, direction):
    # Your code here
    pass

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