Products & Services Industries Academia Support User Community Company

Learn more about Symbolic Math Toolbox   

symvar - Find symbolic variables in symbolic expression or matrix

Syntax

symvar(s)
symvar(s,n)

Description

symvar(s) returns a vector containing all the symbolic variables in s. The variables are returned in the alphabetical order with uppercase letters preceding lowercase letters. If there are no symbolic variables in s, then symvar returns the empty vector. symvar does not consider the constants pi, i, and j to be variables.

symvar(s,n) returns a vector containing the n symbolic variables in s that are alphabetically closest to 'x':

  1. The variables are sorted by the first letter in their names. The ordering is x y w z v u ... a X Y W Z V U ... A. The name of a symbolic variable cannot begin with a number.

  2. For all subsequent letters, the ordering is alphabetical, with all uppercase letters having precedence over lowercase: 0 1 ... 9 A B ... Z a b ...z.

Examples

syms wa wb wx yx ya yb
f = wa + wb + wx + ya + yb + yx;
symvar(f)

The result is:

ans =
[ wa, wb, wx, ya, yb, yx]
syms x y z a b
w = x^2/(sin(3*y - b));
symvar(w)

The result is:

ans =
[ b, x, y]
symvar(w, 3)

The result is:

ans =
[ x, y, b]

symvar(s,1) returns the variable closest to x. When performing differentiation, integration, substitution or solving equations, MATLAB uses this variable as a default variable.

syms v z
g = v + z;
symvar(g, 1)

The result is:

ans =
z
syms aaa aab
g = aaa + aab;
symvar(g, 1)

The result is:

ans =
aaa
syms X1 x2 xa xb
g = X1 + x2 + xa + xb;
symvar(g, 1)

The result is:

ans =
x2 

See Also

findsym, sym, syms

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS