Mathematische Methoden mit Mathematica II

Beispiele

Rechnen mit Vektoren

Ein Vektor ist ein eindimensionales Feld

A={0,2,1}

Vektoren lassen sich addieren/subtrahieren

A={0,2,1};
B={2,-1,0};
A+B
A-B

Skalarprodukt

Dot[A,B]
A.B

... und NICHT!

A * B

Kreuzprodukt

Cross[A,B]
A \[Cross] B

Betrag (Norm) eines Vektors

Norm[A]
(Sqrt[A.A])

Spatprodukt

A={ax,ay,az};
B={bx,by,bz};
F={fx,fy,fz};

(A\[Cross]B).F
(B\[Cross]A).F

Darstellung von Vektoren

Graphische Darstellung von Vektoren durch Pfeile

Vec=Arrow[{{0,0,0},{1,2,0.4}}];
Show[{Graphics3D[{Vec}]},Axes->True,AxesOrigin->{0,0,0}]

Funktion für Vektor definieren

Vector[A_]:=Arrow[Tube[{{0,0,0},A},0.01]];
Show[{Graphics3D[{Thick,Red,Arrowheads[0.1],Vector[{1,1,1}]}]},Axes->True,AxesOrigin->{0,0,0}]

Addtition

A={0,2,1};
B={2,-1,0};
Show[{Graphics3D[{Blue,Vector[A],Green,Vector[B],Thick,Red,Vector[A+B]}]},Axes->True,AxesOrigin->{0,0,0}]

Kreuzprodukt

A={0,2,1};
B={2,-1,0};
Show[{Graphics3D[{Blue,Vector[A],Green,Vector[B],Thick,Red,Vector[A\[Cross]B]}]},Axes->True,AxesOrigin->{0,0,0}]

Koordinatenlinien und -flächen

Kartesische Koordinaten

r[x_,y_,z_]:={x,y,z}

l1=ParametricPlot3D[r[x,0,0],{x,-2,2}];
l2=ParametricPlot3D[r[0,y,0],{y,-2,2}];
l3=ParametricPlot3D[r[0,0,z],{z,-2,2}];
Show[l1,l2,l3,PlotRange->All]

f1=ParametricPlot3D[r[x,y,0],{x,-2,2},{y,-2,2}];
f2=ParametricPlot3D[r[0,y,z],{y,-2,2},{z,-2,2}];
f3=ParametricPlot3D[r[x,0,z],{x,-2,2},{z,-2,2}];
Show[f1,f2,f3,PlotRange->All]

Zylinderkoordinaten

r[ρ_,φ_,z_]:={ρ Cos[φ],ρ Sin[φ],z}

l1=ParametricPlot3D[r[ρ,π/4,2],{ρ,0,2}];
l2=ParametricPlot3D[r[2,φ,1],{φ,0,2π}];
l3=ParametricPlot3D[r[2,π/8,z],{z,-2,2}];
Show[{l1,l2,l3},PlotRange->All]

f1=ParametricPlot3D[r[ρ,φ,2],{ρ,0,2},{φ,0,2π}];
f2=ParametricPlot3D[r[ρ,3π/2,z],{ρ,0,3},{z,-4,4}];
f3=ParametricPlot3D[r[1.5,φ,z],{φ,0,2π},{z,-3,3}];
Show[{f1,f2,f3},PlotRange->All]

Kugelkoordinaten

r[ρ_,φ_,θ_]:={ρ Cos[φ]Sin[θ],ρ Sin[φ]Sin[θ],ρ Cos[θ]}

l1=ParametricPlot3D[r[ρ,π/4,π/2],{ρ,0,2}];
l2=ParametricPlot3D[r[2,φ,1],{φ,0,2π}];
l3=ParametricPlot3D[r[2,π/8,θ],{θ,0,π}];
Show[{l1,l2,l3},PlotRange->All]

f1=ParametricPlot3D[r[ρ,φ,π/2],{ρ,0,2},{φ,0,2π}];
f2=ParametricPlot3D[r[2,φ,θ],{φ,0,2π},{θ,0,π},PlotStyle->Opacity[0.2]];
f3=ParametricPlot3D[r[ρ,π/8,θ],{ρ,0,2},{θ,0,π}];
Show[{f1,f2,f3},PlotRange->All]

Bahnkurven

