(* prirazeni, relace *)

a=1

a

a=.

a

a=1

a=a+1

a++;

a

a+=5

b=1

a>b

a==b

(* komplexni cisla *)

x=2+I

x^2

Re[x]

Im[x]

Abs[x]

Arg[x]

Conjugate[x]

x=.

f=x^2-Abs[x]^2

Simplify[f]

Simplify[f,Im[x]==0]

(* ridici struktury *)

a=2;b=4;

If[a<b,mensi=a,mensi=b];

mensi

For[i=1,i≤10,i++,Print[i]]

suma=0

For[i=1,i≤10,i++,suma+=i]
Print[suma]

suma=0; i=1;
While[i≤10,
suma+=i;
i+=2]
Print[suma]

min[a_,b_]:=If[a<b,a,b]

min[1,2]

min[3,4]

(* vektory, matice *)

v={1,2,3}

MatrixForm[v]

Sqrt[v]

v.v

v=Table[Cos[x],{x,0,2π,π/2}]

v2=Table[x,{x,0,2π,π/2}]

Cos[v2]

m=RandomReal[{0,1},{3,3}]

MatrixForm[m]

m[[All,1]]

m[[2,All]]

m[[1;;2,1;;2]]//MatrixForm

ConstantArray[0,{5,5}]//MatrixForm

Table[0,{i,1,5},{j,1,5}]//MatrixForm

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

MatrixForm[m]

m m

{{4,1},{1,9}}//MatrixForm

m.m //MatrixForm

v={{1},{1}}

MatrixForm[v]

MatrixForm[m.v]

a={{a11,a12},{a21,a22}}

b={{b11,b12},{b21,b22}}

c=a.b;c//MatrixForm

Det[a]

Tr[a]

(* linearni algebra *)

a={{0,1,1},{1,1,1},{1,1,0}};a//MatrixForm

eig=Eigenvalues[a]

vec=Eigenvectors[a]

a.vec[[1]]

eig[[1]]vec[[1]]

b=Inverse[a];b//MatrixForm

a.b//MatrixForm

prava={1,2,3}

x=b.prava

a.x==prava

(* vyrazy *)

a=.;b=.;c=.;x=.;

f1=x

f2=Exp[-x]

f=f1*f2

(* derivace *)

D[f,x]

D[f,x,x]

(* integrace *)

integral=Integrate[f,x]

tem=D[integral,x]

simp=Simplify[tem]

simp==f

Integrate[Exp[-x^2],{x,-Infinity,Infinity}]

vysl=Integrate[Exp[-a x^2],{x,-Infinity,Infinity}]

Simplify[vysl,a>0]

Plot[Cos[x^2],{x,0,5}]

res=Integrate[Cos[x^2],{x,0,α}]

Plot[res,{α,0,10},PlotRange->{0,1},PlotPoints->50]

Integrate[Cos[x^2],{x,0,1}]//N

NIntegrate[Cos[x^2],{x,0,1}]

i1=Integrate[Cos[x^2],{x,0,100}]//N

NIntegrate[Cos[x^2],{x,0,100}]

i2=NIntegrate[Cos[x^2],{x,0,100},MaxRecursion->10]

i1-i2

(* soucty rad *)

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

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

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

Simplify[Sum[n,{n,1,a}]]

(* rovnice *)

Solve[2x+5==0,x]

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

Solve[a x^2+b x+c==0,x]

f=Expand[(x-2)(x-1)(x+2)]

Solve[f==0,x]

f=Cos[x]-x

Solve[f==0,x]

vysl=FindRoot[f,{x,-1}]

Cos[vysl[[1,2]]]

(* diferencialni rovnice *)

