Lista

Listan muodostaminen

Lista on alkioiden järjestetty joukko. Lista muodostetaan aaltosulkeiden avulla. Se on siis muotoa {alkio1, alkio2, alkio3,..., alkioN}. Alkiot voivat olla lukuja, lausekkeita, tekstijonoja jne... . Listan alkiot voivat myös olla listoja.
Tyhjää listaa merkitään
{}.
Vektorit ja matriisit esitetään listoina.

[Graphics:../Images/gr_110.gif]
[Graphics:../Images/gr_111.gif]

Lampaiden määrä Suomessa (Tilastokeskus). Jokainen listan alkio koostuu listasta, jossa on ensimmäisenä alkiona vuosi ja toisena lampaiden määrä (tuhansina) kyseisenä vuotena.

[Graphics:../Images/gr_112.gif]

Listat voidaan esittää taulukkomuodossa TableForm-komennon avulla. Sarakkeille/riveille voidaan antaa otsikot optiolla TableHeadings.

[Graphics:../Images/gr_113.gif]

vuosi maara
1938 956
1960 341
1970 189
1980 106
1990 103
1996 150
1997 150
1998 128

Mathematica Book:
Lisää TableForm-komennon optioista: luku
2.8.8

Listan alkioon viittaaminen

Listan  n:teen alkioon voidaan viitata komennolla lista[[n]]. Listan n. viimeiseen alkioon viitataan vastaavasti komennolla lista[[-n]]. Jos listan alkiot ovat listoja, niin esimerkiksi komento lista[[n,m]]antaa listan n:nnestä alkiosta m:nnen alkion.

Listasta voidaan poimia alkioita useilla eri tavoilla.

[Graphics:../Images/gr_114.gif] [Graphics:../Images/gr_115.gif]
[Graphics:../Images/gr_116.gif] [Graphics:../Images/gr_117.gif]
[Graphics:../Images/gr_118.gif] [Graphics:../Images/gr_119.gif]
[Graphics:../Images/gr_120.gif] [Graphics:../Images/gr_121.gif]
[Graphics:../Images/gr_122.gif] [Graphics:../Images/gr_123.gif]
[Graphics:../Images/gr_124.gif] [Graphics:../Images/gr_125.gif]

[Graphics:../Images/gr_126.gif]
[Graphics:../Images/gr_127.gif]
[Graphics:../Images/gr_128.gif]
[Graphics:../Images/gr_129.gif]
[Graphics:../Images/gr_130.gif]
[Graphics:../Images/gr_131.gif]
[Graphics:../Images/gr_132.gif]
[Graphics:../Images/gr_133.gif]
[Graphics:../Images/gr_134.gif]
[Graphics:../Images/gr_135.gif]

Listojen käsittelyä

[Graphics:../Images/gr_136.gif] [Graphics:../Images/gr_137.gif]
[Graphics:../Images/gr_138.gif] [Graphics:../Images/gr_139.gif]
[Graphics:../Images/gr_140.gif] [Graphics:../Images/gr_141.gif]
[Graphics:../Images/gr_142.gif] [Graphics:../Images/gr_143.gif]

[Graphics:../Images/gr_144.gif]
[Graphics:../Images/gr_145.gif]
[Graphics:../Images/gr_146.gif]
[Graphics:../Images/gr_147.gif]
[Graphics:../Images/gr_148.gif]
[Graphics:../Images/gr_149.gif]
[Graphics:../Images/gr_150.gif]
[Graphics:../Images/gr_151.gif]
[Graphics:../Images/gr_152.gif]
[Graphics:../Images/gr_153.gif]
[Graphics:../Images/gr_154.gif]

Mathematica book
Runsaasti erilaisia listojen käsittelyyn liittyviä komentoja: luku
1.8

Table-komento

Kun lista voidaan muodostaa noudattaen jotakin sääntöä, käytetään usein Table-komentoa. Tällöin alkioiden arvot ovat indeksimuuttujan funktioita.

[Graphics:../Images/gr_155.gif] [Graphics:../Images/gr_156.gif]
[Graphics:../Images/gr_157.gif] [Graphics:../Images/gr_158.gif]
[Graphics:../Images/gr_159.gif] [Graphics:../Images/gr_160.gif]

[Graphics:../Images/gr_161.gif]
[Graphics:../Images/gr_162.gif]
[Graphics:../Images/gr_163.gif]
[Graphics:../Images/gr_164.gif]

Range-komento

Komennolla Range muodostetaan luvuista tasavälisiä listoja.

[Graphics:../Images/gr_165.gif] [Graphics:../Images/gr_166.gif]
[Graphics:../Images/gr_167.gif] [Graphics:../Images/gr_168.gif]
[Graphics:../Images/gr_169.gif] [Graphics:../Images/gr_170.gif]

[Graphics:../Images/gr_171.gif]
[Graphics:../Images/gr_172.gif]