Method on @symfun: symvar (f)
Method on @symfun: symvar (f, n)

Find symbols in symfun and return them as a symbolic vector.

If n specified, we take from the explicit function variables first followed by the output of symvar on any other symbols in the sym (expression) of the symfun.

Example:

syms a x f(t, s)
symvar (f, 1)
  ⇒ (sym) t
symvar (f, 2)
  ⇒ (sym) [t  s]  (1×2 matrix)

Note preference for the arguments of the symfun:

h = f*a + x
  ⇒ h(t, s) = (symfun) a⋅f(t, s) + x
symvar (h, 1)
  ⇒ (sym) t
symvar (h, 2)
  ⇒ (sym) [t  s]  (1×2 matrix)
symvar (h, 3)
  ⇒ (sym) [t  s  x]  (1×3 matrix)
symvar (h, 4)
  ⇒ (sym) [t  s  x  a]  (1×4 matrix)

On the other hand, if n is omitted, the results are sorted as explained elsewhere (see ‘@sym/symvar’). For example:

symvar (f, 2)
  ⇒ (sym) [t  s]  (1×2 matrix)
symvar (f)
  ⇒ (sym) [s  t]  (1×2 matrix)
symvar (h)
  ⇒ (sym) [a  s  t  x]  (1×4 matrix)

Compatibility with other implementations: the output generally matches the equivalent command in the Matlab Symbolic Toolbox (tested with version 2014a). For example:

syms x y s t
f(t, s) = 1
  ⇒ f(t, s) = (symfun) 1
symvar (f, 1)
  ⇒ (sym) t
symvar (f, 2)
  ⇒ (sym) [t  s]  (1×2 matrix)

However, when the symfun formula does not depend on the arguments, the results are not the same:

symvar (f)  % SMT would give []
  ⇒ (sym) [s  t]  (1×2 matrix)

If two variables have the same symbol but different assumptions, they will both appear in the output. It is not well-defined in what order they appear.

See also: findsymbols, @symfun/argnames, @symfun/formula.

Package: symbolic