Graphische Darstellung von Kurven mit Hilfe eines Parameter (entweder Zeit t oder Bogenlänge s)

Beispiel Schiefer Wurf

r[t_]:={{vx*t},{1/2 *(-g) *t^2 +vy *t +h0}}

vx=5;vy=2;g=10;h0=2.5;
ParametricPlot[r[t],{t,0,1}]
Clear[vx,vy,g,h0]

Bahn in 3 Dimensionen

r[s_]:={s*Cos[s],s*Sin[s],s}
ParametricPlot3D[r[s],{s,0,8π}]

Clear[R,ω,b];
r[t_]:={R*Cos[ω t],R*Sin[ω t],b ω t }
pb=Assuming[{R=2;ω=2 π;b=.2;},ParametricPlot3D[r[t],{t,0,5}]]

Berechnung von Geschwindigkeit und Beschleunigung

Clear[R,ω,b,as,vs];
v[t_]=D[r[t],t]
a[t_]=D[v[t],t]

Show[
Assuming[{R=2;ω=2 π;b=.2;vs=.1,as=0.01;},
Graphics3D[{Thick,
Table[Arrow[{r[t],r[t]+v[t]*vs}],{t,0,5,5/17}],
Red,
Table[Arrow[{r[t],r[t]+a[t]*as}],{t,0,5,5/17}]
}]],pb]

Begleitendes Dreibein

Clear[ω,R,λ]

r[t_]:={R Cos[ω t],R Sin[ω t],Exp[λ t]-1}

r[t_]:={R Cos[ω t],R Sin[ω t],-(t-2)^2+4}

v[t_]=D[r[t],t];
vabs[t_]=Sqrt[v[t].v[t]];
a[t_]=D[v[t],t];
aabs[t_]=D[vabs[t],t];
vt[t_]=v[t]/vabs[t];
vn[t_]=Normalize[D[v[t],t]-aabs[t]vt[t]];
vb[t_]=Normalize[Cross[vt[t],vn[t]]];
rn[t_]=1/Norm[(D[v[t],t]-aabs[t]vt[t])/(v[t].v[t])];

p1=Assuming[{ω=2π;R=1;λ=0.5;},ParametricPlot3D[r[t],{t,0,4}]];
Manipulate[Assuming[{ω=2π;R=1;λ=0.5;},Show[p1,Graphics3D[{Thick,Arrow[{{0,0,0},r[t]}],Green,Arrow[{r[t],r[t]+vt[t]}],Blue,Arrow[{r[t],r[t]+vn[t]}],Red,Arrow[{r[t],r[t]+vb[t]}],Orange,Opacity[0.2],EdgeForm[],Cylinder[{{r[t]+rn[t]*vn[t],r[t]+rn[t]*vn[t]+vb[t]/1000}},rn[t]]},Lighting->"Neutral"],PlotRange->{{-R-1,R+1},{-R-1,R+1},{-1,8}},Boxed->False]],{t,0,4}]

Darstellung von Feldern

Skalare Felder

Clear[r,V];
r[x_,y_]:={x,y}
V[r_]:=(V0/(1+(((((n.r)/a)))^2)))
Assuming[{V0=1;n={1,1};a=0.5;},ContourPlot[V[r[x,y]],{x,-2,2},{y,-2,2},ContourShading->None]]

Assuming[{V0=1;n={1,1};a=0.5;},ContourPlot[V[r[x,y]]==0.5,{x,-2,2},{y,-2,2},ContourShading->None]]

Assuming[{V0=1;n={1,1};a=0.5;},ContourPlot[V[r[x,y]],{x,-2,2},{y,-2,2},ColorFunction->"Rainbow"]]

Die Darstellung in 3D  erfordert oft Geduld

Clear[r,V];
r[x_,y_,z_]:={x,y,z}
V[r_]:=(V0/(1+(((((n.r)/a)))^2)))
Assuming[{V0=1;n={1,1,1};a=0.5;},ContourPlot3D[V[r[x,y,z]]==0.5,{x,-1,1},{y,-1,1},{z,-1,1}]]

Vektorfelder

Clear[r,A];
r[x_,y_]:={x,y}
A[r_]:=V0/a r
Assuming[{V0=1;a=1;},VectorPlot[A[r[x,y]],{x,-1,1},{y,-1,1}]]

Assuming[{V0=1;a=1;},StreamPlot[A[r[x,y]],{x,-1,1},{y,-1,1}]]

