Method on @sym: gradient (f)
Method on @sym: gradient (f, x)

Symbolic gradient of symbolic expression.

The gradient of scalar expression is the vector

syms f(x, y, z)
gradient(f)
  ⇒ (sym 3×1 matrix)
      ⎡∂             ⎤
      ⎢──(f(x, y, z))⎥
      ⎢∂x            ⎥
      ⎢              ⎥
      ⎢∂             ⎥
      ⎢──(f(x, y, z))⎥
      ⎢∂y            ⎥
      ⎢              ⎥
      ⎢∂             ⎥
      ⎢──(f(x, y, z))⎥
      ⎣∂z            ⎦

Example:

f = x^3 + 5*y^2;
gradient(f)
  ⇒ (sym 2×1 matrix)
      ⎡   2⎤
      ⎢3⋅x ⎥
      ⎢    ⎥
      ⎣10⋅y⎦

x can be a scalar, vector or cell list. If omitted, it is determined using symvar. Example:

gradient(f, {x y z})
  ⇒ (sym 3×1 matrix)
      ⎡   2⎤
      ⎢3⋅x ⎥
      ⎢    ⎥
      ⎢10⋅y⎥
      ⎢    ⎥
      ⎣ 0  ⎦

Note: assumes x is a Cartesian coordinate system.

See also: @sym/divergence, @sym/curl, @sym/laplacian, @sym/jacobian, @sym/hessian.

Package: symbolic