Die Grundidee von Mathematica

Mathematica stellt jedes Objekt als symbolischen Ausdruck dar.

Alle symbolischen Ausdrücke ergeben sich als Kombinationen des Basisausdruckes der Form: head[arg_1,arg_2,…]

Eine Liste von Elementen:

{a, b, c}

List[a, b, c]

Ein algebraischer Ausdruck:

x^2 + x^(1/2)

Plus[Power[x, 2], Sqrt[x]]

Grafik:

[Graphics:HTMLFiles/index_7.gif]

Graphics[{Circle[{1, 0}, 2], <br />         &nb ... bsp;            Circle[{-1, 0}, 2]}]

Ein button:

Press here

 ButtonBox["Press here"]

Eine Zelle in einem "notebook":

A cell containing text

Cell["A cell containing text", "Text"]

Alle Operationen in Mathematica sind Transformationen symbolischer Ausdrücke auf der Basis einer leistungsfähigen Mustererkennung.

Mit /. führt Mathematica eine einfache Transformation b→1+x durch.

{a, b, c, d}/.b->1 + x

{a, 1 + x, c, d}

Bezeichnen x_ und y_ beliebige Ausdrücke, so ergibt der Ausdruck x_+y_ die Summe der Terme.

{a + b, c + d, a + c}/.x_ + y_->x^2 + y^2

{a^2 + b^2, c^2 + d^2, a^2 + c^2}

{a + b, c + d, a + c}/.a + x_->x^3

{b^3, c + d, c^3}

Mathematica verwendet Ausdrücke (patterns) zur Definition von Funktionen in der Kombination von Funktionsvorschriften und Spezialfällen.

Eine Funktionsdefinition für beliebige  x (zunächst als reell vorausgesetzt).

f[x_] := 2/x

Ein Spezialfall überschreibt die allgemeine Vorschrift.

f[0] := e

Ein Beispiel der Anwendung von f:

f[6] + f[a + b] + f[0]

1/3 + 2/(a + b) + e

Dadurch wird die Definition von  f gelöscht :

Clear[f]

In den Funktionsargumenten können allgemeine Strukturen (Zahlen, Kreise, Matritzen,...) vorkommen.

Ein Funktionswert von  g ergibt sich aus Listenargumenten:

g[{x_, y_}] := x + y

g[{4, a b}]

4 + a b

Clear[g]

Ein Kreis kann ein Funktionsargument sein:

area[Circle[{_, _}, r_]] := π r^2

area[Circle[{2, 3}, u]]

π u^2

Trigonometrische Funktionen und Exponentialfunktionen

TrigToExp[Sin[x]]

1/2  ^(- x) - 1/2  ^( x)

TrigToExp[Tan[x]]

( (^(- x) - ^( x)))/(^(- x) + ^( x))

ExpToTrig[E^x]

Cosh[x] + Sinh[x]

ExpToTrig[E^(I x)]

Cos[x] +  Sin[x]

Additionstheoreme für Winkelfunktionen

TrigExpand[Sin[x + y]]

Cos[y] Sin[x] + Cos[x] Sin[y]

TrigExpand[Cos[x + y]]

Cos[x] Cos[y] - Sin[x] Sin[y]

TrigExpand[Sin[2 x]]

2 Cos[x] Sin[x]

TrigExpand[Tan[x + y]]

(Cos[y] Sin[x])/(Cos[x] Cos[y] - Sin[x] Sin[y]) + (Cos[x] Sin[y])/(Cos[x] Cos[y] - Sin[x] Sin[y])

TrigFactor[Cos[x] Cos[y] - Sin[x] Sin[y]]

Cos[x + y]

Drehmetrizen (analytische und algebraische Strukturen mit Mathematica)

f[x_] := {{Cos[x], Sin[x]}, {-Sin[x], Cos[x]}}

f[x]//MatrixForm

( {{Cos[x], Sin[x]}, {-Sin[x], Cos[x]}} )

p = f[x] . f[y]

{{Cos[x] Cos[y] - Sin[x] Sin[y], Cos[y] Sin[x] + Cos[x] Sin[y]}, {-Cos[y] Sin[x] - Cos[x] Sin[y], Cos[x] Cos[y] - Sin[x] Sin[y]}}

p//MatrixForm

( {{Cos[x] Cos[y] - Sin[x] Sin[y], Cos[y] Sin[x] + Cos[x] Sin[y]}, {-Cos[y] Sin[x] - Cos[x] Sin[y], Cos[x] Cos[y] - Sin[x] Sin[y]}} )

TrigFactor[p]//MatrixForm

( {{Cos[x + y], Sin[x + y]}, {-Sin[x + y], Cos[x + y]}} )

D[f[x], x]//MatrixForm

( {{-Sin[x], Cos[x]}, {-Cos[x], -Sin[x]}} )

Matrizen (Mathematica und algebraische Strukturen)

a = {{1, 1}, {1, 0}}

{{1, 1}, {1, 0}}

a//MatrixForm

( {{1, 1}, {1, 0}} )

Produkt mit Scalaren:

3 a//MatrixForm

( {{3, 3}, {3, 0}} )

nur in Mathematica:

a + 7//MatrixForm

