MATLAB: The order of free symbolic variables

symbolic variables

Hello!I have a question about the order of free symbolic variables.
==========
syms X Y
f=sin(X+Y);
symvar(f,1)
ans =
X
==========
Since abs('Y'-'x')<abs('X'-'x'), why the free symbolic variable of 'f' is not'Y'?
Thanks a lot.

Best Answer

Under Algorithms:
When sorting the symbolic variables by their proximity to x, symvar uses this algorithm:
  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.