Order of polynomial display: increasing order of powers?
Show older comments
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!
4 Comments
Karan Gill
on 27 Oct 2016
Why do you need this particular ordering? Details on what you are trying to do would be helpful.
Walter Roberson
on 27 Oct 2016
The order is important because it is a taylor expansion and the classic representation of a taylor expansion is in increasing orders of differentiation, which for sin() and a number of other important functions results in increasing powers of x.
The order of the terms should be in increasing n so that one can quickly see the effect of truncating at some lower point and so that one can quickly see the pattern in the coefficients.
HiWave
on 18 Feb 2020
I find this extremely annoying as well. It is as if they anticipate no practical use of the output.
Bilal Akbana
on 29 Apr 2021
Following command works and gives result as shown below;
syms x
sympref('PolynomialDisplayStyle','ascend');
sinTaylor = taylor(sin(x),x,'Order',11);
disp(sinTaylor)
x - x^3/6 + x^5/120 - x^7/5040 + x^9/362880
Accepted Answer
More Answers (1)
Robert
on 26 Oct 2016
Hey there
So this is a bug in matlab I found the bug a few weeks ago and it should be fixed in the next release
It turns out with the addition of a tilda you can change the order in which the coeffs function returns values.
Try the following code and please don't forget to accept the answer so i can get the credit for helping. Thanks!
syms x
y = x - x^3/6 + x^5/120 - x^7/5040 + x^9/362880
[High_Order , ~] = coeffs(y) % Use this to get the higher order first
Coefficient_Low_first = coeffs(y)
4 Comments
Alasdair McAndrew
on 26 Oct 2016
Robert
on 26 Oct 2016
You obviously did not try my code I just showed you how to do exactly this. Adding the brackets and the tilda changes the order.
Its a bug in matlab that i have previously reported
The output is as follows. If you tried what i gave you your issue would be solved
>> T = taylor(sin(x),x,'Order',10);
>> coeffs(T)
ans =
[ 1, -1/6, 1/120, -1/5040, 1/362880]
>> [T,~]=coeffs(T)
T =
[ 1/362880, -1/5040, 1/120, -1/6, 1]
>>
Walter Roberson
on 26 Oct 2016
You can extract the coefficients in one order or the reverse but the user needs the symbolic expression itself to be displayed in a different order
Walter Roberson
on 26 Oct 2016
Consider for example sin() around the expression. coeffs() would not work because that would not be a multinomial, but you might still have an interest in the order that the expression displays.
Categories
Find more on Polynomial Creation in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!