Difference between revisions of "Sort Command"

From GeoGebra Manual
Jump to: navigation, search
m (Text replace - "<div class="box info"> 48px|left This page is part of the official manual for print and pdf. For structural reasons normal users can't edit this page. If you found any errors on this page please contact )
Line 1: Line 1:
 
<noinclude>{{Manual Page|version=4.2}}</noinclude>
 
<noinclude>{{Manual Page|version=4.2}}</noinclude>
 
{{command|list}}
 
{{command|list}}
; Sort[List]: Sorts a list of numbers, text objects, or points.
+
;Sort[ <List> ]
 +
:Sorts a list of numbers, text objects, or points.
 
:{{Note| Lists of points are sorted by ''x''-coordinates.}}
 
:{{Note| Lists of points are sorted by ''x''-coordinates.}}
 
:{{Examples|1=<div>
 
:{{Examples|1=<div>
Line 11: Line 12:
 
:{{Examples|1=<div>
 
:{{Examples|1=<div>
 
:* In order to sort a list of polynomials <code>list1 = {x^3, x^2, x^6}</code>  according to degree, create the dependent list of degrees <code>list2 = Zip[Degree[a], a, list1]</code>. After that, <code> Sort[list1, list2]</code> yields the requested ''list3 = {x^2, x^3, x^6}''.
 
:* In order to sort a list of polynomials <code>list1 = {x^3, x^2, x^6}</code>  according to degree, create the dependent list of degrees <code>list2 = Zip[Degree[a], a, list1]</code>. After that, <code> Sort[list1, list2]</code> yields the requested ''list3 = {x^2, x^3, x^6}''.
:* In order to draw the polygon having as vertices the complex roots of <math>x^{10}-1</math>, sorted by their arguments, create <code>list1 = {ComplexRoot[x^10-1]}</code>,  then use the command <code>Polygon[Sort[list1, arg(list1)]] </code></div>}}
+
:* In order to draw the polygon having as vertices the complex roots of <math>x^{10}-1</math>, sorted by their arguments, create <code>list1 = {ComplexRoot[x^10-1]}</code>,  then use the command <code>Polygon[Sort[list1, arg(list1)]]</code>. This command yields ''poly1 = 2.94''.</div>}}
  
 
{{note|There is a workaround to sort lists of arbitrary objects which is explained in the [[Tutorial:Advanced List Sorting]].}}
 
{{note|There is a workaround to sort lists of arbitrary objects which is explained in the [[Tutorial:Advanced List Sorting]].}}

Revision as of 13:00, 16 July 2013



Sort[ <List> ]
Sorts a list of numbers, text objects, or points.
Note: Lists of points are sorted by x-coordinates.
Examples:
  • Sort[{3, 2, 1}] gives you the list {1, 2, 3}.
  • Sort[{"pears", "apples", "figs"}] gives you the list elements in alphabetical order.
  • Sort[{(3, 2), (2, 5), (4, 1)}] gives you {(2, 5), (3, 2), (4, 1)}.


Sort[ <Values>, <Keys> ]
Sorts the first list Values according to the corresponding second list Keys.
Examples:
  • In order to sort a list of polynomials list1 = {x^3, x^2, x^6} according to degree, create the dependent list of degrees list2 = Zip[Degree[a], a, list1]. After that, Sort[list1, list2] yields the requested list3 = {x^2, x^3, x^6}.
  • In order to draw the polygon having as vertices the complex roots of x^{10}-1, sorted by their arguments, create list1 = {ComplexRoot[x^10-1]}, then use the command Polygon[Sort[list1, arg(list1)]]. This command yields poly1 = 2.94.


Note: There is a workaround to sort lists of arbitrary objects which is explained in the Tutorial:Advanced List Sorting.
© 2021 International GeoGebra Institute