1+1
1+2

%

a=4

2%

a=3

a=5

a

(*Math. is case sensitive*)
Sin[Pi]
sin[Pi]

b=1

ClearAll[b]

?b

Sin[5]

Sin[5.]

(1/7)+(2/13)

(1./7)+(2./13)

(*enumerates result*)
N[Pi]

N[Pi,100]

(*names of vars cannot start with numbers*)
123kyncl
kyncl123
123

(*space means multiplication*)
i am an idiot

a=23*7+p;

expr=(x^2)+2*Sin[α*t+(ϕ/6)];
FullForm[expr]
TreeForm[expr]

b*c=2

TreeForm[b*c]

Plot[x*Sin[(1/(1+x))],{x,1,20},PlotRange->All,AxesLabel->None]
Options[Plot]

x=1

ClearAll[x,y]

Solve[x+25y==1&&x-y==5,{x,y}]

Solve[{x+25y==1,x-y==5},{x,y}]

DSolve[D[y[x],x]+Sin[y[x]]==0,y[x],x]

(*Solve fcn does not solve nonlinear equations without exact solutions*)

Solve[Cos[x]==x,x]

(*FindRoot does it numerically!*)

FindRoot[Cos[x]==x,{x,0}]

list={1,2,4}

FullForm[list]
TreeForm[list]

ClearAll[a]

vec={1,3,4}

vec2={a,b,c}

vec.vec2
vec*vec2

mat=(({{1, 2, 5}, {3, 4, 6}, {3, 4, 7}}))

mat.vec2

Det[mat]

alist={1,2,5,35,7,4}

alist[[3]]

Part[alist,3]

listoflist={1,2,4,{2,5,{34,1}}}

TreeForm[listoflist]

listoflist[[4,2]]

Last[listoflist]

First[listoflist]

listoflist

listoflist[[-2]]

Length[listoflist]

Table[dalmatin,{i,1,101}]

Table[x^i,{i,10}]

Table[x^i,{i,1,10,1.7}]

Table[x^i,{i,{1,5,7,8}}]

listofOddPowers=Table[x^i,{i,1,15,2}]

Options[Plot]

Plot[listofOddPowers,{x,-1,1},PlotRange->Full]

Plot[listofOddPowers,{x,-1,1},PlotRange->{{0,1},All}]

Plot[listofOddPowers,{x,-1,1},PlotRange->Full,AxesLabel->{"x","y"}]

Plot[{Sin[x],Cos[x]},{x,-Pi,Pi},AxesLabel->{"x","Cos Sin"},PlotStyle->{{Blue,Dashed},{Red,Thickness[0.02]}},GridLines->{{Pi,2Pi},{-0.1,-.5,.5,0.1}},PlotLegends->"Expressions"]

Manipulate[
Plot[{Sin[x],Cos[n*x]},{x,-Pi,Pi},AxesLabel->{"x","Cos Sin"},PlotStyle->{{Blue,Dashed},{Red,Thickness[0.02]}},GridLines->Full,PlotLegends->{"Sin[x]","Cos[n*x]"}],
{{n,2},1,3}]

Manipulate[
ParametricPlot[{t+rc*Cos[t],rs*Sin[t]},{t,0,4Pi},PlotRange->Full,AxesLabel->{"x","y"},PlotStyle->Blue],
{rc,1,6},{rs,1,6}]

plts=Table[Plot[listofOddPowers[[i]],{x,-1,1}],{i,Length[listofOddPowers]}];

Show[plts]

(*seminar Nr. 2*)
Remove["Global`*"]//Quiet
(*functions i Math*)
(*?___;*)
?_

Remove["Global`*"]//Quiet;
(*original syntaxis*)
f[x:_]:=(x^2);
(*frequently used form*)
f[x_]:=(x^2);
f[4]
f@4
4//f

Remove["Global`*"]//Quiet;
SeedRandom[2]
a:=Random[]
Table[a,{10}]

?=

Remove["Global`*"]//Quiet;
SeedRandom[2]
a=Random[]
Table[a,{10}]
?a

Remove["Global`*"]//Quiet;
f[x_]:=∫Sin[x]\[DifferentialD]x
f[1]

Remove["Global`*"]//Quiet;
f[x_]=∫Sin[x]\[DifferentialD]x
f[1]
?f

Remove["Global`*"]//Quiet;
f[x_]=(x^2)
f[5]
?f

Remove["Global`*"]//Quiet;
x=Pi;
f[x_]=(x^2)
f[5]
?f

Sin@5.

5.//Sin

Remove["Global`*"]//Quiet;
f[x_]:=(x^2);
f[x_Integer]:=5;
f[1.]:=4;
f[1]:=3;
{f[4.5],f[1],f[1.],f[5]}