Clear[r,A];
r[x_,y_,z_]:={x,y,z}
A[r_]:=V0/a r
Assuming[{V0=1,a=1},VectorPlot3D[A[r[x,y,z]],{x,-1,1},{y,-1,1},{z,-1,1}]]

Clear[r,A];
r[x_,y_,z_]:={x,y,z}
A[r_]:=n\[Cross] r
Assuming[{n={1,0,0};},VectorPlot3D[A[r[x,y,z]],{x,-1,1},{y,-1,1},{z,-1,1}]]

Differentation von Feldern

Gradient

Clear[GradFunc];
GradFunc[x_,y_,z_]:={D[V[x,y,z],x],D[V[x,y,z],y],D[V[x,y,z],z]}

V[x_,y_,z_]:=x^2+y^2+z^2

ContourPlot3D[V[x,y,z],{x,-1,1},{y,-1,1},{z,-1,1}]

GradFunc[x,y,z]

VectorPlot3D[Evaluate[GradFunc[x,y,z]],{x,-1,1},{y,-1,1},{z,-1,1}]

Divergenz

Clear[DivFunc,A];
DivFunc[x_,y_,z_]:=D[A[x,y,z][[1]],x]+D[A[x,y,z][[2]],y]+D[A[x,y,z][[3]],z]

A[x_,y_,z_]:={x^2,y^2,z^2}

VectorPlot3D[A[x,y,z],{x,-1,1},{y,-1,1},{z,-1,1}]

DivFunc[x,y,z]

ContourPlot3D[Evaluate[DivFunc[x,y,z]],{x,-1,1},{y,-1,1},{z,-1,1}]

Rotation

Clear[RotFunc,A];
RotFunc[x_,y_,z_]:={D[A[x,y,z][[3]],y]- D[A[x,y,z][[2]],z],D[A[x,y,z][[1]],z]- D[A[x,y,z][[3]],x],D[A[x,y,z][[2]],x]- D[A[x,y,z][[1]],y]}

A[x_,y_,z_]:=Cross[{x,y,z},{1,0,0}]

RotFunc[x,y,z]

VectorPlot3D[Evaluate[RotFunc[x,y,z]],{x,-1,1},{y,-1,1},{z,-1,1}]

Noch einfacher seit  MMA 10:

Gradient

Grad[x^2+y^2+z^2,{x,y,z}]

Divergenz

Div[{x,y,z},{x,y,z}]

Rotation

Curl[{x,y,z}\[Cross]{1,0,0},{x,y,z}]

Rotation eines Gradientfeldes = ?

Curl[Grad[x^2+y^2+z^2,{x,y,z}],{x,y,z}]

Gradient in Zylinderkoordinaten

Grad[f[ρ,θ,z ],{ρ,θ,z },"Cylindrical"]

Bsp. Dipol

c=Join[Table[Lighter[Blue,i/4],{i,0,3}],Table[Lighter[Red,i/4],{i,3,0,-1}]];

Dp={1,0};
V[x_,y_]:=Simplify[1/Norm[{x,y}-Dp]-1/Norm[{x,y}+Dp],{x,y}∈Reals]

ContourPlot[V[x,y],{x,-2,2},{y,-2,2},PlotRange->10,Contours->{-0.75,-0.25,-0.1,0,0.1,0.25,0.75},ContourShading->c]

EF[x_,y_]:=-Grad[V[x,y],{x,y}]

StreamPlot[Evaluate[EF[x,y]],{x,-5,5},{y,-5,5},ColorFunction->"Rainbow",PerformanceGoal->"Quality",StreamStyle->Black]

Integration und Felder

Kurvenintegral

Clear[r,s,F];
r[s_]:={s Cos[s],s Sin[s],0}

F[r_]:={0,0,1}\[Cross]r

vp=VectorPlot[Drop[F[{x,y,0}],{3}],{x,-12,12},{y,-12,12}];
tp=ParametricPlot[Drop[r[s],{3}],{s,0,4π},PlotStyle->{Thick,Orange}];
Show[vp,tp,Graphics[{Brown,Thick,Circle[{0,0},.2],Circle[{4π,0},.2]}],PlotRange->All]

Berechnen der geleisteten Arbeit entlang des Weges

Integrate[F[r[s]].D[r[s],s],{s,0,4π}]