Elementary mathematical function library

u = Exp[2.0]

u

Sin[Pi/2]

N[Sin[(Pi/2)]]

c = 2.98 10^8 Meter / Second

Sin[30 Degree]

Sqrt[5.0]

v = Sqrt[6]

v (Sqrt[5])

Sqrt[-9]

2^(-10)

N[%]

N[v,100]

RandomReal[10]

Special mathematical function library

HermiteH[0, x]

HermiteH[10, x]

HermiteH[10, 1]

LegendreP[2, x]

LegendreP[2, Cos[x]]

BesselJ[0, 5.2]

Plot[BesselJ[0, x], {x, 0, 100}]

Plot[Sin[3x], {x, 0, 4 Pi}]

Matrix and data manipulation tools

m = {{1, 2}, {3,4}}

m

m // MatrixForm

n = (({{1, 2}, {3, 4}}))

n = (({{1, -2}, {3, -4}}))

v = {5, -6}

v //MatrixForm

m.v //MatrixForm

w1 = {1, -2, 4}

w2 = {3, 2, -4}

w1 w2 //MatrixForm

w1.w2

Cross[w1,w2]//MatrixForm

Det[m]

c

Clear[c]

c

a

Clear[a]

m1 = {{a, b}, {c,d}}

m1//MatrixForm

Det[m1]

m1 // MatrixForm

Tr[m1]

m.m1 // MatrixForm

m m1 //MatrixForm

MatrixPower[m, 3] // MatrixForm

m.m.m // MatrixForm

m

minv = Inverse[m]

{{-2,1},{(3/2),-(1/2)}}

minv // MatrixForm

minv.m // MatrixForm

Support for complex number, arbitrary precision and interval arithmetic

Sqrt[-4]

(4 + 3 I) (2 + I)

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

Re[4 + 3 I]

Im[4 + 3 I]

Conjugate[4 + 3 I]

Abs[4 + 3 I]

Abs[5 - 2 I]

N[%]

N[%90]

Sqrt[(5 - 2 I) Conjugate[5 - 2 I]]

N[Pi]

N[Pi, 100000];

N[Sqrt[7], 40]

Limit[2 Sin[x], x -> Infinity]

Support for symbolic computation

3 + 62 - 1

3x - x + 2

Expand[(x + 2 y)(x - 2 y)]

Factor[x^2 - 4 y^2]

Integrate[Sin[x], x]

∫Sin[x]\[DifferentialD]x

Integrate[x^3 Sin[x] Tan[x], x]

D[Exp[x] Sin[x], x]

D[Exp[x] Sin[x], {x, 17}]

D[x^2 Sin[y],{{ x, y}}]

2D and 3D data and function visualization and animation tools

Plot[Exp[-x] Sin[5 x], {x, -3, 3}, PlotRange -> {{-3, 3},{-10, 10}}]

Plot[{Exp[-x] Sin[5 x], Exp[-2 x] Sin[5 x]}, {x, 0, 3}]

Plot3D[Exp[-x y] Sin[5 x + 2 y], {x, 0, 3}, {y, 0, 3}, AxesLabel -> {"x-Achse", "y-Achse","f(x,y)"}]

ContourPlot[Cos[x]+Exp[-0.2 x] Cos[2 y],{x,0,4Pi},{y,0,4Pi}, FrameLabel -> {"x", "y"}]

ReliefPlot[Table[i+Sin[i^2+j^2],{i,-4,4,.03},{j,-4,4,.03}],ColorFunction->"SunsetColors"]

Animate[Plot[Sin[x+a],{x,0,10}],{a,0,5},AnimationRunning->False]

Manipulate[ParametricPlot3D[{a Cos[u] Sin[v], a Sin[u] Sin[v], a (Cos[v] + Log[Tan[v/2]]) + b u}, {u, 0, 4 Pi}, {v, 0, 2}, AxesLabel -> {"x", "y", "z"}, PlotLabel -> "Dini's Surface", PlotPoints-> 64, PlotStyle-> Opacity[0.7]], {{a, 1}, 0, 2}, {{b, 0.15}, 0, 1}]

Solvers for systems of equations

m = {{1, 5}, {2, 1}}

m // MatrixForm

m.{x, y} == {a, b} // MatrixForm

Solve[m.{x, y} == {a, b}, {x, y}]

LinearSolve[m, {a, b}]

DSolve[y'[x]+y[x]==1,y[x],x]

y = 1 + c Exp[-x]

yprime = D[y, x]

yprime + y

Clear[y]

DSolve[{y'[x]==a y[x],y[0]==1},y[x],x]

DSolve[{y'[x]==a y[x]},y[x],x]

DSolve[y''''[x]==y[x],y[x],x]

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

DSolve[{y'[x]==z[x],z'[x]==-y[x],y[0]==0,z[0]==1},{y[x],z[x]},x]

Numeric and symbolic tools for discrete calculus

Sum[i^2, {i, 10}]

Sum[i^2, {i, 2, 10}]

Clear[n]

Sum[i^2, {i, 1, n}]

Product[i^2, {i,1, 3}]

Product[i, {i, 1, n}]

Product[i^2, {i, 1, n}]

SumConvergence[1/n, n]

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

N[Sum[1/n, {n, 1, 1000}]]

N[Sum[1/n, {n, 1, 500000}]]

SumConvergence[1/n^α, n]

N[Sum[1/n^1.1, {n, 1, 10000}]]

N[Sum[1/n^1.1, {n, 1, 10000000000}]]

N[Sum[1/n^2, {n, 1, 100000}]]

Constrained and unconstrained local and global optimization

Minimize[{x-y,-3 (x^2)+2 x y-(y^2)≥-1},{x,y}]

NMinimize[{x-y,-3 (x^2)+2 x y-(y^2)≥-1},{x,y}]

Plot[x^4-3x^2+x,{x,-3,2}]

FindMinimum[x^4-3 x^2+x,{x,1}]

FindMinimum[x^4-3 x^2+x,{x,-1}]

NMinimize[x^4-3x^2+x,x]

data = Import["/Users/webers/Documents/Teaching/MethodenkursMathematicaMatlabPhysChem/WS2016_2017/MathematicaPart/SampleData/sampledata02.xlsx", {"Data", 1}]

ListPlot[data]

model = LinearModelFit[data, {x, x^2, x^3, x^4}, x]

model["BestFit"]

Show[Plot[model[x], {x, 0, 4}, PlotRange -> All], ListPlot[data]]

ListPlot[model["FitResiduals"], Filling -> Axis]

Procedural, functional and object-oriented constructs

Procedural programming

Example 1 – Do loop

mat = {{a, b, c}, {d, e, f}, {g, h, k}}

mat // MatrixForm

newmat = mat;

newmat // MatrixForm

Do[newmat[[i,j]] = mat[[j,i]], {i, Length[mat]}, {j, Length[mat]}]

newmat // MatrixForm

Example 2 – While loop

x = 1.0; i=0;
While[Cos[x]≠x, x= Cos[x]; i++]; {x, i}

Cos[0.739085]

Example 3 – For loop

For[i=0,i<4,i++,Print[i]]

Clear[x]

Example 4 – For loop

Note : semicolon used as delimiter between statements in initial and body

For[i=1;t=x,i^2<10,i++,t=t^2+i;Print[t]]

Example 5 – For loop

For[sum=0.0;x=1.0,(1/x)>0.15,x=x+1,sum=sum+1/x; Print[sum]]