43
Einführung in Mathematica (3) Lineare Algebra, Analysis und Bewegungsgleichungen L. Tiator, Computer in der Wissenschaft, WS 2011/12 Voreinstellungen ü Grafik - Initialisierung SetOptions@8Plot, ListPlot, ParametricPlot, Plot3D, Graphics<, BaseStyle 818, FontFamily "Times", Italic<D; SetOptions@Plot, PlotStyle 8Thickness@0.005D<D; SetOptions@ListPlot, PlotStyle 8Red, PointSize@0.035D<D; dünne Linien und Punkte : SetOptions@8Plot, ListPlot, Graphics<, BaseStyle 8Medium, FontFamily "Times"<D; SetOptions@Plot, PlotStyle 8Thickness@0.002D<D; SetOptions@ListPlot, PlotStyle 8Red, PointSize@0.005D<D; andere mögliche Fonts : BaseStyle 818, FontFamily "Helvetica"< BaseStyle 8Large, FontFamily "Helvetica", Italic, Bold< ü selbstdefinierte globale Funktionen für selbstdefinierte Funktionen etc. eignet sich die Cell-Option : Cell Properties: Initialization Cell solche Zellen können auch an beliebigen Stellen der Datei stehen und werden nach dem Laden der Datei beim ersten Ausführen einer Zelle direkt gestartet tooltip@flist_, nlist_D := Inner@Tooltip, flist, nlist, ListD RootPlot@sol_, opts : OptionsPattern@ListPlotDD := Module@8<, CellPrint@ExpressionCell@N@solD, "Output"DD; ListPlot@Tooltip@8Re@ÓD, Im@ÓD<D & ê@ N@x ê. solD, opts, AspectRatio Automatic, PlotStyle 8Red, PointSize@.02D<D D ComplexNumberPlot@list_, opts : OptionsPattern@ListPlotDD := Module@8<, ListPlot@Tooltip@8Re@ÓD, Im@ÓD<D & ê@ N@listD, opts, AspectRatio Automatic, PlotStyle 8Red, PointSize@.02D<D D

Einführung in Mathematica (3) · Analysis ü Ableitungen ü Einfache oder mehrfache Ableitungen D@f, xD Eine Funktion y[x] kann einfach mit y', y'', usw (Apostroph) abgeleitet werden

Embed Size (px)

Citation preview

Einführung in Mathematica (3)

Lineare Algebra, Analysis und Bewegungsgleichungen

L. Tiator, Computer in der Wissenschaft, WS 2011/12

Voreinstellungen

ü Grafik - Initialisierung

SetOptions@8Plot, ListPlot, ParametricPlot, Plot3D, Graphics<,BaseStyle → 818, FontFamily → "Times", Italic<D;

SetOptions@Plot, PlotStyle → [email protected]<D;SetOptions@ListPlot, PlotStyle → 8Red, [email protected]<D;

dünne Linien und Punkte :

SetOptions@8Plot, ListPlot, Graphics<,BaseStyle → 8Medium, FontFamily → "Times"<D;

SetOptions@Plot, PlotStyle → [email protected]<D;SetOptions@ListPlot, PlotStyle → 8Red, [email protected]<D;

andere mögliche Fonts :

BaseStyle → 818, FontFamily → "Helvetica"<BaseStyle → 8Large, FontFamily → "Helvetica", Italic, Bold<

ü selbstdefinierte globale Funktionen

für selbstdefinierte Funktionen etc. eignet sich die Cell-Option : Cell Properties: Initialization Cellsolche Zellen können auch an beliebigen Stellen der Datei stehen und werden nach dem Laden der Dateibeim ersten Ausführen einer Zelle direkt gestartet

tooltip@flist_, nlist_D := Inner@Tooltip, flist, nlist, ListD

RootPlot@sol_, opts : OptionsPattern@ListPlotDD := Module@8<,CellPrint@ExpressionCell@N@solD, "Output"DD;ListPlot@Tooltip@8Re@ D, Im@ D<D & ê@ N@x ê. solD,opts, AspectRatio → Automatic, PlotStyle → 8Red, [email protected]<D

D

ComplexNumberPlot@list_, opts : OptionsPattern@ListPlotDD := Module@8<,ListPlot@Tooltip@8Re@ D, Im@ D<D & ê@ N@listD,opts, AspectRatio → Automatic, PlotStyle → 8Red, [email protected]<D D

Analysis

ü Ableitungen

ü Einfache oder mehrfache Ableitungen D@ f , xD

Eine Funktion y[x] kann einfach mit y', y'', usw (Apostroph) abgeleitet werden.

y@x_D := x Log@xD

y @xD

1 + Log@xD

y @xD

1

x

yH3L@xD

−1

x2