DSolve[y'[x]+y[x]==a Sin[x],y[x],x]

DSolve[y''[x]+k^2 y[x]==0,y[x],x]

DSolve[{y''[x]+k^2 y[x]==0,y[0]==1},y[x],x]

DSolve[{y''[x]+k^2 y[x]==0,y[0]==1,y'[0]==0},y[x],x]

(* trigonometricke funkce *)

Cos[x+y]

vysl=TrigExpand[Cos[x+y]]

TrigFactor[vysl]

f=(n1 Cos[α2]-n2 Cos[α1])/(n1 Cos[α2]+n2 Cos[α1])

n1=n2 Sin[α2]/Sin[α1]

f2=Simplify[f]

TrigFactor[f2]

TrigToExp[Sin[x]]

ExpToTrig[Exp[I x]]

(* rozvoj v radu *)

Series[Exp[x],{x,0,3}]

Series[Sqrt[1+x],{x,0,3}]

Series[(n+2)/(n+3),{n,Infinity,3}]

Normal[%]

(* grafy funkci *)

plot1=Plot[Sin[x],{x,-5,5}]

plot2=Plot[Sin[x+1],{x,-5,5}]

Show[{plot1,plot2},AxesLabel->{x,y}]

f=Sin[Sqrt[x^2+y^2]]/Sqrt[x^2+y^2]

Plot3D[f,{x,-30,30},{y,-30,30}]

Plot3D[f,{x,-30,30},{y,-30,30},PlotRange->{-0.2,1}]

Plot3D[f,{x,-30,30},{y,-30,30},PlotRange->{-0.1,1},PlotPoints->50]

DensityPlot[f,{x,-20,20},{y,-20,20},PlotRange->{-0.22,0.7},PlotPoints->100]

(* vizualizace dat *)

a=Table[Sin[x],{x,-5,5,0.1}];

ListPlot[a]

a=Table[{x,Sin[x]},{x,-5,5,0.1}];

ListPlot[a]

f

a=Table[Sin[x],{x,0,5,0.5}];

BarChart[a]

a=Table[f,{x,-10.001,10},{y,-10.001,10}];

ListPlot3D[a,InterpolationOrder->0]

ListPlot3D[a]

ListDensityPlot[a,InterpolationOrder->0]

ListDensityPlot[a,InterpolationOrder->3]

a=Table[Exp[-(i+j)],{i,1,4},{j,1,4}]

interp=ListInterpolation[a,{{1,4},{1,4}}];
DiscretePlot3D[interp[i,j],{i,1,4},{j,1,4},ExtentSize->Scaled[.75],ViewPoint->{4,-5,3},BoxRatios->{1,1,0.7},FillingStyle->Opacity[0.8]]

(* cteni dat ze souboru *)

SetDirectory["c:/users/rehacek/desktop/nmp/l01"]

data=ReadList["data.txt",Number,RecordLists->True];

Max[data]

Min[data]

obr1=ListDensityPlot[data,PlotRange->All,Frame->False,InterpolationOrder->0]

obr2=ListPlot3D[data,Mesh->False,Ticks->False]

(* export grafiky do souboru *)

Export["obrazek1.jpg",obr1]

Export["obrazek2.jpg",obr2]

(* cviceni *)

(* prvocisla *)

prvocisla[max_]:=(
Print[2];
For[i=3,i≤max,i+=2,
prvoc=True;
For[del=3,del≤Sqrt[i],del+=2,
If[Divisible[i,del],prvoc=False]
]
If[prvoc,Print[i]]
])

prvocisla[100]

prvocisla[max_]:=(
list={2};
For[i=3,i≤max,i+=2,
prvoc=True;
For[del=3,del≤Sqrt[i],del+=2,
If[Divisible[i,del],prvoc=False]
]
If[prvoc,list=Append[list,i]]
];list)

prvocisla[100]

(* statistika *)
d=ReadList["statistika.txt",Number];

pocet=Length[d]

Mean[d]//N

Variance[d]//N

plot1=Histogram[d]

p=Table[pocet PDF[PoissonDistribution[4],i],{i,0,15}];

plot2=ListPlot[p]

Show[{plot1,plot2}]

p2=Table[{i,pocet PDF[PoissonDistribution[4],i]},{i,0,15}];

plot3=ListPlot[p2]

Show[{plot1,plot3}]

(* difrakce *)

z=.

u=Integrate[Exp[-I(x-ξ)^2/z],{ξ,-1,1}] /z

z=0.01

Plot[Abs[u],{x,-2,2},AxesOrigin->{0,0},PlotRange->All]

z=0.3

Plot[Abs[u],{x,-10z,10z},AxesOrigin->{0,0},PlotRange->All]

z=100

Plot[Abs[u],{x,-10z,10z},AxesOrigin->{0,0},PlotRange->All]

z=.

u

fresnel[x_,z_]:=(((((1/2)-(I/2)) (Sqrt[(π/2)]) (Erf[(((((-1))^(1/4)) (-1+x))/(Sqrt[z]))]-Erf[(((((-1))^(1/4)) (1+x))/(Sqrt[z]))]))/(Sqrt[z])))

Animate[Plot[Abs[fresnel[x,z]],{x,-10z,10z},AxesOrigin->{0,0},PlotRange->All],{z,0.1,1},AnimationRunning->False]