如何计算梯度

计算标量函数的梯度(∇f),即各变量的偏导数组成的向量。流程:对每个自变量求偏导,组合为向量,并在指定点处求值。示例:f(x,y)=x^2 y + 3y → ∇f=(2xy, x^2+3),在 (1,2) 处为 (4,4)。

如何计算梯度

是什么:标量函数的梯度是由该函数对每个变量的偏导数组成的向量,指示函数增长最快的方向。用法:输入多元标量函数,计算各偏导,组成梯度向量并在某点求值。适用场景:优化、方向导数、物理场分析。

Steps

  1. Take the partial derivative of the function with respect to each variable: $partial f/partial x_i$.
  2. Assemble these partial derivatives into the gradient vector: $ abla f = (partial f/partial x_1, partial f/partial x_2, ...)$.
  3. Evaluate the gradient at the desired point by substituting coordinates.

Example

f(x,y) = x^2 y + 3y
∂f/∂x = 2xy
∂f/∂y = x^2 + 3
∇f = (2xy, x^2 + 3)
At (1,2): ∇f = (4,4)

Use this approach for scalar fields in physics, optimization, and directional derivative calculations.