y'''''@xD

−6

x4

die zugrunde liegende Funktion ist: D@ f , xD, bzw. D@ f , 8x, n<D und bezeichnet die "partielle Ableitung"

D@y@xD, xD

1 + Log@xD

D@y@xD, 8x, 3<D

−1

x2

das mathematische Symbol für die partielle Ableitung kann durch Âpd oder mit der Paletteeingegeben werden

f@x_D := LegendreP@5, xD

∂x f@xD

1

8I15 − 210 x2 + 315 x4M

Mit Shift-Ctrl-I (Eingabe Form) Shift-Ctrl-N (Standard Form) und Shift-Ctrl-T (Traditional Form) kann man leicht und schnell mal die Darstellung wechseln.

∂8x,5<f@xD

945

2 Mathematica_3.nb

ü Partielle Ableitungen für mehrdimensionale Funktionen

partielle Ableitung von x2 - y2 nach x

∂xIx2 − y2M

2 x

oder nach x und y

D@x^2 − y^2, x, yD

0

in der "Traditional Form" sieht die Eingabe etwas vertrauter aus:

∂2 Ix2 - y2M∂ x∂ y

0

ü Totales Differential und totale Ableitung Dt@ f , xD

ohne 2. Argument liefert Dt@ f D das totale Differential df

Dt@f@x, yDD

Dt@yD fH0,1L@x, yD + Dt@xD fH1,0L@x, yD

in der "Traditional Form" :

‚ f Hx, yL

Dt@yD fH0,1L@x, yD + Dt@xD fH1,0L@x, yD

zum Beispiel

DtAx2 − y2E

2 x Dt@xD − 2 y Dt@yD

in der "Traditional Form" :

‚ Ix2 - y2M2 x Dt@xD − 2 y Dt@yD

mit einem 2. Argument liefert Dt@ f , xD die totale Ableitung nach x: df ê dx

DtAx2 − y2, xE

2 x − 2 y Dt@y, xD

oder

DtAx2 − y2, tE

2 x Dt@x, tD − 2 y Dt@y, tD

in der "Traditional Form" :

Mathematica_3.nb 3

‚ Ix2 - y2M‚ t

2 x Dt@x, tD − 2 y Dt@y, tD

Beispiel: f Hx, z, tL = x2 + z2 nicht explizit zeitabhängig, wie z.B. die meisten Lagrangefunktionen

f@x_, z_, t_D := x2 + z2

partielle Ableitung:

∂t f@x, z, tD

0

in der "Traditional Form" :

∂ f Hx, z, tL∂ t

0

totale Ableitung:

Dt@f@x, z, tD, tD

2 x Dt@x, tD + 2 z Dt@z, tD

2 x2 + z2

in der "Traditional Form" :

‚ rHx, z, tL‚ t

2 x Dt@x, tD + 2 z Dt@z, tD

2 x2 + z2

wenn aber die Zeit t explizit angegeben wird, sind partielle und totale Ableitungen bei Mathematicaidentisch

totale Ableitung:

Dt@f@x@tD, z@tD, tD, tD

2 x@tD x @tD + 2 z@tD z @tD

2 x@tD2 + z@tD2

in der "Traditional Form" :

‚ f HxHtL, zHtL, tL‚ t

2 x@tD x @tD + 2 z@tD z @tD

2 x@tD2 + z@tD2

partielle Ableitung:

4 Mathematica_3.nb

∂t r@x@tD, z@tD, tD êê Simplify êê TraditionalForm

xHtL x£HtL + zHtL z£HtL

xHtL2 + zHtL2

soll eine Konstante (z.B. die Masse m) nicht auch differenziert werden, kann man dies als Option angeben:

Dt@m x @tD, t, Constants → 8m<D

m x @tD

sonst erhält man einen Zusatzterm:

Dt@m x @tD, tD êê TraditionalForm

m x££HtL

in solchen Bewegungsgleichungen kann man aber genauso gut mit der "partiellen Ableitung" arbeiten

D@m x @tD, tD

m x @tD

ü Integrale

ü Unbestimmte Integrale

‡ Sin@xD x

−Cos@xD

nicht ganz so trivial ist

‡ HLog@xD + Sin@xDL1

x2+ Exp@xD x

−1

2 xH2 + x x Cos@xD − 2 x CosIntegral@xD +

2 x ExpIntegralEi@xD + 2 Log@xD − 2 x x Log@xD + 2 Sin@xD − x x Sin@xDL

zur Probe kann man wieder differenzieren

∂x%

−1

2 x

2

x+ x Cos@xD − 2 CosIntegral@xD +

2 ExpIntegralEi@xD − 2 x Log@xD − 2 x x Log@xD − x Sin@xD − 2 x x Sin@xD +

1

2 x2H2 + x x Cos@xD − 2 x CosIntegral@xD + 2 x ExpIntegralEi@xD +

2 Log@xD − 2 x x Log@xD + 2 Sin@xD − x x Sin@xDL

allerdings kann man dies erst nach einer Vereinfachung als ursprüngliche Funktion wiedererkennen.

Simplify@%D

I1 + x x2M HLog@xD + Sin@xDL

x2

Mathematica_3.nb 5

Bestimmte Integrale

‡0

π

Sin@xD2 x

π

2

Auch uneigentliche Integrale sind möglich (¶ bekommt man mit ÂinfÂ)

‡1

∞ 1

x2x

1

‡0

ExpA−a x2E x

IfBRe@aD > 0,π

2 a, IntegrateA −a x2, 8x, 0, ∞<, Assumptions → Re@aD ≤ 0EF

Mathematica gibt die allgemeinste Lösung des Integrals an, für Spezialfälle müssen Annahmen über dieParameter angegeben werden

Integrate@Exp@−a ∗ x^2D, 8x, 0, Infinity<,Assumptions −> Re@aD > 0D

π

2 a

oder einfach (aber auch unsicherer) die Fallunterscheidung abschalten

Integrate@Exp@−a ∗ x^2D, 8x, 0, Infinity<,GenerateConditions −> FalseD

π

2 a

oder auch mehrdimenionale Integrale

‡0

1

‡0

π

2x Sin@yD y x

1

2

Bei bestimmten Integralen, die über einen einfachen Pol mit Vorzeichenwechsel führen, kann auch dasCauchy Hauptwertintegral ermittelt werden.

IntegrateB1

x − 1, 8x, 0, 3<, PrincipalValue → TrueF

Log@2D

6 Mathematica_3.nb

Limit@Exp@−a xD, x → ∞, Assumptions → a > 0D

0

Bei Grenzwerten, die von oben und unten verschieden sind, kann man eine Richtung angeben

Limit@1 ê x, x −> 0, Direction → 1D

−∞

Limit@Sin@1 ê xD, x → 0D

Interval@8−1, 1<D

Limit@Sin@1 ê xD, x → ∞D

0

ü Einschub Intervallrechnung

x1 = Interval@8−0.1, 0.1<D

Interval@8−0.1, 0.1<D

x2 = 2.0 + x1 ê 2

[email protected], 2.05<D

y1 = x1 ∗ x2

Interval@8−0.205, 0.205<D

y1 =3 + x1

x2

[email protected], 1.58974<D

2 selbst definierte Funktionen, die Intervallrechnung einfacher machen

makeint@a_, δ_D := Interval@8a − δ, a + δ<Dmakecenter@interv_D := Module@8min1, max1, mid<,

min1 = Min@intervD;max1 = Max@intervD;mid = Hmin1 + max1L ê 2;

8mid, min1 − mid, max1 − mid<D

y1 êê makecenter

81.50219, −0.0875547, 0.0875547<

[email protected]`, −0.08755472170106393`D

[email protected], 1.58974<D

ü Reihenentwicklungen

Remove@fD

formale Taylor - Entwicklung :

Mathematica_3.nb 9

PlotB1

x − 1, 8x, 0, 3<, Filling → AxisF

Bei Eingebung von zusätzlichen Optionen kann das Integralzeichen nicht benutzt werden.

ü Numerische Integration

in vielen Fällen liefert eine analytische Integration als Ergebnis spezielle Funktionen

Integrate@Sin@Sin@xDD, 8x, 0, Pi<D

π StruveH@0, 1D

% êê N

1.78649

%% êê N@ , 50D &

1.7864874819500523366874236012519572937614804561287

oder

Integrate@Sin@Sqrt@Log@1 + xDDD, 8x, 0, Pi<D

−1

41ê4 π ErfB

1

2− Log@1 + πD F − ErfiB−

2+ Log@1 + πD F + H1 + πL SinB Log@1 + πD F

% êê N

2.39176 + 0.

% êê Chop

2.39176

oder auch überhaupt kein Ergebnis

IntegrateBSinB1

x2 + 1F, 8x, 0, 1<F

‡0

1

SinB1

1 + x2F x

% êê N

0.698101

Mathematica_3.nb 7

NIntegrateBSinB1

x2 + 1F, 8x, 0, 1<F

0.698101

NIntegrate@Sin@Sin@xDD, 8x, 0, π<D

1.78649

Bei einer normalerweise 16-stelligen internen Maschinengenauigkeit ergibt sich eine etwa 6-stelligeabsolute Genauigkeit des Integrals. Höhere Genauigkeit erzielt man mit entsprechend höherer WorkingPre-cision.

NIntegrate@Sin@Sin@xDD, 8x, 0, Pi<, WorkingPrecision −> 50D

1.7864874819500523366874236012519572937614804561287

Beispiel eines 2-dim Integrals über eine Dreiecksfläche

NIntegrateAExpAx2 − y2E, 8x, 0, 1<, 8y, 0, x<E

0.722623

auch in diesem Fall gibt es eine analytische Lösung mit hypergeometrischen Reihen

‡0

1

‡0

xx2−y2 y x

1

2HypergeometricPFQB81, 1<, :

3

2, 2>, 1F

bei analytischen Lösungen braucht man natürlich keine Workingprecision

N@%, 100D

0.7226228066941736144338319192179077041813074327602015236466145905187402161988902478714850361886118942

ü Grenzwerte

Limit@xx, x → 0D

1

LimitBLogAx2E

x, x → ∞F

0

limxƕ

logIx2M

x

0

Limit@Exp@−a xD, x → ∞D

Limit@ −a x, x → ∞D

Falls a positiv ist, z.B. bei einer Masse oder einer Wellenzahl etc., kann dies als zusätzliche Annahme(Assumption) angegeben werden:

8 Mathematica_3.nb

Series@f@xD, 8x, x0, 3<D

f@x0D + f @x0D Hx − x0L +1

2f @x0D Hx − x0L2 +

1

6fH3L@x0D Hx − x0L3 + O@x − x0D4

auch als Entwicklung in mehreren Dimensionen möglich :

Series@g@x, yD, 8x, x0, 3<, 8y, y0, 2<D

g@x0, y0D + gH0,1L@x0, y0D Hy − y0L +1

2gH0,2L@x0, y0D Hy − y0L2 + O@y − y0D3 +

gH1,0L@x0, y0D + gH1,1L@x0, y0D Hy − y0L +1

2gH1,2L@x0, y0D Hy − y0L2 + O@y − y0D3 Hx − x0L +

1

2gH2,0L@x0, y0D +

1

2gH2,1L@x0, y0D Hy − y0L +

1

4gH2,2L@x0, y0D Hy − y0L2 + O@y − y0D3 Hx − x0L2 +

1

6gH3,0L@x0, y0D +

1

6gH3,1L@x0, y0D Hy − y0L +

1

12gH3,2L@x0, y0D Hy − y0L2 + O@y − y0D3 Hx − x0L3 +

O@x − x0D4

Sinus Taylorreihe

Series@Sin@xD, 8x, 0, 8<D

x −x3

6+

x5

120−

x7

5040+ O@xD9

so wird aus einer Reihe eine normale Funktion :

f0@x_D = % êê Normal

x −x3

6+

x5

120−

x7

5040

Sinus Taylorreihe um p/2

f1@x_D = Series@Sin@xD, 8x, π ê 2, 8<D êê Normal êê Simplify

1 −1

8Hπ − 2 xL2 +

1

384Hπ − 2 xL4 −

Hπ − 2 xL6

46 080+I− π

2+ xM8

40 320

% êê N êê Expand

0.0000247373 + 0.999843 x + 0.000447261 x2 − 0.167421 x3 +0.00083204 x4 + 0.00770694 x5 + 0.000324584 x6 − 0.000311666 x7 + 0.0000248016 x8

mit Chop kann man kleine Terme eines Ausdrucks vernachlässigen, als Default gilt < 10-10 so wie hier kann man aber eine beliebige Schranke angeben:

f2@x_D = % êê ChopA , 10−4E &

0.999843 x + 0.000447261 x2 − 0.167421 x3 +0.00083204 x4 + 0.00770694 x5 + 0.000324584 x6 − 0.000311666 x7

was aber in diesem Fall nicht sinnvoll wäre, wie man im nächsten Plot sieht

10 Mathematica_3.nb

Plot@Tooltip@8Sin@xD, f0@xD, f1@xD, f2@xD<D,8x, 0, 2 π<, PlotStyle → 8Red, Blue, Green, Cyan<D

1 2 3 4 5 6

-6-5-4-3-2-1

1

Plot@tooltip@8Sin@xD, f0@xD, f1@xD, f2@xD<, 8Sin, f0, f1, f2<D êê Evaluate,8x, 0, 2 π<, PlotStyle → 8Red, Blue, Green, Cyan<D

1 2 3 4 5 6

-6-5-4-3-2-1

1

im nächsten Beispiel vergleichen wir eine Entwicklung um Null mit einer asymptotischen Entwicklung umUnendlich

h0@x_D :=ArcTan@xD Sin@xD2

I1 + x2M3

h1@x_D = Series@h0@xD, 8x, 0, 10<D êê Normal

x3 −11 x5

3+376 x7

45−14 453 x9

945

h2@x_D = Series@h0@xD, 8x, ∞, 10<D êê Normal

3 π

x10+

10

3 x9−

3 π

2 x8−

1

x7+

π

2 x6Sin@xD2

Mathematica_3.nb 11

Plot@Tooltip@8h0@xD, h1@xD, h2@xD<D, 8x, 0, 4<, PlotRange → 0.2,PlotStyle → 8Red, Blue, Green<D

1 2 3 4

-0.2

-0.1

0.1

0.2

LogPlot@Abs@Hh0@xD − h2@xDL ê h0@xDD, 8x, 0, 100<D

20 40 60 80 100

10-7

10-5

0.001

Series@Gamma@1 + xD, 8x, ∞, 10<D

J−1−LogB 1

xFN x+OB 1

xF11

2 π x +

π

2

6 x+

π

2

144 x3ê2−

139 π

2

25 920 x5ê2−

571 π

2

1 244 160 x7ê2+

163 879 π

2

104 509 440 x9ê2+

5246 819 π

2

37 623 398 400 x11ê2−

534 703 531 π

2

451 480 780 800 x13ê2−

4483 131 259 π

2

43 342 154 956 800 x15ê2+

432 261 921 612 371 π

2

257 452 400 443 392 000 x17ê2+

6232 523 202 521 089 π

2

43 252 003 274 489 856 000 x19ê2+ OB

1

xF21ê2

% êê N êê Expand êê Chop

J−1.−1. LogB 1

xFN x+OB 1

xF11

2.50663 x +0.208886

x+0.00870357

x3ê2−0.00672109

x5ê2−0.000575201

x7ê2+0.00196529

x9ê2+

0.000174783

x11ê2−0.00148434

x13ê2−0.000129638

x15ê2+0.00210431

x17ê2+0.0001806

x19ê2+ OB

1

xF21ê2

12 Mathematica_3.nb

g10@x_D = % êê Normal;

LogPlot@8Gamma@1 + xD, g10@xD<, 8x, 0, 100<D

20 40 60 80 100

1027

1054

1081

10108

10135

Series@SphericalBesselJ@3, xD, 8x, 0, 10<D êê Normal

x3

105−

x5

1890+

x7

83 160−

x9

6 486 480

Bie der folgenden Reihenentwicklung um den Pol der Tangensfunktion bei p/2 bekommt man als Ergebniseine Laurentreihe

Series@Tan@xD, 8x, π ê 2, 10<D êê Normal

−1

−π

2+ x

+1

3−π

2+ x +

1

45−π

2+ x

3

+2

945−π

2+ x

5

+I− π

2+ xM7

4725+2 I− π

2+ xM9

93 555

ü Laurentreihen und Residuen

Das Residuum einer Funktion ist der -1. Koeffizient ihrer Laurentreihe

laurent =a@−2D

Hx − x0L2+a@−1Dx − x0

+ a@0D + a@1D Hx − x0L

a@−2DHx − x0L2

+a@−1Dx − x0

+ a@0D + Hx − x0L a@1D

Residue@laurent, 8x, x0<D

a@−1D

zum Beispiel für eine gebrochen rationale Funktion

quot1 =1

x Hx − 1L Hx − 2L2

1

H−2 + xL2 H−1 + xL x

Partialbruchzerlegung

quot1 êê Apart

1

2 H−2 + xL2−

3

4 H−2 + xL+

1

−1 + x−

1

4 x

Mathematica_3.nb 13

Residue@quot1, 8x, 0<D

−1

4

Residue@quot1, 8x, 1<D

1

Residue@quot1, 8x, 2<D

−3

4

oder für eine beliebige singuläre Funktion

SeriesB1

Sin@xD3, 8x, 0, 5<F

1

x3+

1

2 x+17 x

120+457 x3

15 120+3287 x5

604 800+ O@xD6

ResidueB1

Sin@xD3, 8x, 0<F

1

2

im Folgenden handelt es sich um eine wesentliche Singularität am Ort x = 0in diesem Fall existiert weder eine Laurentreihe noch ein Residuum

SeriesB −1

x2 , 8x, 0, 5<F

−1

x2

Vektoren und Matrizen

In Mathematica ist ein Vektor eine Liste und eine Matrix eine geschachtelte Liste

ü Vektoren

vec1 = 8a, b, c<

8a, b, c<

vec1 êê MatrixForm

abc

vec2 = Array@a, 3D

8a@1D, a@2D, a@3D<

ü Matrizen

Erzeugung einer 2x2 Matrix mit Palette

14 Mathematica_3.nb

mat1 =a bc d

88a, b<, 8c, d<<

Erzeugung einer beliebigen NxM Matrix mit Palettemit Ctrl Enter ( ‚¿ ) erzeugt man eine neue Zeilemit Ctrl , (Komma) ( ‚ , ) erzeugt man eine neue Spalte

mat2 =

a1 a2 a3 a4b1b2

b4

88a1, a2, a3, a4<, 8b1, , , <, 8b2, , , <, 8 , , , <, 8b4, , , <<

Erzeugung einer symbolischen Matrix mit Array

mat3 = Array@A, 82, 3<D

88A@1, 1D, A@1, 2D, A@1, 3D<, 8A@2, 1D, A@2, 2D, A@2, 3D<<

% êê MatrixForm

A@1, 1D A@1, 2D A@1, 3DA@2, 1D A@2, 2D A@2, 3D

auch eine etwas schönere Schreibweise mit Indizes ist möglich mit der Funktion Subscript[...]

Array@Subscript@x, 1, 2D &, 83, 3<D êê MatrixForm

x1,1 x1,2 x1,3x2,1 x2,2 x2,3x3,1 x3,2 x3,3

aber Vorsicht bei Indizes: Die indizierte Größe ist nicht unabhängig von der normalen Variablen.

9x = 2, x1,2 = 0, x3 = 5=

82, 0, 5<

Array@Subscript@x, 1, 2D &, 83, 3<D êê MatrixForm

21,1 0 21,322,1 22,2 22,323,1 23,2 23,3

Remove@xD

natürlich kann eine Matrix auch mit dem Befehl Table[...] erzeugt werden:

mat4 = TableAai,j, 8i, 1, 4<, 8j, 1, 3<E êê MatrixForm

a1,1 a1,2 a1,3a2,1 a2,2 a2,3a3,1 a3,2 a3,3a4,1 a4,2 a4,3

Vorsicht: //MatrixForm ist wie auch //TableForm etc eine Darstellungsform und sollte nicht in die Defini-tion einer Größe aufgenommen werden:

Mathematica_3.nb 15

mat4@@2, 2DD

Part::partw : Part 2 of

a1,1 a1,2 a1,3

a2,1 a2,2 a2,3

a3,1 a3,2 a3,3

a4,1 a4,2 a4,3

does not exist. à

a1,1 a1,2 a1,3a2,1 a2,2 a2,3a3,1 a3,2 a3,3a4,1 a4,2 a4,3

P2, 2T

besser:

Imat5 = TableAbi,j, 8i, 1, 4<, 8j, 1, 3<EM êê MatrixForm

b1,1 b1,2 b1,3b2,1 b2,2 b2,3b3,1 b3,2 b3,3b4,1 b4,2 b4,3

ü Einheitsmatrix

IdentityMatrix@5D êê MatrixForm

1 0 0 0 00 1 0 0 00 0 1 0 00 0 0 1 00 0 0 0 1

ü Diagonalmatrix

DiagonalMatrix@81, 2, 3, 4, 5<D êê MatrixForm

1 0 0 0 00 2 0 0 00 0 3 0 00 0 0 4 00 0 0 0 5

auch für sub- und superdiagonale Matrizen

DiagonalMatrix@8a, b<, −1D êê MatrixForm

0 0 0a 0 00 b 0

ü Operationen auf Matrizen und Vektoren

ü Multiplikationen (mit normalem Punkt: . )

diese beiden Matrizen passen nicht zusammen:

16 Mathematica_3.nb

mat1.mat5

Dot::dotsh :Tensors 88a, b<, 8c, d<< and 99b1,1, b1,2, b1,3=, 9b2,1, b2,2, b2,3=, 9b3,1, b3,2, b3,3=, 9b4,1, b4,2, b4,3== have incompatible

shapes. à

88a, b<, 8c, d<<.88b1,1, b1,2, b1,3<, 8b2,1, b2,2, b2,3<, 8b3,1, b3,2, b3,3<, 8b4,1, b4,2, b4,3<<

mat1.mat3 êê MatrixForm

a A@1, 1D + b A@2, 1D a A@1, 2D + b A@2, 2D a A@1, 3D + b A@2, 3Dc A@1, 1D + d A@2, 1D c A@1, 2D + d A@2, 2D c A@1, 3D + d A@2, 3D

mit Apply[funct, liste] bzw. funct /@ liste operiert die Funktion auf jedes einzelne Element

MatrixForm ê@ 8mat1, mat3, mat1.mat3<

: a bc d

,A@1, 1D A@1, 2D A@1, 3DA@2, 1D A@2, 2D A@2, 3D ,

a A@1, 1D + b A@2, 1D a A@1, 2D + b A@2, 2D a A@1, 3D + b A@2, 3Dc A@1, 1D + d A@2, 1D c A@1, 2D + d A@2, 2D c A@1, 3D + d A@2, 3D >

mat1.8x, y<

8a x + b y, c x + d y<

vec = 8x, y<

8x, y<

mat1.vec êê MatrixForm

a x + b yc x + d y

vec.mat1 êê MatrixForm

a x + c yb x + d y

Skalarprodukt

81, 2<.83, 4<

11

Vektorprodukt

81, 2, −1< 83, 4, 5<

814, −8, −2<

ü Spalten - und Zeilenvektoren

wenn man zwischen Spalten- und Zeilenvektoren unterscheiden möchte, muss man diese als Matrizenschreiben:

vcolumn = 88x<, 8y<<

88x<, 8y<<

% êê MatrixForm

K xy O

Mathematica_3.nb 17

vline = 88x, y<<

88x, y<<

% êê MatrixForm

H x y L

mat1.vcolumn êê MatrixForm

a x + b yc x + d y

vline.mat1 êê MatrixForm

H a x + c y b x + d y L

die jeweils andere Schreibweise ist dann ausgeschlossen:

mat1.vline êê MatrixForm

Dot::dotsh : Tensors 88a, b<, 8c, d<< and 88x, y<< have incompatible shapes. à

88a, b<, 8c, d<<.88x, y<<

vcolumn.mat1 êê MatrixForm

Dot::dotsh : Tensors 88x<, 8y<< and 88a, b<, 8c, d<< have incompatible shapes. à

88x<, 8y<<.88a, b<, 8c, d<<

mit Transpose[ ] kann man die beiden Formen ineinander überführen:

Transpose@vlineD êê MatrixForm

K xy O

Transpose@vcolumnD êê MatrixForm

H x y L

ü Norm und Normierung

v = 81, 2, 3<

81, 2, 3<

Norm@vD

14

vn = Normalize@vD

:1

14,

2

7,

3

14>

% êê Norm

1

18 Mathematica_3.nb

ü Operationen auf Matrizen

c1 =1 1 +

1 − −1

881, 1 + <, 81 − , −1<<

die transponierte Matrix

Transpose@c1D êê MatrixForm

1 1 −1 + −1

und die hermitisch konjugierte Matrix

ConjugateTranspose@c1D êê MatrixForm

1 1 +1 − −1

Inverse Matrix

Inverse@c1D êê MatrixForm

1

3

1

3+

3

1

3−

3−

1

3

Spur (Tr[...]) und Determinante (Det[...])

c1 êê Trc1 êê Det

0

−3

ü Lineare Gleichungssysteme

A . x = bdabei ist A eine Matrix und b und x sind Vektoren. Formal ist die Lösung: x = A-1 . b

mA = RandomInteger@5, 83, 3<D

883, 2, 2<, 85, 4, 2<, 85, 4, 0<<

vb = RandomInteger@8−2, 2<, 3D

80, −1, 0<

ü Lösung mit Inverser Matrix

vx = [email protected]

:2, −5

2, −

1

2>

Mathematica_3.nb 19

ü Lösung mit LinearSolve

vx = LinearSolve@mA, vbD

:2, −5

2, −

1

2>

ü Lösung mit Solve

vx = 8x, y, z<

8x, y, z<

eq1 = mA.vx vb

83 x + 2 y + 2 z, 5 x + 4 y + 2 z, 5 x + 4 y< 80, −1, 0<

Solve@eq1, 8x, y, z<D

::x → 2, y → −5

2, z → −

1

2>>

ü Eigenwert Gleichungen

. = l bzw. ( - l ) . = 0dabei ist l ein Eigenwert und v ein Eigenvektor. Eine 3x3 Matrix hat 3 Eigenwerte und 3 dazugehörigeEigenvektoren.

ü triviales Beispiel

HmA = DiagonalMatrix@8a, b, c<DL êê MatrixForm

a 0 00 b 00 0 c

Eigenvalues@mAD

8a, b, c<

Eigenvectors@mAD

881, 0, 0<, 80, 1, 0<, 80, 0, 1<<

man kann auch mit Eigensystem[...] die Eigenwerte und dazugehörigen Eigenvektoren auf einmalberechnen:

Eigensystem@mAD

88a, b, c<, 881, 0, 0<, 80, 1, 0<, 80, 0, 1<<<

% êê MatrixForm

a b c81, 0, 0< 80, 1, 0< 80, 0, 1<

20 Mathematica_3.nb

ü ein nicht so triviales Beispiel

HmB = Array@Subscript@b, 1, 2D &, 82, 2<DL êê MatrixForm

b1,1 b1,2b2,1 b2,2

Eigensystem@mBD êê MatrixForm

1

2Kb1,1 + b2,2 − b1,1

2 + 4 b1,2 b2,1 − 2 b1,1 b2,2 + b2,22 O 1

2Kb1,1 + b2,2 + b1,1

2 + 4 b1,2 b2,1 − 2 b1,1 b2,2 + b2,22

:− −b1,1+b2,2+ b1,12 +4 b1,2 b2,1−2 b1,1 b2,2+b2,2

2

2 b2,1, 1> :− −b1,1+b2,2− b1,1

2 +4 b1,2 b2,1−2 b1,1 b2,2+b2,22

2 b2,1, 1>

HmB = Array@Subscript@b, 1, 2D &, 84, 4<DL êê MatrixForm

b1,1 b1,2 b1,3 b1,4b2,1 b2,2 b2,3 b2,4b3,1 b3,2 b3,3 b3,4b4,1 b4,2 b4,3 b4,4

Eigensystem@mBD

A very large output was generated. Here is a sample of it:

99RootA 14 + 37 + 12 H−b1,2 b2,1 + 14 + b2,2 b4,4 + b3,3 b4,4L +1 Hb1,3 b2,2 b3,1 − b1,2 b2,3 b3,1 − b1,3 b2,1 b3,2 + b1,1 b2,3 b3,2 + b1,2 b2,1 b3,3 − b1,1 b2,2 b3,3 +

b1,4 b2,2 b4,1 − b1,2 b2,4 b4,1 + 13 + b1,1 b3,4 b4,3 + b2,2 b3,4 b4,3 + b1,2 b2,1 b4,4 −

b1,1 b2,2 b4,4 + b1,3 b3,1 b4,4 + b2,3 b3,2 b4,4 − b1,1 b3,3 b4,4 − b2,2 b3,3 b4,4L &, 1E,Root@ 1 &, 2D, 1 , RootA 14 + 38 + 1 H 1 L &, 4E=,

8 1 <=

Show Less Show More Show Full Output Set Size Limit...

mit numerischen Matrizen ist das alles kein Problemdas nächste Beispiel rechnet jedoch erstmal exakt, da es sich um ganze Zahlen handelt

HmC = RandomInteger@9, 85, 5<DL êê MatrixForm

9 4 9 5 56 4 6 6 64 1 9 0 52 1 2 4 69 8 4 6 2

Eigensystem@mCD

Mathematica_3.nb 21

:9RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 3E,RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 2E,RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 5E,RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 4E,RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 1E=,

::199 386 458

19 113 455+

1

19 113 45585 731 307 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 3E +

1

19 113 4555660 304 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 3E2 −

1

19 113 4555076 186 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 3E3 +

1

19 113 455189 452 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 3E4,

−27 694 848

3822 691−

1

11 468 07337 265 914 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 3E −

1

11 468 0732889 590 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 3E2 +

1

3822 691767 956 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 3E3 −

1

11 468 07385 537 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 3E4,

−93 079 003

19 113 455−

1

57 340 365111 196 331 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 3E −

1

57 340 3657630 837 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 3E2 +

1

19 113 4552076 701 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 3E3 −

1

57 340 365230 756 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 3E4,

−11 753 170

3822 691−

1

11 468 07310 732 768 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 3E −

1

11 468 073224 042 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 3E2 +

1

3822 691222 021 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 3E3 −

1

11 468 07325 690 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 3E4, 1>,

22 Mathematica_3.nb

:199 386 458

19 113 455+

1

19 113 45585 731 307 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 2E +

1

19 113 4555660 304 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 2E2 −

1

19 113 4555076 186 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 2E3 +

1

19 113 455189 452 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 2E4,

−27 694 848

3822 691−

1

11 468 07337 265 914 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 2E −

1

11 468 0732889 590 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 2E2 +

1

3822 691767 956 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 2E3 −

1

11 468 07385 537 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 2E4,

−93 079 003

19 113 455−

1

57 340 365111 196 331 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 2E −

1

57 340 3657630 837 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 2E2 +

1

19 113 4552076 701 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 2E3 −

1

57 340 365230 756 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 2E4,

−11 753 170

3822 691−

1

11 468 07310 732 768 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 2E −

1

11 468 073224 042 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 2E2 +

1

3822 691222 021 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 2E3 −

1

11 468 07325 690 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 2E4, 1>,

:199 386 458

19 113 455+

1

19 113 45585 731 307 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 5E +

1

19 113 4555660 304 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 5E2 −

1

19 113 4555076 186 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 5E3 +

Mathematica_3.nb 23

1

19 113 455189 452 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 5E4,

−27 694 848

3822 691−

1

11 468 07337 265 914 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 5E −

1

11 468 0732889 590 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 5E2 +

1

3822 691767 956 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 5E3 −

1

11 468 07385 537 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 5E4,

−93 079 003

19 113 455−

1

57 340 365111 196 331 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 5E −

1

57 340 3657630 837 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 5E2 +

1

19 113 4552076 701 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 5E3 −

1

57 340 365230 756 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 5E4,

−11 753 170

3822 691−

1

11 468 07310 732 768 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 5E −

1

11 468 073224 042 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 5E2 +

1

3822 691222 021 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 5E3 −

1

11 468 07325 690 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 5E4, 1>,

:199 386 458

19 113 455+

1

19 113 45585 731 307 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 4E +

1

19 113 4555660 304 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 4E2 −

1

19 113 4555076 186 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 4E3 +

1

19 113 455189 452 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 4E4,

−27 694 848

3822 691−

1

11 468 07337 265 914 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 4E −

1

11 468 0732889 590 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 4E2 +

24 Mathematica_3.nb

1

3822 691767 956 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 4E3 −

1

11 468 07385 537 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 4E4,

−93 079 003

19 113 455−

1

57 340 365111 196 331 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 4E −

1

57 340 3657630 837 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 4E2 +

1

19 113 4552076 701 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 4E3 −

1

57 340 365230 756 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 4E4,

−11 753 170

3822 691−

1

11 468 07310 732 768 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 4E −

1

11 468 073224 042 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 4E2 +

1

3822 691222 021 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 4E3 −

1

11 468 07325 690 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 4E4, 1>,

:199 386 458

19 113 455+

1

19 113 45585 731 307 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 1E +

1

19 113 4555660 304 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 1E2 −

1

19 113 4555076 186 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 1E3 +

1

19 113 455189 452 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 1E4,

−27 694 848

3822 691−

1

11 468 07337 265 914 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 1E −

1

11 468 0732889 590 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 1E2 +

1

3822 691767 956 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 1E3 −

1

11 468 07385 537 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 1E4,

−93 079 003

19 113 455−

1

57 340 365111 196 331 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 1E −

Mathematica_3.nb 25

1

57 340 3657630 837 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 1E2 +

1

19 113 4552076 701 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 1E3 −

1

57 340 365230 756 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 1E4,

−11 753 170

3822 691−

1

11 468 07310 732 768 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 1E −

1

11 468 073224 042 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 1E2 +

1

3822 691222 021 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 1E3 −

1

11 468 07325 690 RootA−1080 + 524 1 + 416 12 + 62 13 − 28 14 + 15 &, 1E4, 1>>>

Eigensystem@mCD êê N

8824.7906, 6.30732, −2.08477 + 1.44889 , −2.08477 − 1.44889 , 1.0716<,881.08142, 0.932444, 0.649633, 0.499963, 1.<,8−0.448935, 0.839284, −1.50168, 1.27336, 1.<, 80.353902 + 0.231149 ,0.0154224 + 0.200685 , −0.557376 − 0.17437 , −0.860628 − 0.256574 , 1.<,

80.353902 − 0.231149 , 0.0154224 − 0.200685 , −0.557376 + 0.17437 ,−0.860628 + 0.256574 , 1.<, 815.2646, −10.779, −6.97231, −4.03139, 1.<<<

ComplexNumberPlot@%@@1DDD

26 Mathematica_3.nb

Manipulate@ComplexNumberPlot@Eigenvalues@RandomInteger@9, 8n, n<D êê ND,PlotRange → 88−20, 20<, 8−20, 20<<D,88n, 3<, 1, 50, 1, Appearance → 8"Labeled", "Open"<<D

n 3

3

ü Vergleich von Rechenzeiten

Eigenvalues@RandomInteger@9, 850, 50<DD; êê Timing

82.203, Null<

Eigenvalues@RandomInteger@9, 8100, 100<DD; êê Timing

864.719, Null<

im ersten Beispiel wird noch exakt gerechnet, was zu sehr langen Rechenzeiten führen kann,inallen weiteren Beispeilen ist die Rechenzeit sehr kurz und praktisch gleich

Eigenvalues@N@RandomInteger@9, 8500, 500<DDD; êê Timing

80.641, Null<

Eigenvalues@N@RandomInteger@9, 8500, 500<DDD; êê Timing

80.64, Null<

Eigenvalues@RandomReal@9, 8500, 500<DD; êê Timing

80.625, Null<

Mathematica_3.nb 27

ü Matrix Diagonalisierung

X-1. A . X diagH lHALL

dabei sind l(A) die Eigenwerte und X eine Matrix aus den Eigenvektoren

mat = K 1 23 4 O;

vals = Eigenvalues@matD

:1

2K5 + 33 O,

1

2K5 − 33 O>

vecs = Eigenvectors@matD

::−4

3+1

6K5 + 33 O, 1>, :−

4

3+1

6K5 − 33 O, 1>>

Inverse@[email protected]@vecsD êê Simplify êê MatrixForm

1

2J5 + 33 N 0

0 1

2J5 − 33 N

Lösung von Gleichungen

ü Gleichungen und Gleichungssysteme

ü Exakte Lösungen von Gleichungen

In Mathematica werden Gleichungen mit doppeltem Gleichheitszeichen definiert:

eqn1 = a x2 + b x + c == 0

c + b x + a x2 0

Algebraische Gleichungen werden bis zum Grad n=4 von Mathematica exakt gelöst mit Angabe allerLösungen.

Solve@eqn1, xD

::x →−b − b2 − 4 a c

2 a>, :x →

−b + b2 − 4 a c

2 a>>

Alle Lösungen unter Berücksichtigung von Ausnahmefällen, wie z.B. a=0 findet man mit

Reduce@eqn1, xD

a ≠ 0 && x−b − b2 − 4 a c

2 a»» x

−b + b2 − 4 a c

2 a»»

a 0 && b ≠ 0 && x −c

b»» Hc 0 && b 0 && a 0L

28 Mathematica_3.nb

Solve löst auch Systeme von Gleichungen, die als Liste eingegeben werden

eqn2 = 9a x2 + y == 1, b y − x == 15=

9a x2 + y 1, −x + b y 15=

solution2 = Solve@eqn2, 8x, y<D

::y →1

2−

1

a b2+30

b−

1 − 60 a b + 4 a b2

a b2, x →

−1 − 1 − 60 a b + 4 a b2

2 a b>,

:y → −1

2 a b2+15

b+

1 − 60 a b + 4 a b2

2 a b2, x →

−1 + 1 − 60 a b + 4 a b2

2 a b>>

Die Lösung lässt sich durch Einsetzen überprüfen

Simplify@eqn2 ê. solution2D

88True, True<, 8True, True<<

Man kann aber auch in einem Gleichungssystem Variable eliminieren, um so Gleichungen mit weniger Unbekannten zu erhalten

Eliminate@eqn2, xD

−30 a b y + a b2 y2 1 − 225 a − y

Die Funktion Solve arbeitet mit Inversen Funktionen. Sofern diese existieren, sind auch nichtalgebraische Lösungen möglich.

Solve@ArcSin@xD == a, xD

88x → Sin@aD<<

Solve@8Exp@x yD == 2, x + 2 y == 1<, 8x, y<D

Solve::ifun :Inverse functions are being used by Solve, so some solutions may not be found; use Reduce for complete

solution information. à

::x →1

2−1

2−1 + 8 Log@2D , y →

1

4K1 + −1 + 8 Log@2D O>,

:x →1

2+1

2−1 + 8 Log@2D , y →

1

4K1 − −1 + 8 Log@2D O>>

Simplify@8Exp@x yD == 2, x + 2 y == 1< ê. %D

88True, True<, 8True, True<<

Reduce@8Exp@x yD == 2, x + 2 y == 1<, 8x, y<D

C@1D ∈ Integers &&

x1

2K1 − 1 − 8 H2 π C@1D + Log@2DL O »» x

1

2K1 + 1 − 8 H2 π C@1D + Log@2DL O && y

1 − x

2

Bei höherem Polynomgrad gibt es im allgemeinen keine exakten Lösungen mehr.

SolveAx5 − 5 x2 + 1 == 0, xE

99x → RootA1 − 5 12 + 15 &, 1E=, 9x → RootA1 − 5 12 + 15 &, 2E=,9x → RootA1 − 5 12 + 15 &, 3E=, 9x → RootA1 − 5 12 + 15 &, 4E=, 9x → RootA1 − 5 12 + 15 &, 5E==

Mathematica_3.nb 29

Numerische Lösungen algebraischer Gleichungen

In solchen Fällen helfen dann die numerischen Fähigkeiten von Mathematica. Entweder NSolve[...]oder N[Solve[...]] oder Solve[...]//N . Die Lösungen sind immer noch vollständig.

NSolveAx5 − 5 x2 + 1 == 0, xE

88x → −0.837998 − 1.51442 <, 8x → −0.837998 + 1.51442 <,8x → −0.443366<, 8x → 0.451384<, 8x → 1.66798<<

ü Numerische Lösungen nichtalgebraischer Gleichungen

Transzendente Gleichungen können natürlich nicht vollständig gelöst werden, da es mitunter unendlichviele Lösungen geben kann. Hier verwendet man die numerische Funktion "FindRoot", bei der ein Startwert angegeben werden muss.Mathematica sucht dann die Lösung in der Nähe des Startwertes.

FindRoot@Cos@xD == x, 8x, 1<D

8x → 0.739085<

FindRoot@8Cos@a xD == x, −a Sin@a xD == −1<, 8x, 1<, 8a, 1<D

8x → 0.652185, a → 1.31916<

Für das nächste Beispiel gibt es unendlich viele Lösungen, Mathematica findet die Lösung, welche amnächsten zum Startwert liegt:

FindRootASinAx2E == 0, 8x, 2<E

8x → 1.77245<

PlotASinAx2E, 8x, 0, 5<E

1 2 3 4 5

-1.0

-0.5

0.5

1.0

Im nächsten Beispiel wird ein Intervall für die Suche angegeben, in dem jedoch keine Nullstelle liegt:

FindRootASinAx2E == 0, 8x, 1., .5, 1.5<E

FindRoot::reged :The point 80.5< is at the edge of the search region 80.5, 1.5< in coordinate 1 and the computed search

direction points outside the region. à

8x → 0.5<

FindRootASinAx2E == 0, 8x, 4.2, 4, 4.5<E

8x → 4.34161<

30 Mathematica_3.nb

Um eine Lösung auch im Komplexen zu finden, muss man einen komplexen Startwert angeben:

FindRootASinAx2E == π, 8x, 1<E

FindRoot::lstol :The line search decreased the step size to within tolerance specified by AccuracyGoal and PrecisionGoal but

was unable to find a sufficient decrease in the merit function. You may need morethan MachinePrecision digits of working precision to meet these tolerances. à

8x → 1.25331<

FindRootASinAx2E == π, 8x, 1 + <E

8x → 1.40864 + 0.643007 <

ü Differentialgleichungen

ü Exakte Lösungen von Differentialgleichungen

Remove@yD

DSolve@y @xD == y@xD, y@xD, xD

88y@xD → x C@1D + −x C@2D<<

Ein Anfangswertproblem mit den Startwerten y(0)=1 und y'(0)=2

DSolve@8y @xD == y@xD, y@0D == 1, y @0D == 2<, y@xD, xD

::y@xD →1

2−x I−1 + 3 2 xM>>

mit Hilfe von Ersetzungsregeln bekommt man eine funktionelle Form der Lösung, mit der man beliebig weiterrechnen und zeichnen kann

f@x_D = y@xD ê. %P1T

1

2−x I−1 + 3 2 xM

bis auf wenige Ausnahmen sind jedoch die meisten DGLs nicht analytisch lösbar,das erste Beispiel führt noch auf eine Lösung mit speziellen Funktionen

DSolve@y @xD == a Cos@xD y@xD, y@xD, xD

::y@xD → C@1D MathieuCB0, 2 a,x

2F + C@2D MathieuSB0, 2 a,

x

2F>>

das nächste Beispiel ist eine nichtlineare DGL, die keine analytische Lösung mehr besitzt

DSolveAy @xD == a Sin@y@xDD ∗ x2, y@xD, xE

DSolveAy @xD a x2 Sin@y@xDD, y@xD, xE

Mathematica_3.nb 31

ü Numerische Lösungen von Differentialgleichungen

In solchen Fällen hilft die Numerik weiter, mit der sehr viele DGLs bequem gelöst werden können. Natür-lich müssen dafür alle Parameter durch numerische Konstanten ersetzt werden und die Lösung kann nurfür einen eingeschränkten Bereich berechnet werden. Für eine graphische Darstellung der Lösung reicht dies im allgemeinen aus, ansonsten müssen die einzel-nen Bereiche nacheinander berechnet werden.

NDSolveA9y @xD == a Sin@y@xDD ∗ x2, y@0D == 1, y @0D == 1=ê. a → 1, y@xD, 8x, 0, 20<E

88y@xD → InterpolatingFunction@880., 20.<<, <>D@xD<<

Die Lösung wird intern als Interpolationspolynom gespeichert, die mit der gewünschten oder voreingestell-ten Genauigkeit für den ganzen Definitionsbereich gilt. Mit Hilfe der Ersetzungsregeln erzeugt man einenormale Funktion g(x), die man danach weiter verwenden kann, z.B. zum Plotten, Differenzieren oderIntegrieren, etc

g@x_D = y@xD ê. %@@1DD

InterpolatingFunction@880., 20.<<, <>D@xD

Plot@g@xD, 8x, 0, 20<D

5 10 15 20

1.52.02.53.03.54.0

versucht man jedoch die Lösung für wesentlich größere Intervalle zu berechnen, bekomm man eine Fehlermeldung, dass die maximale Anzahl von Schritten (10 000) erreicht ist

NDSolveA9y @xD == a Sin@y@xDD ∗ x2, y@0D == 1, y @0D == 1=ê. a → 1, y@xD, 8x, 0, 100<E

NDSolve::mxst : Maximum number of 10000 steps reached at the point x == 34.79979710410593`. à

88y@xD → InterpolatingFunction@880., 34.7998<<, <>D@xD<<

mit der Option: MaxSteps->100 000 oder auch mehr kann man auch größere Bereiche auf Kosten längererRechenzeiten und Speicherplatz berechnen

NDSolveA9y @xD == a Sin@y@xDD ∗ x2, y@0D == 1, y @0D == 1=ê. a → 1, y@xD, 8x, 0, 100<, MaxSteps → 100 000E

88y@xD → InterpolatingFunction@880., 100.<<, <>D@xD<<

beim nächsten Beispiel ist endgültig Schluss (abhängig vom vorhandenen RAM)

32 Mathematica_3.nb

NDSolveA9y @xD == a Sin@y@xDD ∗ x2, y@0D == 1, y @0D == 1=ê. a → 1, y@xD, 8x, 0, 1000<, MaxSteps → 10 000 000E êê Timing

8167.719, 88y@xD → InterpolatingFunction@880., 1000.<<, <>D@xD<<<

Euler-Lagrange-Bewegungsgleichungen

Beispiel: Federpendel im homogenen Erdfeld (in 1 Dimension)Aufstellung von Bewegungsgleichungen mit dem Euler - Lagrange - Formalismus Numerische Lösung der Bewegungsgleichungen Grafische Darstellung der Bewegung im Orts - und Phasenraum

Eine punktförmige Masse m hängt an einer Feder mit der Federkonstanten c. Die Ruhelänge der Feder seiL0 (siehe Abb. 1). Durch Einwirkung des Erdfeldes (g = 9.81 m ë sec2) wird die Feder auf die Länge L1

gespannt. Zum Zeitpunkt t = 0 wird der Körper am Ort x = L0 + x0 losgelassen und dadurch in Schwingungenversetzt. Berechne die Bewegung des Körpers und zeichne den zeitlichen Verlauf x(t) und die Darstellungim Phasenraum x† als Funktion von x.

Abb. 1 : Federpendel im homogenen Erdfeld

kinetische Energie T:

T =1

2m x @tD2

1

2m x @tD2

potentielle Energie V:

V = −m g x@tD +1

2c HL0 − x@tDL2

1

2c HL0 − x@tDL2 − g m x@tD

Mathematica_3.nb 33

Lagrange-Funktion L=T-V:

L = T − V

−1

2c HL0 − x@tDL2 + g m x@tD +

1

2m x @tD2

ü Aufstellen der Bewegungsgleichung

t∂L

∂x HtL −∂L

∂x HtL = 0

ü a) InputForm

Dt@D@L, x'@tDD, tD − D@L, x@tDD == 0

−g m − c HL0 − x@tDL + m x @tD 0

die Masse m ist eine Konstante

% ê. Dt@m, tD → 0

−g m − c HL0 − x@tDL + m x @tD 0

oder mit zusätzlicher Option für Konstanten

Dt@D@L, x'@tDD, t, Constants −> 8m, c<D − D@L, x@tDD == 0

−g m − c HL0 − x@tDL + m x @tD 0

oder man gibt m und c global das Attribut: Constant

SetAttributes@8m, c<, ConstantD

Dt@D@L, x'@tDD, tD − D@L, x@tDD == 0

−g m − c HL0 − x@tDL + m x @tD 0

wenn alle Zeitabhängigkeiten explizit angegeben sind, braucht man keine totale Ableitung, es reicht danneine partielle Ableitung nach t

D@D@L, x'@tDD, tD − D@L, x@tDD == 0

−g m − c HL0 − x@tDL + m x @tD 0

ü b) StandardForm

∂t∂x @tDL − ∂x@tDL 0

−g m − c HL0 − x@tDL + m x @tD 0

Dt@∂x @tDL, tD − ∂x@tDL 0

−g m − c HL0 − x@tDL + m x @tD 0

ü c) TraditionalForm

‚ t

∂L

∂ x¢HtL-

∂L

∂ xHtL0

−g m − c HL0 − x@tDL + m x @tD 0

34 Mathematica_3.nb

∂ t

∂L

∂ x¢HtL-

∂L

∂ xHtL0

−g m − c HL0 − x@tDL + m x @tD 0

bwgl = %;

ü Lösung der Bewegungsgleichung

In diesem einfachen Beispiel ist eine analytische Lösung möglich, wenn nicht kann jede DGL mit NDSolve[{...}, x[t], {t,0, tmax}] auch numerisch gelöst werden.

DSolve@8bwgl, x'@0D == 0, x@0D == L0 + x0<, x@tD, tD

::x@tD →

c L0 + g m − g m CosB c t

mF + c x0 CosB c t

mF

c>>

% ê. c −> m ω^2 êê PowerExpand

::x@tD →g m + L0 m ω2 − g m Cos@t ωD + m x0 ω2 Cos@t ωD

m ω2>>

lsg = % êê Simplify

::x@tD → L0 +g

ω2+ x0 −

g

ω2Cos@t ωD>>

wenn man die Lösung einer Gleichung oder DGL weiter verwenden will, sollte man sich die genaueStruktur des Objekts anschauen. Die TreeForm verwendet die Tooltips, so dass man bequem mit Hilfe der Maus die Struktur analysierenkann.Für die folgende Anwendung ist es jedoch nicht so kritisch, man kann entweder das volle Objekt lsg,oder das 1. Element lsg[[1]] oder auch das 1. Unterelement des 1. Elements lsg[[1, 1]] verwen-den. Für die rechte Seite der Regel findet man z.B. lsg[[1, 1, 2]]

Mathematica_3.nb 35

lsg êê TreeForm

List

List

Rule

x

t

Plus

L0Times

g Power

ω −2

Times

Plus

x0Times

−1 g Power

ω −2

Cos

Times

t ω

lsg

::x@tD → L0 +g

ω2+ x0 −

g

ω2Cos@t ωD>>

lsg@@1DD

:x@tD → L0 +g

ω2+ x0 −

g

ω2Cos@t ωD>

lsg@@1, 1DD

x@tD → L0 +g

ω2+ x0 −

g

ω2Cos@t ωD

lsg@@1, 1, 2DD

L0 +g

ω2+ x0 −

g

ω2Cos@t ωD

ü Einsetzen der Parameter und graphische Darstellung x(t)

parameter := 8g −> 9.81, ω −> 1, L0 −> 5, x0 −> 1<

x1 êê Clear

x1@t_D = x@tD ê. lsg@@1DD ê. parameter

14.81 − 8.81 Cos@tD

Ruhelage = x1@Pi ê 2D;

36 Mathematica_3.nb

Plot@x1@tD, 8t, 0, 10<, AxesOrigin → 80, Ruhelage<, PlotRange → 825, 0<, PlotStyle → Red,PlotLabel → "Pendelschwingung", FrameLabel → 8"t", "x H t L"<, Frame → TrueD

0 2 4 6 8 100

5

10

15

20

25

t

xHt

LPendelschwingung

ü Geschwindigkeit x(t) als Funktion der Zeit t

PlotAx1 @tD, 8t, 0, 10<, PlotLabel → "Geschwindigkeit: xHtL"E

2 4 6 8 10

-5

5

Geschwindigkeit: x° HtL

Mathematica_3.nb 37

ü Darstellung im Phasenraum 8 x(t), x†(t) < als Parameterdarstellung mit Parameter t

ParametricPlotA8x1@tD, x1 @tD<, 8t, 0, 10<, PlotStyle → Red, AxesOrigin → 8Ruhelage, 0<,PlotLabel → "Phasenraumdiagramm", FrameLabel → 9"xHtL", "xHtL"=, Frame → TrueE

10 15 20

-5

0

5

xHtL

x° HtL

Phasenraumdiagramm

bei Parametric Plots wird der AspectRatio automatisch so gesetzt, dass beide Achsen gleich skaliert werden

PlotAx1 @tD, 8t, 0, 10<, PlotLabel → "Geschwindigkeit: xHtL", AspectRatio → 1E

2 4 6 8 10

-5

5

Geschwindigkeit: x° HtL

bei Plot und einigen anderen grafischen Funktionen wird der AspectRatio auf den Goldenen Schnitt gesetzt

38 Mathematica_3.nb

GoldenRatio êê N

1.61803

Bewegungsgleichungen mit Newton II

Beispiel: Duffing-Oszillatornichtlineare Schwingungen

ü Potential V(x) = a x^2 + b x^4

Duffing@a_, b_, x_D = a x2 + b x4

a x2 + b x4

ü Beispiel: a<0 und b>0

Pot@x_D := Duffing@−2, 0.2, xD

Plot@Pot@xD, 8x, −4.2, 4.2<, Frame → True,FrameLabel → 8"x", "VHxL"<, PlotLabel → "Duffing−Oszillator",PlotStyle → Red, BaseStyle → 814, FontFamily → "CourierBold"<D

-4 -2 0 2 4-5

0

5

10

15

20

25

x

VHxL

Duffing-Oszillator

ü Kraft = -Gradient (Potential)

Kraft = −Pot @xD ê. x → x@tD

4 x@tD − 0.8 x@tD3

ü Lösung der Bewegungsgleichung: x'' = Kraft, bzw. x' = v und v' = Kraft

DSolve@8x''@tD Kraft, x'@0D == 0, x@0D x0<, x@tD, tD

DSolve::bvimp :General solution contains implicit solutions. In the boundary value problem these solutions will be

ignored, so some of the solutions will be lost. à

8<

Mathematica_3.nb 39

Für diese nichtlineare DGL ist eine analytische Lösung nicht möglich. Daher löst man solche DGLs im Allgemeinen numerisch.Bei einer numerischen Rechnung müssen natürlich auch alle Parameter und Anfangswerte, bzw. Randwerte explizit mit einem numerischen Wert angegeben werden

NDSolve@8x @tD == v@tD, v @tD == Kraft, x@0D 2, v@0D == 0<,8x@tD, v@tD<, 8t, 0, 10<D

88x@tD → InterpolatingFunction@880., 10.<<, <>D@tD,v@tD → InterpolatingFunction@880., 10.<<, <>D@tD<<

lsg = %P1T;

Plot@x@tD ê. lsg, 8t, 0, 10<, PlotStyle → RedD

2 4 6 8 10

2.1

2.2

2.3

2.4

Im nächsten Beispiel ist die Energie des Teilchen höher als die Potentialbarriere bei x=0

lsg = NDSolve@8x @tD == v@tD, v @tD == Kraft, x@0D 3.5, v@0D == 0<,8x@tD, v@tD<, 8t, 0, 10<D

88x@tD → InterpolatingFunction@880., 10.<<, <>D@tD,v@tD → InterpolatingFunction@880., 10.<<, <>D@tD<<

Plot@x@tD ê. lsg, 8t, 0, 10<, PlotStyle → RedD

2 4 6 8 10

-3-2-1

123

40 Mathematica_3.nb

ü Lösung für die Geschwindigkeit v(t)

Plot@v@tD ê. lsg, 8t, 0, 10<, PlotStyle → BlueD

2 4 6 8 10

-4

-2

2

4

ü und schließlich die Darstellung im Phasenraum (x(t), v(t))

ParametricPlot@8x@tD ê. lsg, v@tD ê. lsg<, 8t, 0, 10<, PlotStyle → MagentaD

0.2 0.4 0.6 0.8 1.0

0.2

0.4

0.6

0.8

1.0

8x@tD ê. lsg, v@tD ê. lsg< ê. t → 1

88−0.0481846<, 8−3.32179<<

bei manchen Funktionen, wie hier bei ParametricPlot muss man genau auf die Listenstruktur achten

8x@tD ê. lsg@@1DD, v@tD ê. lsg@@1DD< ê. t → 1

8−0.0481846, −3.32179<

Mathematica_3.nb 41

ParametricPlot@8x@tD, v@tD< ê. lsg, 8t, 0, 10<, PlotStyle → MagentaD

-3 -2 -1 1 2 3

-4

-2

2

4

8x@tD, v@tD< ê. lsg ê. t → 1

88−0.0481846, −3.32179<<

ü AspectRatio

ein AspectRatio ∫ 1 fällt bei anharmonischen Bewegungen nicht so sehr auf

ParametricPlot@8x@tD, v@tD< ê. lsg, 8t, 0, 10<, AspectRatio → 0.61D

-3 -2 -1 1 2 3

-4

-2

2

4

jedoch um so stärker bei harmonischen Schwingungen,hier erwartet man einen perfekten Kreis

42 Mathematica_3.nb

lsg = NDSolve@8x @tD == v@tD, v @tD == Kraft, x@0D 2.2, v@0D == 0<,8x@tD, v@tD<, 8t, 0, 10<D;

ParametricPlot@8x@tD, v@tD< ê. lsg, 8t, 0, 10<, AspectRatio → 0.61D

2.212.222.232.242.252.262.27

-0.10

-0.05

0.05

0.10

lsg = NDSolve@8x @tD == v@tD, v @tD == Kraft, x@0D 2.2, v@0D == 0<,8x@tD, v@tD<, 8t, 0, 10<D;

ParametricPlot@8x@tD, v@tD< ê. lsg, 8t, 0, 10<, AspectRatio → 1D

2.212.222.232.242.252.262.27

-0.10

-0.05

0.05

0.10

Mathematica_3.nb 43