HP Forums

Full Version: about the proot command output
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,
The proot command in the Prime inputs a list, say p, and outputs a list, proot(p), whose items are the roots of the polynomial whose coefficients are those of the list p, with 1st item in list equal to constant coefficient, and so on.

Is there any rule as to how the roots are ordered in the list proot(p)? Sometimes I get real numbers first, sometime complex numbers first. For example,
proot([1 -2 -4 4 -5 6])=[3. 1. -2. -i i])
proot([1 -2 -4 4 -5 7])=[-2.74e-2+1.03*i -2.74e-2-1.03*i 1.07 -2.01 2.98]

Also, related to input, how does the CAS Setting INCREASING affect the order of the input list of coefficients?

Thanks
proot output is not sorted, run sort(proot(...)) to sort it.
Increasing coeffs flag is for symbolic output only. 1-d polynomial input/output as a list of coefficients is sorted from x^n to x^0.
(10-06-2014 08:17 AM)parisse Wrote: [ -> ]proot output is not sorted, run sort(proot(...)) to sort it.
Increasing coeffs flag is for symbolic output only. 1-d polynomial input/output as a list of coefficients is sorted from x^n to x^0.

Thank you. But how does SORT work on a list that has both real and complex numbers? It does sort the real numbers from small to large, but I cannot figure out what it does to the complex ones:
SORT([1 i -i 3 2+i])=[1 3 2+i i -i]
Or what it does to lists with just complex numbers
SORT([-2+i -i 2+i 3-i 5i]) = [5i 3-i 2i -2i -i]
If you want to sort by real part first then imaginary part, you can try something like:
l:=[-2+i, -i, 2+i ,3-i ,5i];
sort(l,(a,b)->if re(a)!=re(b) then re(a)<re(b) else im(a)<im(b) end);
(10-06-2014 03:58 PM)parisse Wrote: [ -> ]If you want to sort by real part first then imaginary part, you can try something like:
l:=[-2+i, -i, 2+i ,3-i ,5i];
sort(l,(a,b)->if re(a)!=re(b) then re(a)<re(b) else im(a)<im(b) end);

Great, thanks.
I was just reading about SORT with functions in your hprime.pdf, but did not think of this possibility.
By the way, in the latest Xcas version you can also use SortA. I don't remember if that works on the Prime.
I'm going to modify proot in Xcas in order to sort the roots.
Reference URL's