Directional Derivatives
Desliza para mostrar el menú
The directional derivative of a function describes how the function changes as you move from a point in a specific direction. For a function f(x, y), the directional derivative at a point (x_0, y_0) in the direction of a unit vector u = (a, b) is given by:
D_uf(x_0, y_0) = ∇f(x_0, y_0) · u = f_x(x_0, y_0)a + f_y(x_0, y_0)b
Here, ∇f(x_0, y_0) is the gradient vector at (x_0, y_0), f_x and f_y are the partial derivatives, and · denotes the dot product.
Example:
Suppose f(x, y) = x^2 + y^2 and you want the directional derivative at (1, 2) in the direction of vector v = (3, 4). First, normalize v to get the unit vector u = (3/5, 4/5). The gradient at (1, 2) is (2x, 2y) = (2, 4). The directional derivative is:
D_uf(1, 2) = (2, 4) · (3/5, 4/5) = 2*(3/5) + 4*(4/5) = (6/5) + (16/5) = 22/5
This value tells you how fast the function increases if you move from (1, 2) in the direction (3, 4).
1234567891011121314151617181920212223242526import numpy as np def gradient(f, x, h=1e-6): n = len(x) grad = np.zeros(n) for i in range(n): x_forward = np.array(x) x_backward = np.array(x) x_forward[i] += h x_backward[i] -= h grad[i] = (f(*x_forward) - f(*x_backward)) / (2 * h) return grad def directional_derivative(f, x0, direction): direction = np.array(direction) unit_direction = direction / np.linalg.norm(direction) grad = gradient(f, x0) return np.dot(grad, unit_direction) # Example usage: # f(x, y) = x^2 + y^2 f = lambda x, y: x**2 + y**2 point = [1, 2] direction = [3, 4] result = directional_derivative(f, point, direction) print(f"Directional derivative at {point} in direction {direction}: {result:.2f}")
¡Gracias por tus comentarios!
Pregunte a AI
Pregunte a AI
Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla