(*^ ::[ frontEndVersion = "Microsoft Windows Mathematica Notebook Front End Version 2.2"; microsoftWindowsStandardFontEncoding; fontset = title, "Helv", 24, L0, center, nohscroll, bold; fontset = subtitle, "Helv", 18, L0, center, nohscroll, bold; fontset = subsubtitle, "Helv", 14, L0, center, nohscroll, bold; fontset = section, "Helv", 14, L0, bold, grayBox; fontset = subsection, "Helv", 12, L0, bold, blackBox; fontset = subsubsection, "Helv", 10, L0, bold, whiteBox; fontset = text, "Helv", 12, L0; fontset = smalltext, "Helv", 10, L0; fontset = input, "Courier New", 12, L0, nowordwrap, bold; fontset = output, "Courier New", 12, L0, nowordwrap, bold; fontset = message, "Courier New", 10, L0, nowordwrap, R65280; fontset = print, "Courier New", 10, L0, nowordwrap; fontset = info, "Courier New", 10, L0, nowordwrap; fontset = postscript, "Courier New", 8, L0, nowordwrap; fontset = name, "Helv", 10, L0, nohscroll, italic, B65280; fontset = header, "Helv", 18, L0, nohscroll, bold; fontset = footer, "Helv", 18, L0, center, nohscroll, bold; fontset = help, "Helv", 10, L0, nohscroll; fontset = clipboard, "Helv", 12, L0, nohscroll; fontset = completions, "Helv", 12, L0, nowordwrap, nohscroll; fontset = graphics, "Courier New", 10, L0, nowordwrap, nohscroll; fontset = special1, "Arial", 12, L0, center, nowordwrap, nohscroll, bold; fontset = special2, "Helv", 12, L0, center, nowordwrap, nohscroll; fontset = special3, "Helv", 12, L0, right, nowordwrap, nohscroll; fontset = special4, "Helv", 12, L0, nowordwrap, nohscroll; fontset = special5, "Helv", 12, L0, nowordwrap, nohscroll; fontset = leftheader, "Helv", 12, L0, nowordwrap, nohscroll; fontset = leftfooter, "Helv", 12, L0, nowordwrap, nohscroll; fontset = reserved1, "Courier New", 10, L0, nowordwrap, nohscroll;] :[font = section; inactive; ] Erzeugen von Matrizen und Vektoren :[font = subsection; inactive; startGroup; Cclosed; ] Copyright :[font = text; inactive; endGroup; ] Copyright 1994, Claudia Funke TU-Berlin, FB 13, Fachgebiet Ökonometrie und Statistik Dieses Notebook darf ausschließlich als Unterrichtsmaterial und für private Zwecke verwendet und nicht ohne Zustimmung der Autorin verändert werden. :[font = subsection; inactive; ] Grundlagen :[font = text; inactive; ] Vektoren und Matrizen werden in Mathematica durch Listen dargestellt. Alles, was keine Liste ist, wird von Mathematica als Skalar betrachtet. Jede Liste kann wiederum durch eine Liste dargestellt werden. Elemente einer Matrix können demnach alle möglichen Elemente einer Liste sein, also reelle und komplexe Zahlen, Variablen, Zeichenketten und Objekte. :[font = subsubsection; inactive; startGroup; Cclosed; ] Erzeugen von Matrizen :[font = text; inactive; ] Vektoren und Matrizen können auf verschiedene Weisen erzeugt werden, die einfachste Form ist die Zuweisung der Elemente durch eine Aufzählung. :[font = input; nowordwrap; ] x = {1, 2, 3, c} :[font = text; inactive; ] Eine anschauliche Ausgabe der Liste erfolgt durch :[font = special1; inactive; output; nowordwrap; nohscroll; center; ] MatrixForm[ Liste ] :[font = input; nowordwrap; ] x = {{1, 2},{3, 4}}; MatrixForm[x] :[font = text; inactive; ] Durch die Funktion :[font = special1; inactive; output; nowordwrap; nohscroll; center; ] Table[ f, {i, n}, {j, n} ] :[font = text; inactive; ] Wird eine Matrix X erzeugt, in der die Funktion f für verschiedene Werte von i und j ausgewertet werden. :[font = input; nowordwrap; ] x = Table[ 1 / (i+j-1), {i, 4}, {j, 4}]; MatrixForm[x] :[font = text; inactive; ] Graphische Objekte können ebenfalls Elemente von Matrizen sein. :[font = input; nowordwrap; ] x = Table[ Plot[Sin[x], {x, 0, 2 Pi}], {3}, {3}] :[font = input; nowordwrap; ] MatrixForm[x] :[font = text; inactive; ] Mathematica kann Matrizen höherer Dimension (Tensoren) erstellen und verarbeiten. Eine dreidimensionale Matrix ist z.B. eine Matrix mit komplexen Zahlen, wobei jedes Element wiederum in Form einer neuen Liste als Real- teil und Imaginärteil aufgeteilt wurde. :[font = text; inactive; ] Dazu wird als Beispiel zuerst eine zweidimensionale (5,4) - Matrix erzeugt, bei der jedes Element aus einer komplexen Zahl besteht. :[font = input; nowordwrap; ] x = Table[ N[a + I b, 2], {a, 2, 4, 2}, {b, -0.5, 0.5, 1}]; MatrixForm[x] :[font = text; inactive; ] Anschließend wird jede komplexe Zahl in ihrem Realteil und Imaginärteil aufgespalten und als Liste abgespeichert. :[font = input; nowordwrap; ] x = Map[ {Re[#], Im[#]}&, x, {2}] :[font = text; inactive; ] Die neue Dimension der Matrix lautet nun :[font = input; endGroup; nowordwrap; ] Dimensions[x] :[font = subsubsection; inactive; startGroup; Cclosed; ] Spezielle Matrizen und Vektoren :[font = text; inactive; ] Die Einheitsmatrix I wird durch die Funktion :[font = special1; inactive; output; nowordwrap; nohscroll; center; ] IdentityMatrix[ n ] :[font = input; nowordwrap; ] erzeugt. :[font = input; nowordwrap; ] x = IdentityMatrix[3]; MatrixForm[x] :[font = text; inactive; ] Eine beliebige Skalarmatrix läßt sich mit Table[ ] erzeugen. :[font = input; nowordwrap; ] x = Table[0, {3}, {4}]; MatrixForm[x] :[font = text; inactive; ] Eine Diagonalmatrix erhält man mit :[font = special1; inactive; output; nowordwrap; nohscroll; center; ] DiagonalMatrix[ Liste ] :[font = text; inactive; ] wobei Liste einen Vektor der Diagonalelemente darstellt und damit die Größe der Matrix bestimmt. :[font = input; nowordwrap; ] x = DiagonalMatrix[{a, b, c}]; MatrixForm[x] :[font = text; inactive; ] Eine Matrix mit standardnormalverteilten Zufallszahlen erhält man ebenfalls mit Table[ ]. :[font = input; nowordwrap; ] x = Table[Random[ ], {3}, {4}]; MatrixForm[x] :[font = text; inactive; ] Obere und untere Dreiecksmatrizen werden auch mit Table[ ] erzeugt. :[font = input; nowordwrap; ] x = Table[ If[i >= j, 1, 0], {i, 4}, {j, 4} ]; MatrixForm[x] :[font = input; nowordwrap; ] x = Table[ If[i <= j, 1, 0], {i, 4}, {j, 4}]; MatrixForm[x] :[font = text; inactive; ] Zum Aufbau einer mehrdiagonalen Matrix wird die Funktion :[font = special1; inactive; output; nowordwrap; nohscroll; center; backColorRed = 65280; backColorGreen = 65280; backColorBlue = 65280; fontColorRed = 0; fontColorGreen = 0; fontColorBlue = 0; bold; fontName = "Arial"; fontSize = 12; ] Switch[ Ausdruck, Form1, Wert1, Form2, Wert2, ... , def ] :[font = text; inactive; ] benötigt. Switch[ ] vergleicht expr. mit form1 bzw. form2 und gibt bei Übereinstimmung den form1 bzw. form2 zugeordneten Wert zurück. form1 bzw. form2 muß ein Skalar sein. Gibt es keine Übereinstimmung von expr. mit einem der angegebenen Werte, so kann mit _ und def ein Defaultwert zurückgegeben werden. :[font = input; endGroup; nowordwrap; ] x = Table[ Switch[i-j, -1, a, 0, b, 1, c, _, 0], {i, 5}, {j, 5}]; MatrixForm[x] :[font = subsubsection; inactive; startGroup; Cclosed; ] Spezielle Vektoren :[font = text; inactive; ] Für das Plotten von Beobachtungswerten wird häufig ein Vektor mit fortlaufenden Werten benötigt. Dies kann mit :[font = special1; inactive; output; nowordwrap; nohscroll; center; ] Range[ n1, n2, dn ] :[font = text; inactive; ] erfolgen. :[font = input; nowordwrap; ] x = Range[5] :[font = input; endGroup; nowordwrap; ] x = Range[0, 4, 0.25] ^*)