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

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

The symbols are sorted in alphabetic order with capital letters first. If n is specified, the n symbols closest to x are returned.

Example:

syms x y
f = x^2 + 3*x*y - y^2;
symvar (f)
  ⇒ (sym) [x  y]  (1×2 matrix)
symvar (f, 1)
  ⇒ (sym) x

Further examples:

syms a x t
f = a*x + t;
symvar (f, 1)
  ⇒ (sym) x
symvar (f, 2)
  ⇒ (sym) [x  t]  (1×2 matrix)
symvar (f, 3)
  ⇒ (sym) [x  t  a]  (1×3 matrix)

And note its ok to ask for more:

symvar (f, 1000)
  ⇒ (sym) [x  t  a]  (1×3 matrix)

Compatibility with other implementations: the output should match the order of the equivalent command in the Matlab Symbolic Toolbox version 2014a, as documented here: http://www.mathworks.co.uk/help/symbolic/symvar.html

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, @sym/findsym.

Package: symbolic