Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære The Gradient Vector | Section
Understanding Multivariate Calculus
Seksjon 1. Kapittel 4
single

single

bookThe Gradient Vector

Sveip for å vise menyen

The gradient vector is a fundamental concept in multivariate calculus, representing the direction and rate of the steepest ascent of a scalar-valued function of several variables. If you have a function f(x,y,...,n)f(x, y, ..., n), the gradient of ff at any point is a vector composed of the partial derivatives of ff with respect to each variable. Mathematically, for a function f(x,y)f(x, y), the gradient is defined as:

f(x,y)=[fx,fy]∇f(x, y) = \left[\frac{∂f}{∂x}, \frac{∂f}{∂y}\right]

where fx\frac{\raisebox{1pt}{$∂f$}}{\raisebox{-1pt}{$∂x$}} and fy\frac{\raisebox{1pt}{$∂f$}}{\raisebox{-1pt}{$∂y$}} are the partial derivatives of ff with respect to xx and yy, respectively. The gradient vector always points in the direction where the function increases most rapidly, and its length tells you how fast the function increases in that direction.

Some important properties of the gradient vector include:

  • The gradient is perpendicular (normal) to the level curves (contours) of the function;
  • If the gradient at a point is zero, that point is a critical point (which could be a maximum, minimum, or saddle point);
  • The gradient can be generalized to functions of more than two variables by including all partial derivatives as components of the vector.

To compute the gradient, you simply calculate all the first-order partial derivatives with respect to each variable at the point of interest.

1234567891011121314151617181920212223242526272829
import numpy as np import matplotlib.pyplot as plt # Define the sample function def f(x, y): return x**2 + y**2 # Compute the gradient of f def grad_f(x, y): df_dx = 2 * x df_dy = 2 * y return np.array([df_dx, df_dy]) # Create a grid of points x = np.linspace(-2, 2, 20) y = np.linspace(-2, 2, 20) X, Y = np.meshgrid(x, y) # Compute gradient at each point U = 2 * X V = 2 * Y plt.figure(figsize=(6, 6)) plt.quiver(X, Y, U, V, color="blue", angles='xy') plt.title("Gradient Vector Field for f(x, y) = x² + y²") plt.xlabel("x") plt.ylabel("y") plt.grid(True) plt.show()
copy
Oppgave

Sveip for å begynne å kode

Calculate the gradient vector of the function $f(x, y) = x^3 + y^2$ at a given point using the sympy library in the global scope.

  • Define the symbols x and y utilizing sympy.symbols().
  • Define the mathematical expression f=x3+y2f = x^3 + y^2.
  • Compute the partial derivative of ff with respect to x and y utilizing sympy.diff().
  • Evaluate both derivatives at the coordinates provided by the val_x and val_y variables utilizing the .subs() method.
  • Assign the evaluated results to the variables grad_x and grad_y as floats.
  • Print the result as a tuple (grad_x, grad_y).

Løsning

Switch to desktopBytt til skrivebordet for virkelighetspraksisFortsett der du er med et av alternativene nedenfor
Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 1. Kapittel 4
single

single

Spør AI

expand

Spør AI

ChatGPT

Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår

some-alt