Method on @sym: divergence (F)
Method on @sym: divergence (F, x)

Symbolic divergence of symbolic expression.

Consider a vector expression F:

syms f_1(x,y,z) f_2(x,y,z) f_3(x,y,z)
F = [f_1; f_2; f_3]
  ⇒ F = (sym 3×1 matrix)
      ⎡f₁(x, y, z)⎤
      ⎢           ⎥
      ⎢f₂(x, y, z)⎥
      ⎢           ⎥
      ⎣f₃(x, y, z)⎦

The divergence of F is the scalar expression:

divergence(F)
  ⇒ (sym)
      ∂                 ∂                 ∂
      ──(f₁(x, y, z)) + ──(f₂(x, y, z)) + ──(f₃(x, y, z))
      ∂x                ∂y                ∂z

Examples:

syms x y
F = [x^2/2  y^2/2];
divergence(F)
  ⇒ (sym) x + y

syms z
F = [y x x*y];
divergence(F, [x; y; z])
  ⇒ (sym) 0

Note: assumes x is a Cartesian coordinate system.

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

Package: symbolic