Ein Rundgang durch Mathematica

Mit Mathematica rechnen

1/3 + 1/7

N[1/3 + 1/7]

N[Pi, 50]

Abs[2 + 3  I]

(3 + 2  I)/(2 - I)

Polynome, Umformungen

Factor[x^4 + 2  x^3 - 12  x^2 - 40  x - 32]

Expand[(x - 1)^4]

Simplify[Exp[x Log[y]]]

Simplify[Sin[x]^2 + Cos[x]^2]

Expand[Cos[4  x] + 4  Cos[2  x] + 3, Trig -> True] // 
      Simplify

TrigReduce[4  Cos[x]^3]

f = (4  x + 
            2)/((x^2 + 3  x + 2) (x^2 + 4  x + 5))

Apart[f, x]

Lösen von Gleichungen

Solve[x^2 - x == 5, x]

FindRoot[{x^2 + y^2 == 10, x^y == 2}, {x, 3}, {y, 
        1}]

GLS = {2  x + 3  y + z == 
            1, 
x - y - z == 
            4, 
3  x + 7  z == 5};

Solve[GLS]

Lineare Algebra

a = {{1, 2}, {3, 4}}; MatrixForm[a]

b = {{w, x}, {y, z}}; MatrixForm[b]

a + b // MatrixForm

a*b  // MatrixForm

a . b // MatrixForm

Det[a]

inva = Inverse[a]; inva // MatrixForm

a . inva

a^(-1) // MatrixForm

invb = Inverse[b]; invb // MatrixForm

b . invb // MatrixForm

Simplify[b . invb] // MatrixForm

Clear[a, b]

Grenzwerte und Reihen

Limit[(Sqrt[1 + x] - 1)/x, x -> 0]

Limit[x!/x^x, x -> Infinity]

Sum[1/2^n, {n, 1, Infinity}]

Sum[1/n^2, {n, 1, Infinity}]

Sum[1/n, {n, 1, Infinity}]

Sum[(-1)^n, {n, 1, Infinity}]

Ein problematisches Beispiel

f = x^(3/2)*(Sqrt[x + 1] + Sqrt[x - 1] - 2  Sqrt[x])

Limit[f, x -> Infinity]

Limit[Expand[f], x -> Infinity]

Limit[f /. x -> 1/y, y -> 0]

Series[f, {x, Infinity, 5}]

Series[f /. x -> 1/y, {y, 0, 5}]

Clear[f]

Differentiation, Integration

D[(x - 1)/(x^2 + 1), x]

Simplify[%]

D[Sin[x y], x]

Integrate[1/(1 + x^3), x]

D[%, x]

Simplify[%]

Integrate[Sin[x^2], {x, a, b}]

?FresnelS

Differentialgleichungen

dgl = D[y[x], x] y[x] (1 + x^2) == x

DSolve[{dgl, y[0] == 0}, y[x], x]

Potenzreihen

Series[Sin[x], {x, 0, 10}]

Series[x!, {x, Infinity, 3}]

Series[Sum[1/k, {k, 1, n}], {n, Infinity, 5}]

Interpolation

datax = Range[10]

datay = Table[Random[Integer, 10], {10}]

dataxy = Transpose[{datax, datay}]

f = InterpolatingPolynomial[dataxy, x]

Expand[%]

f /. x -> 3

p1 = Plot[f, {x, 1, 10}]

p2 = ListPlot[dataxy, PlotStyle -> RGBColor[1, 0, 0]]

Show[p1, p2, ImageSize -> {800, Automatic}]

Clear[f]

Grafik

Plot[Sin[x]*Exp[-x/5], {x, 0, 4  Pi}]

Plot3D[Sin[x] Exp[y], {x, 0, 2  Pi}, {y, 0, Pi}]

Programmierung

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

f[50]

Map[f, Range[0, 10]]

f[-1]

Routenplanung oder ein wenig Graphentheorie ...

\(vertices = 
      Import["~/papers/Vortraege/bozen-2003-09-26/OeBB-Knoten.txt", "CSV"]\)
\(edges = 
      Import["~/papers/Vortraege/bozen-2003-09-26/OeBB-Kanten.txt", "CSV"]\)

Remove[Red]; Remove[Blue]

<< DiscreteMath`Combinatorica`

G = 
      FromOrderedPairs[
Map[Drop[#, -1] &, 
          edges], 
Map[{#[[3]], -#[[4]]} &, 
          vertices], 
Type -> Undirected]

xv = Map[#[[3]] &, vertices];
yv = Map[#[[4]] &, vertices];

Aratio = (Max[yv] - Min[yv])/(Max[xv] - Min[xv])

G1 = 
      SetEdgeWeights[
SetVertexLabels[
          G, 
Map[#[[2]] &, 
            vertices]], 
Map[#[[3]] &, 
          edges]
]

ShowGraph[G1, VertexStyle -> Disk[0.005], EdgeStyle -> Thin, 
      AspectRatio -> Aratio, ImageSize -> {800, 800*Aratio}, 
      VertexLabelPosition -> Center]

ShowGraph[SetEdgeLabels[G, Map[#[[3]] &, edges]], 
      VertexStyle -> Disk[0.005], EdgeStyle -> Thin, 
      AspectRatio -> Aratio, ImageSize -> {800, 800*Aratio}, 
      EdgeLabelPosition -> Center]

Nummer[s_] := 
      Module[{l}, l = Flatten[Position[vertices, {_, s, _, _}]]; 
        If[Length[l] == 1, l[[1]], 
          Print["Error: " <>  s  <>  "yields " <> 
              ToString[l]]]]

\(RoutenPlaner[von_, nach_] := 
      Module[{shortest, shortestedges}, 
shortest = 
          ShortestPath[G1, Nummer[von], 
            Nummer[nach]]; 
shortestedges = 
          Transpose[{Drop[shortest, \(-1\)], 
              Drop[shortest, 
                1]}]; 
ShowGraph[
SetGraphOptions[
            G1, {Append[shortestedges, EdgeColor -> Red], 
              Join[shortest, {VertexColor -> Green, 
                  VertexLabelColor -> 
                    Green}]}], 
VertexStyle -> 
            Disk[0.005], EdgeStyle -> Thin, AspectRatio -> Aratio, 
          ImageSize -> {800, 800*Aratio}, 
          VertexLabelPosition -> Center, 
          PlotRange -> 
            Zoom[shortest]]; 
Append[
Map[
            vertices[\([#, 2]\)] &, 
            shortest], 
ToString[
              Plus @@ GetEdgeWeights[G1, 
                  shortestedges]] <> " km"
]
]\)

RoutenPlaner["Graz", "Bolzano/Bozen"]

RoutenPlaner["Graz", "Innsbruck"]

RoutenPlaner["Innsbruck", "Bolzano/Bozen"]

RoutenPlaner["Graz", "Brennero/Brenner"]