Method on @sym: children (f)

Return "children" (terms, lhs/rhs, etc) of symbolic expression.

For a scalar expression, return a row vector of sym expressions:

syms x y
f = 2*x*y + sin(x);
C = children(f)
  ⇒ C = (sym) [2⋅x⋅y  sin(x)]  (1×2 matrix)

children(C(1))
  ⇒ ans = (sym) [2  x  y]  (1×3 matrix)
children(C(2))
  ⇒ ans = (sym) x

A symbol/number/boolean has itself as children:

children(x)
  ⇒ ans = (sym) x

For matrices/vectors, return a cell array where each entry is a row vector. The cell array is the same shape as the input.

A = [x*y 2; 3 x]
  ⇒ A = (sym 2×2 matrix)
      ⎡x⋅y  2⎤
      ⎢      ⎥
      ⎣ 3   x⎦

C = children (A)
  ⇒ C = { ... }

class (C), size (C)
  ⇒ ans = cell
  ⇒ ans =
       2   2

C{:}
  ⇒ ans = (sym) [x  y]  (1×2 matrix)
  ⇒ ans = (sym) 3
  ⇒ ans = (sym) 2
  ⇒ ans = (sym) x

For sets, children can be used to extract an matrix (array) containing the set elements, see ‘finiteset’. This is useful for accessing the elements of a set.

See also: @sym/lhs, @sym/rhs, @sym/eq, @sym/lt, finiteset.

Package: symbolic