Differenze tra le versioni di "Tutorial:Ordinare gli elementi di una lista"

Da GeoGebra Manual.
Riga 14: Riga 14:
  
 
{{example|1=
 
{{example|1=
If you want to sort a list of points such that their distance to the origin is increasing we have <math>X := \mathbb R^2</math> and <math>f((x,y)) := \sqrt{x^2 + y^2}</math>. In GeoGebra <math>f</math> for a point <code>A</code> would be <code>Length[A]</code>, so the bold section in the algorithm would read <code>Length[Element[list,i]]</code>.}}
+
Per ordinare una lista di punti in modo tale che la loro distanza dall'origine sia crescente, avremo <math>X := \mathbb R^2</math> e <math>f((x,y)) := \sqrt{x^2 + y^2}</math>. In GeoGebra <math>f</math> per un punto <code>A</code> è <code>Lunghezza[A]</code>, e quindi la parte in grassetto dell'algoritmo diventa in questo caso <code>Lunghezza[Elemento[lista, i]]</code>.}}
 
{{example|1=
 
{{example|1=
If you want to sort a list of circles such that their radius is increasing the bold section in the algorithm would read <code>Radius[Element[list,i]]</code>.}}
+
Per ordinare una lista di circonferenze secondo il raggio decrescente, la parte in grassetto dell'algoritmo sarà <code>Raggio[Elemento[lista,i]]</code>.}}
 
{{example|1=
 
{{example|1=
A complete construction to sort a list of complex numbers by their argument can be found on GeoGebra: http://www.geogebra.org/material/show/id/7518
+
Su GeoGebra è disponibile una [[http://www.geogebra.org/material/show/id/7518 costruzione completa]] sull'ordinamento di numeri complessi secondo i rispettivi argomenti}}
}}
+
Il trucco per risolvere questo problema in GeoGebra è quello di utilizzare il comando predefinito per ordinare una lista di punti. Invece di pensare a un punto in termini geometrici, conviene pensare ad esso come a una coppia di numeri. GeoGebra allora consente l'ordinamento delle coppie rispetto all'ascissa, in modo da ottenere allows us to sort those points by their x-coordinates,  so we create a list of points <math>\tilde c = (\tilde c_1, \ldots, \tilde c_n)</math> with <math>\tilde c_k := (f(a_k), k)</math> and sort this list. Let's call the sorted list <math>c = (c_1, \ldots, c_n)</math>. This sorted list now allows us to construct <math>\sigma</math>, because <math>y(c_{\sigma(k)}) = k</math>. Using <math>\sigma</math> we can then construct the sorted version of our original list.
The trick to solve this problem in GeoGebra is to use the existing command to sort a list of points. Instead of thinking of points geometrically we think of those just as pairs of numbers. GeoGebra allows us to sort those points by their x-coordinates,  so we create a list of points <math>\tilde c = (\tilde c_1, \ldots, \tilde c_n)</math> with <math>\tilde c_k := (f(a_k), k)</math> and sort this list. Let's call the sorted list <math>c = (c_1, \ldots, c_n)</math>. This sorted list now allows us to construct <math>\sigma</math>, because <math>y(c_{\sigma(k)}) = k</math>. Using <math>\sigma</math> we can then construct the sorted version of our original list.
 
  
 
== And for the names? ==
 
== And for the names? ==

Versione delle 09:44, 18 ago 2012

A volte il comando Ordina non è sufficiente per ottenere alcune opzioni avanzate di ordinamento degli oggetti presenti in una lista. (Per ritornare alla situazione iniziale, dopo un ordinamento, basta utilizzare il comando Ordina[] assieme al comando Inverti[]).

Quando il tipo di oggetti contenuti nella lista non è supportato dal comando Ordina[] o si desidera utilizzare un criterio di ordinamento completamente diverso da quello implementato, è possibile seguire il procedimento e gli esempi descritti di seguito.

Algoritmo

  1. Sialista la lista da ordinare.
  2. lista_h = Ordina[Successione[(*numero basato su Elemento[lista, i]*, i), i, 1, Lunghezza[lista]]]
    Ciò corrisponde a c nella Spiegazione. La parte di testo in grassetto si riferisce a f nella Spiegazione.
  3. lista_s = Successione[Elemento[lista, y(Elemento[lista_h, i])], i, 1, Lunghezza[lista]]
    Ecco la lista ordinata.

Spiegazione

Riformuliano in termini matematici la questione: data una lista (a_1, a_2, \ldots, a_n) \subset X e un'applicazione f: X \to \mathbb R si vuole determinare una permutazione \sigma \in S_n tale che f(a_{\sigma(k)}) \leq f(a_{\sigma(l)}) \; \forall (k,l) \in \mathbb N^2: 1 \leq k \leq l \leq n. Si può pensare alla permutazione \sigma come a una rinumerazione, tale che (a_{\sigma(1)}, a_{\sigma(2)}, \ldots, a_{\sigma(n)}) sarà la lista ordinata.

È innanzitutto necessario determinare un'applicazione f che ci consenta di ottenere un ordinamento corretto:

Esempio: Per ordinare una lista di punti in modo tale che la loro distanza dall'origine sia crescente, avremo X := \mathbb R^2 e f((x,y)) := \sqrt{x^2 + y^2}. In GeoGebra f per un punto A è Lunghezza[A], e quindi la parte in grassetto dell'algoritmo diventa in questo caso Lunghezza[Elemento[lista, i]].
Esempio: Per ordinare una lista di circonferenze secondo il raggio decrescente, la parte in grassetto dell'algoritmo sarà Raggio[Elemento[lista,i]].
Esempio: Su GeoGebra è disponibile una [costruzione completa] sull'ordinamento di numeri complessi secondo i rispettivi argomenti

Il trucco per risolvere questo problema in GeoGebra è quello di utilizzare il comando predefinito per ordinare una lista di punti. Invece di pensare a un punto in termini geometrici, conviene pensare ad esso come a una coppia di numeri. GeoGebra allora consente l'ordinamento delle coppie rispetto all'ascissa, in modo da ottenere allows us to sort those points by their x-coordinates, so we create a list of points \tilde c = (\tilde c_1, \ldots, \tilde c_n) with \tilde c_k := (f(a_k), k) and sort this list. Let's call the sorted list c = (c_1, \ldots, c_n). This sorted list now allows us to construct \sigma, because y(c_{\sigma(k)}) = k. Using \sigma we can then construct the sorted version of our original list.

And for the names?

Imagine we have constructed five points called A, B, C, D and E and we want to sort those points based upon some criterion. Using list = {A,B,C,D,E} the algorithm above can be used to achieve this, but it will just return a sorted list with the coordinates of the points, not a sorted list with their original names, which could have a meaning in the construction and thus also helpful to display to the user. To also display those names in a sorted manner we have to extend our algorithm slightly:

  1. Let list_n be a list with the names of the objects we want to sort.
    For example: list_n = {"A", "B","C","D","E"}. Do not forget the quotes: We want the names of the objects and not the objects themselves!
  2. Define list=Sequence[Object[Element[list_n, k]], k, 1, Length[list_n]].
    This creates the list of objects we want to sort based upon the name list.
  3. list_h = Sort[Sequence[(*number based upon Element[list, i]*, i), i, 1, Length[list]]]
    This is step 2 of our original algorithm.
  4. list_{ns} = Sequence[Element[list_n, y(Element[list_h, i])], i, 1, Length[list]]
    This is now a list with the sorted names of the objects, like {"B", "A", "E", "F", "D"}. If you also want a sorted list with the values you can just use list_s as defined in the original algorithm.
Esempio: The third example from above using this modified algorithm to also display object names can be found here: http://www.geogebra.org/material/show/id/7775

es:Tutorial:Orden de Listas Avanzado fr:Tutoriel:Tri pointu pour une liste de:Anleitungen:Listen von beliebigen Elementen sortieren

© 2024 International GeoGebra Institute