( {{8, 8}, {8, 7}} )

f[x_] := x + 7

Map[f, a]

{{8, 8}, {8, 7}}

Produkte und Potenzen

a . a//MatrixForm

( {{2, 1}, {1, 1}} )

MatrixPower[a, 2]//MatrixForm

( {{2, 1}, {1, 1}} )

MatrixPower[a, 10]//MatrixForm

( {{89, 55}, {55, 34}} )

b = MatrixPower[a, 0.5]//N

{{0.920442 + 0.217287 , 0.568864 - 0.351578 }, {0.568864 - 0.351578 , 0.351578 + 0.568864 }}

b . b

{{1. - 2.90295*10^-17 , 1. - 1.32679*10^-17 }, {1. - 1.00546*10^-16 , 2.67554*10^-16 + 9.21572*10^-18 }}

Chop[b . b]

{{1., 1.}, {1., 0}}

c = MatrixPower[{{2, 1}, {1, 1}}, 0.5]

{{1.34164, 0.447214}, {0.447214, 0.894427}}

c . c//MatrixForm

( {{2., 1.}, {1., 1.}} )

MatrixPower[{{2, 1}, {1, 1}}, 1/2]

{{1/2 (1/10 (3 - 5^(1/2)))^(1/2) (-1 + 5^(1/2)) + 1/2 (1 + 5^(1/2)) (1/10 (3 + 5^(1/2)))^(1/ ... , 1/2 (1/10 (3 - 5^(1/2)))^(1/2) (1 + 5^(1/2)) + 1/2 (-1 + 5^(1/2)) (1/10 (3 + 5^(1/2)))^(1/2)}}

Beispiel eines diskreten Modells (Fibonaccizahlen)

Definition 1 in Mathematica:

f[n_] := f[n - 1] + f[n - 2] ; f[0] = 1 ; f[1] = 1 ;

Table[f[i], {i, 0, 30}]

{1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811, 514229, 832040, 1346269}

Timing[f[30]]

{6.71 Second, 1346269}

Definition 2 in Mathematica ("Funktion mit Gedächtnis"):

g[n_] := g[n] = g[n - 1] + g[n - 2] ; g[0] = 1 ; g[1] = 1 ;

Table[g[i], {i, 0, 30}]

{1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811, 514229, 832040, 1346269}

Timing[g[30]]

{0. Second, 1346269}

Zusammenhang mit Matrizenrechnung:

MatrixPower[{{1, 1}, {1, 0}}, 29]//MatrixForm

( {{832040, 514229}, {514229, 317811}} )

Explizite Definition:

h[n_] := 1/Sqrt[5] (((1 + Sqrt[5])/2)^(n + 1) - ((1 - Sqrt[5])/2)^(n + 1))

h[n]

(-(1/2 (1 - 5^(1/2)))^(1 + n) + (2/(1 + 5^(1/2)))^(-1 - n))/5^(1/2)

Table[Expand[h[i]], {i, 0, 30}]

{1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811, 514229, 832040, 1346269}

Rekurrence-Gleichungen und erzeugende Funktionen

<<DiscreteMath`RSolve`

RSolve[{a[n] a[n - 1] + a[n - 2], a[0] a[1] 1}, a[n], n]

{{a[n]  (2^(-1 - n) (-(1 - 5^(1/2))^(1 + n) + (1 + 5^(1/2))^(1 + n)))/5^(1/2)}}

GeneratingFunction[{a[n] a[n - 1] + a[n - 2], a[0] a[1] 1}, a[n], n, x]

{{-1/(-1 + x + x^2)}}

s = Series[-1/(-1 + x + x^2), {x, 0, 30}]

1 + x + 2 x^2 + 3 x^3 + 5 x^4 + 8 x^5 + 13 x^6 + 21 x^7 + 34 x^8 + 55 x^9 + 89 x^10 + 144 x^ ... 4 + 121393 x^25 + 196418 x^26 + 317811 x^27 + 514229 x^28 + 832040 x^29 + 1346269 x^30 + O[x]^31

Table[SeriesCoefficient[s, n], {n, 0, 30}]

{1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811, 514229, 832040, 1346269}

g[n_] := g[n] = g[n - 1] + g[n - 2] ; g[0] = 1 ; g[1] = 1 ;

Table[g[i], {i, 0, 30}]

{1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811, 514229, 832040, 1346269}

Tensoren

t = {{{1, 2, 3}, {4, 5, 6}}, {{7, 8, 9}, {10, 11, 12}}}

{{{1, 2, 3}, {4, 5, 6}}, {{7, 8, 9}, {10, 11, 12}}}

t//MatrixForm

( {{( {{1}, {2}, {3}} ), ( {{4}, {5}, {6}} )}, {( {{7}, {8}, {9}} ), ( {{10}, {11}, {12}} )}} )

Beispiel: Berechnungen mit 1200×900×3-Tensor

(* g = Import["c:\\vl2004\\IMGA1468.jpg"] ; Bildübertragungen sind über In ... 400, 300}] ; <br />g[[1, 1]] = gg[[1, 1]] - 100 ; <br />Show[g, ImageSize {400, 300}] *)


Created by Mathematica  (October 23, 2005) Valid XHTML 1.1!