Remove["Global`*"]//Quiet;
f[{a_,b_}]:=a+b;
f[{a_,b_,c_}]:=a+b-c;
f[]:=5;
f[{E,Pi}]
f[{E,Pi,I}]
f[]
f[x_Integer]:=x+1
f[0.5]
f[1]
f[x_,y_,z_]:=x+y-z
f[1,2,3]

f[List[1,k]]

f[List[5*I,g,l]]

Head[List[5*I,g,l]]

f[1]

x=1

?x

ClearAll[x]

Solve[x^2==5,x]

$RecursionLimit=(10^6);
Remove["Global`*"]//Quiet;
a[n_Integer]:=n*a[n-1];
a[0]:=1;
Trace[a[3]];
Timing[Table[a[i],{i,1500}]][[1]]

Remove["Global`*"]//Quiet;
a[n_Integer]:=a[n]=n*a[n-1];
a[0]:=1;
Trace[a[3]];
Timing[Table[a[i],{i,1500}]][[1]]

(*Pure Functions*)
((#)^2)&[5]
#1+2#2&[E,Pi]

Select[{1,2,4,7,6,2},#>2&]

test[x_]:=x>2;
Select[{1,2,4,7,6,2},test]

Remove["Global`*"]//Quiet;
test[x_]:=x>2;
f[x_?test]:=5;
{f[8],f[1]}

Remove["Global`*"]//Quiet;
f[x_?#>2&]:=5;
{f[8],f[1]}

Remove["Global`*"]//Quiet;
f[x_?(#>2&)]:=5;
{f[8],f[1]}

Remove["Global`*"]//Quiet;
Map[f,{1,2,3,5}]
f/@{1,2,3,5}

Remove["Global`*"]//Quiet;
Apply[f,{1,2,3,5}]
f@@{1,2,3,5}
Plus@@{1,2,3,5}
Power@@{a,b,c,d}

Remove["Global`*"]//Quiet;
f[funct_]:=Plot[funct[t],{t,0,12},PlotRange->All,PlotLabel->"function"];
f/@{Sin,Cos,Cos[#]+2Sin[#]&}

Plot[Sin[t],{t,0,12},PlotLabel->"function",PlotRange->All,PlotStyle->{Red,Thickness[0.006]}]

Remove["Global`*"]//Quiet;
f[thickness_]:=Plot[Sin[t],{t,0,12},PlotLabel->"function",PlotRange->All,PlotStyle->{Red,Thickness[thickness]}]
f[0.001]

Solve[x^2+a x+1==0,x]

ClearAll[f]
f[a_]:=Solve[x^2+a x+1==0,x];
f[5]

ClearAll[f]
f[a_]:=Solve[a x+1==0,x];
f[5]

Equal[a,b]

Equal[1,2]

Remove["Global`*"]//Quiet;
(*ReaplaceAll and Rule*)
ReplaceAll[Power[x,2],Rule[x,2]]

(x^2)/.x->2

((Abs[x])^2)/.{{x->1},{x->2},{x->1+I}}

Remove["Global`*"]//Quiet;
sol=NSolve[(x^17)+0.1==0]
absXSquareValues=((Abs[x])^2)/.sol;
Plus@@absXSquareValues;

{Re[x],Im[x]}/.sol;
ListPlot[%,AspectRatio->1];

Abs[x]/.sol

sol=NSolve[(x^17)+0.1==0];
lines={{0,0},{Re[x],Im[x]}}/.sol;

pltlines=ListLinePlot[lines,AspectRatio->1,PlotStyle->{{Thick,Red}},GridLines->All]

Amp=Abs[x]/.sol[[1]];Show[pltlines,ParametricPlot[{Amp*Sin[x],Amp*Cos[x]},{x,0,2Pi},PlotStyle->Blue]];

Remove["Global`*"]//Quiet;
f[a_]:=x/.FindRoot[Cos[x]==a*x,{x,0}];
f[1]

x/.{x->0.123}

(*Module*)
Remove["Global`*"]//Quiet;
f[a_]:=Module[{sol,x},
sol=FindRoot[Cos[x]==a*x,{x,0}];
x/.sol
];
f[1]

(*Piecewise functions*)
Remove["Global`*"]//Quiet;
?/;

(*Piecewise functions*)
Remove["Global`*"]//Quiet;
f[x_]:=x/;x≤1;
f[x_]:=2-(x^2)/;x>1;
Plot[f[x],{x,-1,2}]

g[x_/;x≤1]:=x;
g[x_/;x>1]:=2-(x^2);
Plot[g[x],{x,-1,2}]

Remove["Global`*"]//Quiet;
f[x_]:=1-(x^2)/;-1<x≤1;
f[x_]:=f[x-2]/;x>1;
f[x_]:=f[x+2]/;x≤1;
Trace[f[3.5]];
Plot[f[x],{x,-5,5}];

Remove["Global`*"]//Quiet;
f[x_]:=Which[x<1,x,x≥1,2-(x^2)];
Plot[f[x],{x,-1,2}];

Piecewise

dsol=y[t]/.DSolve[{D[y[t],t]==-y[t]/(1+(y[t])^2),y[0]==1},y[t],t][[1]]//Quiet

Plot[dsol,{t,-100,100}]

ClearAll[y,t,sol]
sol=DSolve[{y'[t]==-y[t],y[0]==1},y[t],t]
forPlot=y[t]/.sol;
Plot[forPlot,{t,0,5}]

ajsd2asd=1

NestList[f,x0,5]

{Sin[5],Sin[5.]}

{Head[5.],Head[5],Head["5"],Head[5+5I],Head[{1,1}]}

Remove["Global`*"]//Quiet;
derivative[{t_,y_}]:=((-y)/(1+t));
tStart=0.;
tEnd=20;
yStart=10;
Manipulate[
nSteps=10*(2^i);
Δt=((tEnd-tStart)/nSteps);
step[point:{t_,y_}]:={t+Δt,y+Δt*derivative[point]};
solution=NestList[step,{tStart,yStart},nSteps];
pltEuler=ListPlot[solution,PlotRange->All,PlotStyle->{PointSize[0.01],Red}]
,{i,0,10,1}];

SolutionbyDSolve=y[t]/.DSolve[{D[y[t],t]==((-y[t])/(t+1)),y[0]==10},y[t],t][[1]];

pltDsolve=Plot[SolutionbyDSolve,{t,0,20},PlotRange->Full];

SolutionbyDSolve=y[t]/.DSolve[{D[y[t],t]==((-y[t])/(t+1)),y[0]==10},y[t],t][[1]];
pltDsolve=Plot[SolutionbyDSolve,{t,0,20},PlotRange->Full];
Manipulate[
tStart=0.;
tEnd=20;
yStart=10;
nSteps=10*(2^i);
Δt=((tEnd-tStart)/nSteps);
step[point:{t_,y_}]:={t+Δt,y+Δt*derivative[point]};
solution=NestList[step,{tStart,yStart},nSteps];
pltEuler=ListPlot[solution,PlotRange->All,PlotStyle->{PointSize[0.01],Red}];
Show[pltDsolve,pltEuler],{i,0,10,1}
];

NestList[Cos,0,5]

NestList[g,x0,5]

Remove["Global`*"]//Quiet;
Solve[-y[xi]==y'[xi]*(x-xi),x]//Simplify;
f[x_]:=100x-Exp[x];
Plot[f[x],{x,0,10}];
xNext[xPrevious_]:=xPrevious-((f[xPrevious])/(f'[xPrevious]));
xStart=10.;
NestList[xNext,xStart,10]
%/.x_Real->{x,f[x]}

test[x_]:=Abs[f[x]]>0.001;
NestWhileList[xNext,xStart,test]

xNext[xPrevious_]:=xPrevious-((f[xPrevious])/(f'[xPrevious]));
NestWhileList[xNext,xStart,Abs[f[#]]>0.001&]
%/.x_Real:>{x,f[x]}

Remove["Global`*"]//Quiet;
f=Cos;
xStart=1.;
test[x_]:=Abs[f[x]-x]>(10^(-5));
NestWhileList[f,xStart,test]

NestWhileList[Cos,1.,Abs[Cos[#]-#]>(10^(-5))&]

?/;

Remove["Global`*"]//Quiet;
f=Sin;
nextInterval[{a_,b_}]:={a,a+0.5(b-a)}/;f[a]*f[a+0.5(b-a)]<0;
nextInterval[{a_,b_}]:={a+0.5(b-a),b}/;f[b]*f[a+0.5(b-a)]<0;
intervalStart={1.,1.3Pi};
test[{a_,b_}]:=b-a>(10^(-3));
NestWhileList[nextInterval,intervalStart,test]

Quiet@Remove["Global`*"]
(*interpolation*)
n=5;
dataSin=Table[{x,Sin[x]},{x,0.,4Pi,((2Pi)/n)}];
intSin=Interpolation[dataSin,InterpolationOrder->2];
Plot[{Sin[x],intSin[x]},{x,0,4Pi},PlotStyle->Thick];
TreeForm[intSin];
{xmin,xmax}=intSin[[1,1]]

Quiet@Remove["Global`*"]
xValue[y_]:=x/.FindRoot[x+(E^x)==y,{x,1}];
ymin=1;
ymax=50;
Timing[Table[xValue[y],{y,ymin,ymax,((ymax-ymin)/10000)}]][[1]]

dataOfInverseFunction=Table[{x+(E^x),x},{x,0,4,0.01}];
intXValue=Interpolation[dataOfInverseFunction];
Timing[Table[intXValue[y],{y,ymin,ymax,((ymax-ymin)/10000)}]][[1]]

{xValue[5],intXValue[5]}