pdf, 634K

Transcription

pdf, 634K
Einführung in Mathematica (3)
Lineare Algebra, Analysis und Bewegungsgleichungen
Michael O. Distler, Computer in der Wissenschaft, SS 2010
(Vorlage von L. Tiator)
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 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
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
2
Mathematica_3.nb
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
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
vier mal das Gleiche :
9y''''', Derivative@5D@yD, yH5L , y H5L =
9-
6
6
&, -
ð14
6
&, -
ð14
Remove@yD
6
&, -
ð14
&=
ð14
Mathematica_3.nb
3
9y''''', Derivative@5D@yD, yH5L , y H5L =
9yH5L , yH5L , yH5L , yH5L =
Die zugrunde liegende Mathematica Funktion heißt Derivative[n][f] und ist eine sogenannte "Reine Funktion" (pure function).
Aber auch für Funktionen einer Variablen kann man das Symbol der partiellen Ableitung
verwenden, dafür lautet die Funktion D[f, x], bzw. D[f, {x, n}]
f@x_D := LegendreP@5, xD
¶x f@xD
1
8
I15 - 210 x2 + 315 x4 M
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
ã Partielle Ableitungen
partielle Ableitung von x2 - y 2 nach x
¶x Ix2 - y2 M
2x
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 - y2 M
¶x¶ y
0
ã Totales Differential
ohne 2. Argument liefert Dt[f] das totale Differential df
df = Úni=1
¶f
¶xi
dxi
oder für zwei unabhängige Variablen
df =
¶f
¶x
dx +
¶f
¶y
dy
4
Mathematica_3.nb
df = Úni=1
¶f
¶xi
dxi
oder für zwei unabhängige Variablen
df =
¶f
¶x
dx +
¶f
¶y
dy
Dt@f@x, yDD
Dt@yD fH0,1L @x, yD + Dt@xD fH1,0L @x, yD
zum Beispiel
DtAx2 - y2 E
2 x Dt@xD - 2 y Dt@yD
in der "Traditional Form" :
â Ix2 - y2 M
2 x Dt@xD - 2 y Dt@yD
mit einem 2. Argument liefert Dt[f,x] 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
totales Differential von r =
r@x_, z_, t_D :=
x2 + z2
x@tD2 + z@tD2
Dt@r@x, z, tD, tD
2 x@tD x¢ @tD + 2 z@tD z¢ @tD
2
x@tD2 + z@tD2
in diesem Fall liefert auch schon die partielle Ableitung nach t das gleiche Ergebnis, da die
Zeit t bereits explizit angegeben ist.
¶t r@x, z, tD
2 x@tD x¢ @tD + 2 z@tD z¢ @tD
2
x@tD2 + z@tD2
soll eine Konstante (z.B. die Masse m) nicht mitdifferenziert werden, kann man dies als
Option angeben:
Mathematica_3.nb
5
soll eine Konstante (z.B. die Masse m) nicht mitdifferenziert werden, kann man dies als
Option angeben:
Dt@m x¢HtL, t, Constants ® 8m<D
m x¢¢ @tD
Ÿ Integrale
ã Unbestimmte Integrale
à Sin@xD âx
-Cos@xD
nicht ganz so trivial ist sicher
à HLog@xD + Sin@xDL
1
2x
1
x2
+ Exp@xD âx
H2 + ã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
2x
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 +
H2 + ãx x Cos@xD - 2 x CosIntegral@xD + 2 x ExpIntegralEi@xD +
2 x2
2 Log@xD - 2 ãx x Log@xD + 2 Sin@xD - ãx x Sin@xDL
1
allerdings kann man dies erst nach einer Vereinfachung als ursprüngliche Funktion
wiedererkennen.
Simplify@%D
I1 + ãx x2 M HLog@xD + Sin@xDL
x2
6
Mathematica_3.nb
ã Bestimmte Integrale
2
à Sin@xD âx
Π
0
Π
2
Auch uneigentliche Integrale sind möglich
à
¥
1
x2
1
âx
1
2
à ExpA-a x E âx
¥
0
Π
IfBRe@aD > 0,
2
, IntegrateAã-a x , 8x, 0, ¥<, Assumptions ® Re@aD £ 0EF
2
a
Mathematica gibt die allgemeinste Lösung des Integrals an, für Spezialfälle müssen Annahmen über die Parameter 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
Π
2
à à x Sin@yD ây âx
1
0
0
1
2
Bei bestimmten Integralen, die über einen einfachen Pol mit Vorzeichenwechsel führen,
kann auch das Cauchy Hauptwertintegral ermittelt werden.
Mathematica_3.nb
7
IntegrateB
1
x-1
, 8x, 0, 3<, PrincipalValue ® TrueF
Log@2D
ã 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
-
1
ä ã14
Π
-ä
ErfB
4
2
Log@1 + ΠD F - ä ErfiB-
%  N
2.39176 + 0. ä
%  Chop
2.39176
oder auch überhaupt kein Ergebnis
IntegrateBSinB
à SinB
1
1
0
1 + x2
%  N
0.698101
F âx
1
x2
+1
F, 8x, 0, 1<F
ä
+
2
Log@1 + ΠD F + H1 + ΠL SinB
Log@1 + ΠD F
8
Mathematica_3.nb
NIntegrateBSinB
1
x2 + 1
F, 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-stellige absolute Genauigkeit des Integrals. Höhere Genauigkeit erzielt man mit
entsprechend höherer WorkingPrecision.
NIntegrate@Sin@Sin@xDD, 8x, 0, Pi<, WorkingPrecision -> 50D
1.7864874819500523366874236012519572937614804561287
Beispiel eines 2-dim Integrals über eine Dreiecksfläche
NIntegrateAExpAx2 - y2 E, 8x, 0, 1<, 8y, 0, x<E
0.722623
auch in diesem Fall gibt es eine analytische Lösung mit hypergeometrischen Reihen
x
à à ã
1
0
1
2
x
2
-y2
ây âx
0
3
HypergeometricPFQB81, 1<, : , 2>, 1F
2
bei analytischen Lösungen braucht man natürlich keine Workingprecision
N@%, 100D
0.722622806694173614433831919217907704181307432760201523646614590518740216198890247871485„
0361886118942
Ÿ Grenzwerte
Limit@xx , x ® 0D
1
Mathematica_3.nb
lim
x®¥
9
logIx2 M
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:
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
Ÿ Reihenentwicklungen
Remove@fD
formale Taylor - Entwicklung :
Series@f@xD, 8x, x0, 3<D
f@x0D + f¢ @x0D Hx - x0L +
1
2
f¢¢ @x0D Hx - x0L2 +
1
6
fH3L @x0D Hx - x0L3 + O@x - x0D4
auch als Entwicklung in mehreren Dimensionen möglich :
10
Mathematica_3.nb
Series@g@x, yD, 8x, x0, 3<, 8y, y0, 2<D
g@x0, y0D + gH0,1L @x0, y0D Hy - y0L +
1
2
gH0,2L @x0, y0D Hy - y0L2 + O@y - y0D3 +
gH1,0L @x0, y0D + gH1,1L @x0, y0D Hy - y0L +
1
2
1
6
gH2,0L @x0, y0D +
1
gH3,0L @x0, y0D +
1
2
6
1
2
gH1,2L @x0, y0D Hy - y0L2 + O@y - y0D3 Hx - x0L +
gH2,1L @x0, y0D Hy - y0L +
gH3,1L @x0, y0D Hy - y0L +
gH2,2L @x0, y0D Hy - y0L2 + O@y - y0D3 Hx - x0L2 +
1
4
1
12
gH3,2L @x0, y0D Hy - y0L2 + O@y - y0D3 Hx - x0L3 +
O@x - x0D4
Sinus Taylorreihe
Series@Sin@xD, 8x, 0, 8<D
x3
x-
x5
+
6
x7
+ O@xD9
120
5040
so wird aus einer Reihe eine normale Funktion :
f0@x_D = %  Normal
x3
x-
x5
+
6
x7
-
120
5040
Sinus Taylorreihe um Π/2
f1@x_D = Series@Sin@xD, 8x, Π  2, 8<D  Normal  Simplify
1
18
HΠ - 2 xL +
2
1
384
HΠ - 2 xL 4
HΠ - 2 xL6
46 080
I+
Π
2
8
+ xM
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-4 E &
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
Mathematica_3.nb
11
Plot@Tooltip@8Sin@xD, f0@xD, f1@xD, f2@xD<D,
8x, 0, 2 Π<, PlotStyle ® 8Red, Blue, Green, Cyan<D
1
-1
-2
-3
-4
-5
-6
1
2
3
4
5
6
im nächsten Beispiel ist die Funktion Tootip etwas übersichtlicher :
LogPlot@8Tooltip@Abs@f0@xD - Sin@xDD, "f0-Sin"D,
Tooltip@Abs@f1@xD - Sin@xDD, "f1-Sin"D<,
8x, 0, 2 Π<, PlotStyle ® 8Blue, Green<D
0.01
10-6
10-10
10-14
1
2
3
4
5
6
Plot@8f0@xD, Sin@xD<, 8x, 0, Π<D
1.0
0.8
0.6
0.4
0.2
0.5
1.0
1.5
2.0
2.5
3.0
im nächsten Beispiel vergleichen wir eine Entwicklung um Null mit einer asymptotischen
Entwicklung um Unendlich
12
Mathematica_3.nb
ArcTan@xD Sin@xD2
H1 + x2 L
h0@x_D :=
3
h1@x_D = Series@h0@xD, 8x, 0, 10<D  Normal
x3 -
11 x5
376 x7
+
14 453 x9
-
3
45
945
h2@x_D = Series@h0@xD, 8x, ¥, 10<D  Normal
3Π
3Π
10
+
x10
3
x9
2
Π
1
-
x8
+
x7
Sin@xD2
2 x6
Plot@Tooltip@8h0@xD, h1@xD, h2@xD<D, 8x, 0, 4<, PlotRange ® 0.2,
PlotStyle ® 8Red, Blue, Green<D
0.2
0.1
1
2
3
4
- 0.1
- 0.2
LogPlot@Abs@Hh0@xD - h2@xDL  h0@xDD, 8x, 2, 100<D
0.1
0.001
10-5
10-7
0
20
40
60
80
100
Mathematica_3.nb
13
Series@Gamma@1 + xD, 8x, ¥, 10<D
J-1-LogB FN x+OB F
ã
1
1
x
x
11
2Π
Π
Π
2
2
x +
Π
5 246 819
2
+
25 920 x52
+
1 244 160 x72
Π
4 483 131 259
2
-
104 509 440 x92
37 623 398 400 x112
Π
432 261 921 612 371
451 480 780 800 x132
2
+
43 342 154 956 800 x152
Π
2
+
257 452 400 443 392 000 x172
Π
-
6 232 523 202 521 089
2
2
-
534 703 531
2
Π
571
2
144 x32
x
Π
139
+
6
163 879
Π
43 252 003 274 489 856 000 x192
1 212
+ OB F
x
%  N  Expand  Chop
J-1.-1. LogB FN x+OB F
ã
1
1
x
x
11
0.208886
x +
2.50663
0.00870357
+
x
0.000174783
0.00672109
-
0.00148434
-
x112
+
x72
0.00210431
+
x132
0.00196529
+
x52
0.000129638
-
0.000575201
-
x32
x92
0.0001806
+
x152
x172
x192
1 212
+ OB F
x
Series@SphericalBesselJ@3, xD, 8x, 0, 10<D  Normal
x3
x5
x7
105
x9
+
-
1890
83 160
6 486 480
Bei der folgenden Reihenentwicklung um den Pol der Tangensfunktion bei Π/2 bekommt
man als Ergebnis eine Laurentreihe
Series@Tan@xD, 8x, Π  2, 10<D  Normal
1
-
Π
2
Π
1
+
+x
3
Π
1
+x +
2
45
3
+x
2
Π
2
+
945
+x
2
I-
5
+
Π
2
2 I-
7
+ xM
4725
+
Π
2
9
+ xM
93 555
Ÿ Laurentreihen und Residuen
Das Residuum einer Funktion ist der -1. Koeffizient ihrer Laurentreihe
(Hat f in a eine Polstelle 1. Ordnung, dann gilt: Resa f = limz®a Hz - aL f HzL )
laurent =
a@-2D
Hx -
a@-2D
Hx - x0L2
a@-1D
+
x0L2
x - x0
+
a@-1D
x - x0
+ a@0D + Hx - x0L a@1D
+ a@0D + a@1D Hx - x0L
14
Mathematica_3.nb
Residue@laurent, 8x, x0<D
a@-1D
zum Beispiel für eine gebrochen rationale Funktion
1
x Hx - 1L Hx - 2L2
quot1 =
1
H-2 + xL2 H-1 + xL x
Series@quot1, 8x, 0, 5<D;
Residue@quot1, 8x, 0<D
1
4
Series@quot1, 8x, 1, 5<D;
Residue@quot1, 8x, 1<D
1
Series@quot1, 8x, 2, 5<D;
Residue@quot1, 8x, 2<D
3
4
oder für eine beliebige singuläre Funktion
SeriesB
1
1
+
x3
1
Sin@xD3
2x
457 x3
17 x
+
, 8x, 0, 5<F
+
120
ResidueB
3287 x5
+
15 120
1
Sin@xD3
+ O@xD6
604 800
, 8x, 0<F
1
2
im Folgenden handelt es sich um eine wesentliche Singularität am Ort x = 0
in diesem Fall existiert weder eine Laurentreihe noch ein Residuum
Mathematica_3.nb
15
-
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
a
b
c
vec2 = Array@a, 3D
8a@1D, a@2D, a@3D<
Ÿ Matrizen
Erzeugung einer 2x2 Matrix mit Palette
mat1 = K
a b
O
c d
88a, b<, 8c, d<<
Erzeugung einer beliebigen NxM Matrix mit Palette
mit Ctrl Enter erzeugt man eine neue Zeile
mit Ctrl , (Komma) erzeugt man eine neue Spalte
mat2 =
a1 a2 a3 a4
b1 ƒ ƒ ƒ
b2 ƒ ƒ ƒ
ƒ ƒ ƒ ƒ
b4 ƒ ƒ ƒ
88a1, a2, a3, a4<, 8b1, ƒ, ƒ, ƒ<, 8b2, ƒ, ƒ, ƒ<, 8ƒ, ƒ, ƒ, ƒ<, 8b4, ƒ, ƒ, ƒ<<
Erzeugung einer symbolischen Matrix mit Array
16
Mathematica_3.nb
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, 3D
A@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,3
x2,1 x2,2 x2,3
x3,1 x3,2 x3,3
aber Vorsicht bei Indizes: Die indizierte Größe ist nicht unabhängig von der normalen Variablen.
8x = 2, x1,2 = 0, x3 = 5<
82, 0, 5<
Array@Subscript@x, ð1, ð2D &, 83, 3<D  MatrixForm
21,1 0 21,3
22,1 22,2 22,3
23,1 23,2 23,3
Remove@xD
natürlich kann eine Matrix auch mit dem Befehl Table[...] erzeugt werden:
mat4 = Table@ai,j , 8i, 1, 4<, 8j, 1, 3<D  MatrixForm
a1,1
a2,1
a3,1
a4,1
a1,2
a2,2
a3,2
a4,2
a1,3
a2,3
a3,3
a4,3
Vorsicht: //MatrixForm ist wie auch //TableForm etc eine Darstellungsform und sollte nicht in die
Definition einer Größe aufgenommen werden:
Mathematica_3.nb
17
mat4@@2, 2DD
a1,1 a1,2 a1,3
Part::partw : Part 2 of
a2,1 a2,2 a2,3
a3,1 a3,2 a3,3
does not exist. ‡
a4,1 a4,2 a4,3
a1,1
a2,1
a3,1
a4,1
a1,2
a2,2
a3,2
a4,2
a1,3
a2,3
a3,3
a4,3
P2, 2T
besser:
Hmat5 = Table@bi,j , 8i, 1, 4<, 8j, 1, 3<DL  MatrixForm
b1,1
b2,1
b3,1
b4,1
b1,2
b2,2
b3,2
b4,2
b1,3
b2,3
b3,3
b4,3
Ÿ Einheitsmatrix
IdentityMatrix@5D  MatrixForm
1
0
0
0
0
0
1
0
0
0
0
0
1
0
0
0
0
0
1
0
0
0
0
0
1
Ÿ Diagonalmatrix
DiagonalMatrix@81, 2, 3, 4, 5<D  MatrixForm
1
0
0
0
0
0
2
0
0
0
0
0
3
0
0
0
0
0
4
0
0
0
0
0
5
auch für sub- und superdiagonale Matrizen
DiagonalMatrix@8a, b<, -1D  MatrixForm
0 0 0
a 0 0
0 b 0
Ÿ Operationen auf Matrizen und Vektoren
ã Multiplikationen (mit normalem Punkt: . )
diese beiden Matrizen passen nicht zusammen:
18
Mathematica_3.nb
mat1.mat5
Dot::dotsh :
Tensors 88a, b<, 8c, d<< and 88b1,1 , b1,2 , b1,3 <, 8b2,1 , b2,2 , b2,3 <, 8b3,1 , b3,2 , b3,3 <, 8b4,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, 3D
c 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<
:K
a b
O,
c d
A@1, 1D A@1, 2D A@1, 3D
,
A@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, 3D
>
c 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
K
ax+by
O
cx+dy
vec.mat1  MatrixForm
K
ax+cy
O
bx+dy
Skalarprodukt
81, 2<.83, 4<
11
Vektorprodukt
Mathematica_3.nb
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
Matrizen schreiben:
vcolumn = 88x<, 8y<<
88x<, 8y<<
%  MatrixForm
K
x
O
y
vline = 88x, y<<
88x, y<<
%  MatrixForm
Hx yL
mat1.vcolumn  MatrixForm
K
ax+by
O
cx+dy
vline.mat1  MatrixForm
Hax+cy bx+dy 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:
19
20
Mathematica_3.nb
Transpose@vlineD  MatrixForm
K
x
O
y
Transpose@vcolumnD  MatrixForm
Hx yL
ã Norm und Normierung
v = 81, 2, 3<
81, 2, 3<
Norm@vD
14
vn = Normalize@vD
:
1
2
,
14
3
,
7
>
14
%  Norm
1
ã 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
Mathematica_3.nb
21
Inverse Matrix
Inverse@c1D  MatrixForm
1
3
1
1
3
3
-
ä
3
+
-
ä
3
1
3
Spur (Tr[...]) und Determinante (Det[...])
c1  Tr
c1  Det
0
-3
Ÿ Lineare Gleichungssysteme
mA = RandomInteger@5, 83, 3<D
883, 3, 5<, 82, 0, 5<, 82, 1, 5<<
vb = RandomInteger@8-2, 2<, 3D
8-2, -1, -2<
Ÿ Lösung mit Inverser Matrix
vx = [email protected]
82, -1, -1<
Ÿ Lösung mit LinearSolve
vx = LinearSolve@mA, vbD
82, -1, -1<
Ÿ Lösung mit Solve
vx = 8x, y, z<
8x, y, z<
22
Mathematica_3.nb
eq1 = mA.vx Š vb
83 x + 3 y + 5 z, 2 x + 5 z, 2 x + y + 5 z< Š 8-2, -1, -2<
Solve@eq1, 8x, y, z<D
88x ® 2, y ® -1, z ® -1<<
bei älteren Mathematica Versionen müssen Vektorgleichungen zuerst in die Standardform umgewandelt werden
Thread@eq1D
83 x + 3 y + 5 z Š -2, 2 x + 5 z Š -1, 2 x + y + 5 z Š -2<
Ÿ Eigenwert Gleichungen
M . v = Λ v bzw. (M - ΛI) . v = 0
dabei ist Λ ein Eigenwert und v ein Eigenvektor. Eine 3x3 Matrix hat 3 Eigenwerte und 3 dazugehörige Eigenvektoren.
Ÿ triviales Beispiel
HmA = DiagonalMatrix@8a, b, c<DL  MatrixForm
a 0 0
0 b 0
0 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 einmal
berechnen:
Eigensystem@mAD
88a, b, c<, 881, 0, 0<, 80, 1, 0<, 80, 0, 1<<<
Mathematica_3.nb
23
Ÿ ein nicht so triviales Beispiel
HmB = Array@Subscript@b, ð1, ð2D &, 82, 2<DL  MatrixForm
b1,1 b1,2
b2,1 b2,2
Eigensystem@mBD
::
Kb1,1 + b2,2 -
b21,1 + 4 b1,2 b2,1 - 2 b1,1 b2,2 + b22,2 O,
Kb1,1 + b2,2 +
b21,1 + 4 b1,2 b2,1 - 2 b1,1 b2,2 + b22,2 O>,
::-
-b1,1 + b2,2 +
b21,1 + 4 b1,2 b2,1 - 2 b1,1 b2,2 + b22,2
:-
-b1,1 + b2,2 -
1
2
1
2
, 1>,
2 b2,1
b21,1 + 4 b1,2 b2,1 - 2 b1,1 b2,2 + b22,2
, 1>>>
2 b2,1
mit numerischen Matrizen ist das alles natürlich kein Problem
HmC = RandomInteger@9, 85, 5<DL  MatrixForm
8
3
1
4
1
5
2
8
1
4
9
1
9
6
2
1
4
9
9
6
4
0
7
6
7
Eigensystem@mCD  N
8824.0259, 0.858169 + 4.81369 ä, 0.858169 - 4.81369 ä, 4.62887 + 0.337358 ä, 4.62887 - 0.337358 ä<,
881.55564, 0.58202, 1.82654, 1.58152, 1.<,
8-1.30354 - 0.80898 ä, -0.143431 + 1.52198 ä, 1.22674 - 0.92649 ä, -1.11967 + 0.231288 ä, 1.<,
8-1.30354 + 0.80898 ä, -0.143431 - 1.52198 ä, 1.22674 + 0.92649 ä, -1.11967 - 0.231288 ä, 1.<,
84.29741 + 4.40539 ä, 1.92098 + 2.0171 ä, -3.13687 - 2.47664 ä, -1.34646 - 1.1972 ä, 1.<,
84.29741 - 4.40539 ä, 1.92098 - 2.0171 ä, -3.13687 + 2.47664 ä, -1.34646 + 1.1972 ä, 1.<<<
ev = Eigenvalues@mCD  N
824.0259, 0.858169 + 4.81369 ä, 0.858169 - 4.81369 ä, 4.62887 + 0.337358 ä, 4.62887 - 0.337358 ä<
ComplexNumberPlot@evD
4
2
-2
-4
5
10
15
20
24
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
6
6
[email protected], -5.00283 + 4.8909 ä, -5.00283 - 4.8909 ä, -4.8847,
3.67298 + 0.77275 ä, 3.67298 - 0.77275 ä<, PlotRange ® 88-20, 20<, 8-20, 20<<D
Die Rechenzeit ist deutlich kürzer, wenn Mathematica das Eigenwertproblem numerisch und nicht
exakt zu lösen versucht:
Eigenvalues@RandomInteger@9, 875, 75<DD;  Timing
85.188, Null<
Eigenvalues@N@RandomInteger@9, 875, 75<DDD;  Timing
80.015, Null<
Eigenvalues@N@RandomInteger@9, 8500, 500<DDD;  Timing
80.438, Null<
Eigenvalues@RandomReal@9, 8500, 500<DD;  Timing
80.406, Null<
Ÿ Matrix Diagonalisierung
X -1. A . X ‡ diagH ΛHALL
mat =
1 2
;
3 4
vals = Eigenvalues@matD
:
1
2
J5 +
33 N,
1
2
J5 -
33 N>
Mathematica_3.nb
25
vecs = Eigenvectors@matD
::-
4
1
+
3
6
J5 +
33 N, 1>, :-
4
1
+
3
6
J5 -
33 N, 1>>
Vorsicht: Mathematica liefert die Eigenvektoren als Zeilenvektoren. Um Spaltenvektoren zu erhalten, muss die Matrix mit den Eigenvektoren noch transponiert werden.
Inverse@[email protected]@vecsD  Simplify 
MatrixForm
1
2
J5 +
33 N
0
0
1
2
J5 -
33 N
ã Diagonalisierung singulärer Matrizen
Auch singuläre Matrizen sind u.U. diagonalisierbar:
A=
1 -1 -1
2 -1 -3 ; Inverse@AD
2 0 -4
8Λ, Xt< = Eigensystem@AD;
HX = Transpose@XtDL  MatrixForm
HL = DiagonalMatrix@ΛDL  MatrixForm
Inverse::sing : Matrix 881, -1, -1<, 82, -1, -3<, 82, 0, -4<< is singular. ‡
Inverse@881, -1, -1<, 82, -1, -3<, 82, 0, -4<<D
1 3 2
2 4 1
2 2 1
-3 0 0
0 -1 0
0 0 0
Mindestens einer der Eigenwerte ist in diesem Fall gleich Null:
[email protected]  MatrixForm
-3 0 0
0 -1 0
0 0 0
Probe:
A = X . diagH ΛHALL . X -1
X.L.Inverse@XD  MatrixForm
1 -1 -1
2 -1 -3
2 0 -4
26
Mathematica_3.nb
Clear@A, L, X, Xt, ΛD
ã Invertierbare Matrizen sind nicht notwendig auch diagonalisierbar
A=
1 0 0
2 -1 0 ; Inverse@AD
2 3 -1
8Λ, Xt< = Eigensystem@AD;
HX = Transpose@XtDL  MatrixForm
HL = DiagonalMatrix@ΛDL  MatrixForm
881, 0, 0<, 82, -1, 0<, 88, -3, -1<<
0 0 2
0 0 2
1 0 5
-1 0 0
0 -1 0
0 0 1
Der doppelte Eigenwert zeigt das Problem an: Matrix X ist singulär und damit nicht invertierbar.
Inverse@XD
Inverse::sing : Matrix 880, 0, 2<, 80, 0, 2<, 81, 0, 5<< is singular. ‡
Inverse@880, 0, 2<, 80, 0, 2<, 81, 0, 5<<D
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 aller Lösungen.
Solve@eqn1, xD
::x ®
-b -
b2 - 4 a c
2a
>, :x ®
-b +
b2 - 4 a c
2a
>>
Alle Lösungen unter Berücksichtigung von Ausnahmefällen, wie z.B. a=0 findet man mit
Mathematica_3.nb
27
Alle Lösungen unter Berücksichtigung von Ausnahmefällen, wie z.B. a=0 findet man mit
Reduce@eqn1, xD
b2 - 4 a c
-b a ¹ 0 && x Š
2a
c
a Š 0 && b ¹ 0 && x Š b
ÈÈ x Š
-b +
b2 - 4 a c
2a
ÈÈ
ÈÈ Hc Š 0 && b Š 0 && a Š 0L
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
1
:y ® -
+
a b2
2
1 - 60 a b + 4 a b2
30
-
1
-
2 a b2
+
b
2ab
1 - 60 a b + 4 a b2
15
1 - 60 a b + 4 a b2
a b2
b
+
-1 , x®
-1 +
1 - 60 a b + 4 a b2
, x®
2 a b2
2ab
>,
>>
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<<
28
Mathematica_3.nb
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 ®
:x ®
1
1
-
2
1
+
2
1
ä
-1 + 8 Log@2D , y ®
2
1
4
1
ä
-1 + 8 Log@2D , y ®
2
4
J1 + ä
-1 + 8 Log@2D N>,
J1 - ä
-1 + 8 Log@2D N>>
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 &&
1
1
x Š K1 - 1 - 8 H2 ä Π C@1D + Log@2DL O ÈÈ x Š K1 +
2
2
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==
ã 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 unendlich viele 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<
Mathematica_3.nb
29
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 am nächsten zum Startwert liegt:
FindRootASinAx2 E == 0, 8x, 2<E
8x ® 1.77245<
PlotASinAx2 E, 8x, 0, 5<E
1.0
0.5
1
2
3
4
5
- 0.5
- 1.0
Im nächsten Beispiel wird ein Intervall für die Suche angegeben, in dem jedoch keine
Nullstelle liegt:
FindRootASinAx2 E == 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<
FindRootASinAx2 E == 0, 8x, 4.2, 4, 4.5<E
8x ® 4.34161<
Um eine Lösung auch im Komplexen zu finden, muss man einen komplexen Startwert
angeben:
30
Mathematica_3.nb
FindRootASinAx2 E == Π, 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 more
than MachinePrecision digits of working precision to meet these tolerances. ‡
8x ® 1.25331<
FindRootASinAx2 E == Π, 8x, 1 + ä<E
8x ® 1.40864 + 0.643007 ä<
Ÿ Differentialgleichungen
ã Exakte Lösungen von Differentialgleichungen
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 x M>>
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 x M
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
2
F + C@2D MathieuSB0, 2 a,
x
2
F>>
das nächste Beispiel ist eine nichtlineare DGL, die keine analytische Lösung mehr besitzt
Mathematica_3.nb
31
DSolveAy²@xD == a Sin@y@xDD * x2 , y@xD, xE
DSolveAy¢¢ @xD Š a x2 Sin@y@xDD, y@xD, xE
ã 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ürlich müssen dafür alle Parameter durch numerische Konstanten ersetzt
werden und die Lösung kann nur für einen eingeschränkten Bereich berechnet werden.
Für eine graphische Darstellung der Lösung reicht dies im allgemeinen aus, ansonsten
müssen die einzelnen 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 voreingestellten Genauigkeit für den ganzen Definitionsbereich gilt. Mit Hilfe der
Ersetzungsregeln erzeugt man eine normale Funktion g(x), die man danach weiter verwenden kann, z.B. zum Plotten, Differenzieren oder Integrieren, etc
g@x_D = y@xD . %@@1DD
InterpolatingFunction@880., 20.<<, <>D@xD
Plot@g@xD, 8x, 0, 20<D
4.0
3.5
3.0
2.5
2.0
1.5
5
10
15
20
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
32
Mathematica_3.nb
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ängerer Rechenzeiten 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
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
No more memory available.
Mathematica kernel has shut down.
Try quitting other applications and then retry.
Euler-Lagrange-Bewegungsgleichungen
Beispiel: Federpendel im homogenenErdfeld (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 sei L0 (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 Schwingungen versetzt. Berechne die Bewegung des Körpers und zeichne den zeitlichen Verlauf x(t) und die
Darstellung im Phasenraum x als Funktion von x.
Mathematica_3.nb
33
Abb. 1 : Federpendel im homogenen Erdfeld
T=
1
2
m x¢ @tD2
m x¢ @tD2
1
2
V = - m g x@tD +
1
2
c HL0 - x@tDL2
c HL0 - x@tDL2 - g m x@tD
1
2
L=T-V
1
2
c HL0 - x@tDL2 + g m x@tD +
1
2
m x¢ @tD2
Ÿ Aufstellen der Bewegungsgleichung
â
¶L
ât ¶x¢ HtL
-
ã a) InputForm
Dt@D@L, x'@tDD, tD - D@L, x@tDD == 0
-g m - c HL0 - x@tDL + Dt@m, tD x¢ @tD + m x¢¢ @tD Š 0
% . Dt@m, tD ® 0
-g m - c HL0 - x@tDL + m x¢¢ @tD Š 0
oder mit zusätzlicher Option für Konstanten
¶L
¶x HtL
=0
34
Mathematica_3.nb
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
eine 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 H¶x¢ @tD LL - ¶x@tD L == 0
-g m - c HL0 - x@tDL + m x¢¢ @tD Š 0
ã c) TraditionalForm
â J ¶x¢ HtL N
¶L
ât
-
¶L
¶ xHtL
== 0
-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
m
c
F + c x0 CosB
c t
m
F
>>
Mathematica_3.nb
35
% . 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
g
+ x0 -
Ω2
Cos@t ΩD>>
Ω2
wenn man die Lösung einer Gleichung oder DGL weiter verwenden will, sollte man sich die genaue
Struktur des Objekts anschauen. 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]] verwenden. Für die rechte Seite der Regel findet man z.B.
lsg[[1, 1, 2]]
lsg  TreeForm
lsg@@1DD
:x@tD ® L0 +
g
g
+ x0 -
Ω2
Cos@t ΩD>
Ω2
lsg@@1, 1, 2DD
g
L0 +
g
+ x0 -
Ω2
Cos@t ΩD
Ω2
Ÿ Einsetzen der Parameter und graphische Darstellung x(t)
parameter := 8g -> 9.81, Ω -> 1, L0 -> 5, x0 -> 1<
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
Pendelschwingung
25
xHtL
20
15
10
5
0
0
2
4
6
8
10
t
Ÿ Darstellung im Phasenraum x(t) als Funktion von x(t)
Plot@x1¢ @tD, 8t, 0, 10<, PlotLabel ® "Geschwindigkeit: x HtL"D
Geschwindigkeit: x HtL
5
2
-5
4
6
8
10
Mathematica_3.nb
37
Ÿ Darstellung im Phasenraum {x(t), x(t)} als Parameterdarstellung mit Parameter t
ParametricPlot@8x1@tD, x1¢ @tD<, 8t, 0, 10<,
PlotStyle ® Red, AspectRatio ® Automatic,
AxesOrigin ® 8Ruhelage, 0<, PlotLabel ® "Phasenraumdiagramm",
FrameLabel ® 8"xHtL", "x HtL"<, Frame ® TrueD
Phasenraumdiagramm
xHtL
5
0
-5
10
15
xHtL
20
Bewegungsgleichungenmit Newton II
Beispiel: Duffing-Oszillator
nichtlineare 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
38
Mathematica_3.nb
Plot@Pot@xD, 8x, -4.2, 4.2<, Frame ® True,
FrameLabel ® 8"x", "VHxL"<, PlotLabel ® "Duffing-Oszillator",
PlotStyle ® Red, BaseStyle ® 814, FontFamily ® "CourierBold"<D
Duffing-Oszillator
25
VHxL
20
15
10
5
0
-5
-4
-2
0
x
2
4
Ÿ 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<
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;
Mathematica_3.nb
39
Plot@x@tD . lsg, 8t, 0, 10<, PlotStyle ® RedD
2.4
2.3
2.2
2.1
2
4
6
8
10
Im nächsten Beispiel ist die Energie des Teilchen höher als die Potentialbarriere bei x=0
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<<
lsg = %P1T;
Plot@x@tD . lsg, 8t, 0, 10<, PlotStyle ® RedD
3
2
1
-1
-2
-3
2
4
6
8
10
40
Mathematica_3.nb
Ÿ Lösung für die Geschwindigkeit v(t)
Plot@v@tD . lsg, 8t, 0, 10<, PlotStyle ® BlueD
4
2
2
4
6
8
10
-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
4
2
-3
-2
-1
1
-2
-4
2
3