Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Oppiskele The Gradient Vector | Section
Understanding Multivariate Calculus
Osio 1. Luku 4
single

single

bookThe Gradient Vector

Pyyhkäise näyttääksesi valikon

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
Tehtävä

Pyyhkäise aloittaaksesi koodauksen

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).

Ratkaisu

Switch to desktopVaihda työpöytään todellista harjoitusta vartenJatka siitä, missä olet käyttämällä jotakin alla olevista vaihtoehdoista
Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 1. Luku 4
single

single

Kysy tekoälyä

expand

Kysy tekoälyä

ChatGPT

Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme

some-alt