symvar

Lists the symbolic variables in an expression.

Category: Language Fundamentals > Data Types

Syntax

v = symvar(f)

Returns all symbolic variables of f, in alphabetical order.

v = symvar(f, n)

Returns the n variables closest to x, in order of preference.

Description

Only free symbolic variables are listed; constants such as pi and numbers are not. The default variable that functions like diff and int use when you do not name one is the first element of symvar(f, 1): the letter closest to x in the alphabet.

The expression must be symbolic, so create variables first with syms.

Input arguments

f
Symbolic expression, equation or function.
n
Number of variables to return.

Output arguments

v
Row vector of symbolic variables.

Example

All variables and the default one

syms x y a
symvar(a*x^2 + y)
symvar(a*x^2 + y, 1)
Output
ans = 
[a, x, y]
ans = x

See also

syms diff int subs solve