MATLAB: Order of polynomial display: increasing order of powers

displaypolynomialsSymbolic Math Toolboxterm order

A symbolic polynomial will be displayed in order of decreasing powers:
>> taylor(sin(x),x,'Order',11)
ans =
x^9/362880 - x^7/5040 + x^5/120 - x^3/6 + x
Is there a preference value I can set which will display such polynomials in increasing order of powers? Like this:
x - x^3/6 + x^5/120 - x^7/5040 + x^9/362880
Thank you!

Best Answer

No, there is no preference for adjusting the order of expressions. The symbolic engine is permitted to return expressions in any order, and is permitted to change the order during different executions.
There might be a rule, but it is not easy to figure out what it is. For example,
>> y*k*x
ans =
k*x*y
>> k*x*k+x*y*x*x*x + y*x*k + k^2
ans =
k^2*x + k^2 + y*k*x + y*x^4
>> k*x*k+x*y*x*x*x + y*x*k + k^2*y
ans =
k^2*x + y*k^2 + y*k*x + y*x^4
The first of those suggests possibly alphabetical order, k coming before x coming before y. But the second of those has y*k*x -- why did it choose that in the larger expression? It has not ordered the expression by powers of x -- if it did then k^2 would have to be first or last. The third shows k^2*x and y*k^2 which has equal powers of k but sorts differently, non-alphabetically. But
>> x*k^2 + y*k^2
ans =
k^2*x + k^2*y
so sometimes it does put them in alphabetical order.
It is not sorting alphabetically. It is not sorting by total power.
But it is influenced by those things. For example if you replace k by the other single-letter names in k^2*x + k^2 + y*k*x + y*x^4 (excluding x and y) then the same order is used in each case, except for z:
y*x^4 + x*z^2 + y*x*z + z^2
When I was testing last week, I found cases where the order changed completely if a constant was added to the expression.