Quiet[Remove["Global`*"]];

(*jak se podivat na vnitrni reprezentacvi vyrazu*)
vyr1=a==(b^2)+4;
FullForm[vyr1];
TreeForm[vyr1];
TraditionalForm[vyr1]

(*ukazka kdy to pomuze*)
a*b=5

a*b//TreeForm

(*vnitrni funkce maji tzv. Attributes*)
Attributes[Times]

(*neco o List -ech*)
(*pouziti jako vektor*)
listik1={1,2,3};
listik2={a,b,c};
(* hvezdicka nasoli po prvcich*)
listik1*listik2
(*tecka dela skalarni soucin*)
listik1.listik2

listik1//TreeForm;
listik1//FullForm

(*list jako matice*)
(*Ctrl + , da novy sloupec*)
(*Ctrl + Enter da novy radek*)
matice=(({{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}))

matice//TreeForm;
(*pro matice mame spoustu funkci*)
Det[matice];
(*maticove nasobeni je opet tecka*)
matice.listik1

(*vyber prvku z listu*)
listik3={1,{ja,ty},{{alfa,romeo}}};
Part[listik3,2];
listik3[[2]];
(*chci romeo*)
listik3[[3,1,2]];
(*od konce zaporna cisla*)
listik3[[-1,-1,-1]];
(*prvni aposledni funkce First a Last*)
First[listik3];
Last[listik3]

listik4={1,{ja,ty},{alfa,romeo}};
listik4[[3,2]];

(*mame-li nejake pravidlo, muzeme pouzit pro zadani Listu prikaz Table*)
Table[opice,{12}];
(*kdyz je druhy parametr {iterator, horniMez} tak iterator zacne cislem 1, krok je 1 a neprekroci horniMez*)
Table[(x^i),{i,4.5}];
(*nejobecnejsi syntaxe {iterator,dolniMez,horniMez,krok}*)
Table[(x^i),{i,0,3.0,.32}];
(*vice iteratoru da matici, kubickou matici atd.*)
Table[Prime[i+j-1],{i,5},{j,5}];
(*druhy parametr ve tvaru {iterator,{i1,i2,i3...}} vrati..*)
hodnotyIteratoru={1,8,r,5};
Table[(x^i),{i,hodnotyIteratoru}];

(*neco o patternech*)
(*?___*)(*nejobecnejsi pattren*)
(*cislo 1 zcela konkretni pattern*)
(*ale pred patterny jeste Set a SetDelayed*)
(*Set piseme jako "="*)
Set[a,2];
a=2;

ClearAll[a];
SeedRandom[1];
a=Random[];
?a

?:=

ClearAll[a];
SeedRandom[1];
a:=Random[]
?a

ClearAll[a];
SeedRandom[1];
a:=Random[];
Table[a,{5}]

ClearAll[a];
SeedRandom[1];
a=Random[];
Table[a,{5}]

(*a ted uz ty funkce*)
ClearAll[f];
f[x_]:=Integrate[(x^17)Sin[x],x];
f[1.3];
?f

ClearAll[f];
f[x_]=Integrate[(x^17)Sin[x],x]
f[1.3]
?f

ClearAll[f];
f[a_]:=FindRoot[Cos[x]==a*x,{x,0}]
f[0.1]

ClearAll[f,a];
f[a_]=FindRoot[Cos[x]==a*x,{x,0}]

ClearAll[f];
(*x vlevo i vpravo ma stejnou vyblitou barvu*)
x=5;
f[x_]:=(x^2);
f[3];
?f

ClearAll[f];
(*x vlevo i vpravo nema stejnou vyblitou barvu*)
x=5;
f[x_]=(x^2);
f[3];
?f

ClearAll[f,x];
(*x vlevo i vpravo nema stejnou vyblitou barvu*)
f[x_]=(x^2);
f[3]

(*pretezovano fci*)

TreeForm[a*b+c]

Quiet[Remove["Global`*"]];
(*konkretnejsi pattern ma prednost pred obecnejsim*)
f[x_]:=(x^2);
f[x_Integer]:=Pi;
f[1]:=E;
f[1.]:=I;
{f[4.5],f[5],f[1],f[1.]}

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

Quiet[Remove["Global`*"]];
$RecursionLimit=(10^6);
a[n_Integer]:=a[n]=n*a[n-1];
a[0]:=1;
a[5];
Trace[a[7]];
?a

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

Quiet[Remove["Global`*"]];
f[{a_,b_}]:=a+b;
f[{1,E}]

Quiet[Remove["Global`*"]];
derivace[{t_,y_}]:=-y+t;
tmin=0.;
tmax=10;
nKroku=500;
Δt=((tmax-tmin)/nKroku);
krokEuler[bod:{t_,y_}]:=bod+{Δt,derivace[bod]*Δt};
yStart=6;
pocBod={tmin,yStart};
sol=NestList[krokEuler,pocBod,nKroku];
ListPlot[sol];

Quiet[Remove["Global`*"]];
(*omezeni platnosti patternu*)
f[x_Real]:=(x^2);

Quiet[Remove["Global`*"]];
(*omezeni platnosti patternu*)
test[x_]:=x≥5;
f[x_?test]:=(x^2);
{f[4],f[6]}

Quiet[Remove["Global`*"]];
(*omezeni platnosti patternu*)
(*?*Q**)
f[x_?NumericQ]:=x+1;
g[x_?NumberQ]:=x+1;
{f[Pi],g[Pi]}

Quiet[Remove["Global`*"]];
(*v globalni, ostatni lokalni*)
f[x_]:=Module[{odmx,blabla},
odmx=(Sqrt[x]);
v=odmx+1;
blabla=(Sqrt[v])

];
f[1]

(*Map a Apply*)
Quiet[Remove["Global`*"]];
Map[f,{1,2,3}];
f/@{1,2,3};
listOsob={ja,ty,on,ona,ono};
ostrihejVlasy/@listOsob;
Apply[natocPecko,listOsob];
natocPecko@@listOsob;

f@@{1,2,3}

vyr=a*b+c;
TreeForm[vyr];
Apply[Times,vyr]
TreeForm[%];

listik={a,b,c,d};
Plus@@listik
Power@@listik

(2^a)//TreeForm;

Plus@@Range[100]

(*Pure Functions*)
Quiet[Remove["Global`*"]];
((#)^2)&/@Range[10]
((#)^2)&[2]

gg=#1+((#2)^2)&;
gg[E,Pi]

Quiet[Remove["Global`*"]];
a=5;
((#)^a)+4&[2]
#=4

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

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

Quiet[Remove["Global`*"]];
test[x_]:=x>2;
f[x_?test]:=1;
f[2]

Quiet[Remove["Global`*"]];
f[x_?(#>2&)]:=1;
f[3]

Quiet[Remove["Global`*"]];
(*nefunguje & ma velikou prioritu*)
f[x_?#>2&]:=1;
f[3]

(*pravidla zamen*)
Quiet[Remove["Global`*"]];
{a,b,c,d}/.c->1
{a,b,c,d}/.{c->1,d->2}

{a,b,c,d}/.{{c->1},{c->2}}

Quiet[Remove["Global`*"]];
sol=NSolve[(x^17)==2];
(x^2)+1/.sol[[3]]

Quiet[Remove["Global`*"]];
(*sectete druhe odmocniny z korenu*)
sol=NSolve[(x^17)==2];
Plus@@((Sqrt[#])&/@(x/.sol))

listik=Range[5]
(Sqrt[#])&/@listik
Plus@@%

listik={1,(Sqrt[2]),(Sqrt[3]),2,(Sqrt[5])};
listik/.List->Plus

mat=(({{1, 2}, {3, 4}}));
TreeForm[mat];
Plus@@mat
mat/.List->Plus

listDvojic=Table[{(x^2),(x^3)},{x,1,3,0.5}]

Reverse/@listDvojic

listDvojic/.{a_,b_}:>{b,a}

ClearAll[a]
listDvojic/.{a_,b_}->{b,a}

a="Patapuf";
listDvojic/.{a_,b_}->{b,a}

listDvojic/.{a_?(#>4&),b_}:>{b,a}

Table[(E^(Pi+j))+(Pi^(E-i)),{i,3},{j,4}]
%/.(E^(a_)):>(2^a)

(*reseni obvodu*)
Quiet[Remove["Global`*"]];
R1=100;
R2=100;
c=4.7*(10^(-6));
L=0.047;
uz[t_]:=10Tanh[20*Sin[314t]];
Plot[uz[t],{t,0,0.04}];
rce={0==iL[t]+iUz[t],
iL[t]==iR1[t]+iR2[t],
iR2[t]==iC[t],
u1[t]-u2[t]==L*iL'[t],
u2[t]==R1*iR1[t],
u2[t]-u3[t]==R2*iR2[t],
iC[t]==c*u3'[t],
u1[t]==uz[t]
};
nezname=Cases[rce,_Symbol[t],{0,∞}]//Union;
poc=Cases[rce,a_'[t]:>a[0]==0,{0,∞}]//Union;
tmax=0.04;
sol=NDSolve[Union[rce,poc],nezname,{t,0,tmax},StartingStepSize->(10^(-13))];
Plot[{uz[t],u3[t]/.sol},{t,0,tmax}]

Quiet[Remove["Global`*"]];
uz[t_]:=10Tanh[10*Sin[314t]];
R1=R2=100;
L=0.1;
c=47*(10^(-6));
rce={0==iU[t]+iR1[t],
iR1[t]==iL[t]+iC[t],
iC[t]==iR2[t],
u1[t]==uz[t],
u1[t]-u2[t]==R1*iR1[t],
u2[t]==L*iL'[t],
iC[t]==c*D[u2[t]-u3[t],t],
u3[t]==R2*iR2[t]
};
nezname=Cases[rce,_Symbol[t],{0,∞}]//Union;
poc=Cases[rce,a_'[t]:>a[0]==0,{0,∞}]//Union;
tmax=0.04;
sol=NDSolve[Union[rce,poc],nezname,{t,0,tmax},StartingStepSize->(10^(-13))];
Plot[{uz[t],u3[t]/.sol},{t,0,tmax},PlotStyle->Thick]

Quiet[Remove["Global`*"]];
uz[t_]:=10Tanh[10*Sin[314t]];
R1=R2=100;
L=0.1;
c=47*(10^(-6));
rce={0==iU[t]+iR1[t],
iR1[t]==iL[t]+iC[t],
iC[t]==iR2[t],
u1[t]==uz[t],
u1[t]-u2[t]==R1*iR1[t],
u2[t]==L*iL'[t],
u2[t]-u3[t]==uC[t],
iC[t]==c*uC'[t],
u3[t]==R2*iR2[t]
};
nezname=Cases[rce,_Symbol[t],{0,∞}]//Union;
poc=Cases[rce,a_'[t]:>a[0]==0,{0,∞}]//Union;
tmax=0.04;
sol=NDSolve[Union[rce,poc],nezname,{t,0,tmax},StartingStepSize->(10^(-13))];
Plot[{uz[t],u3[t]/.sol},{t,0,tmax},PlotStyle->Thick]

Quiet[Remove["Global`*"]];
uz[t_]:=10*Sin[314t+1.5];
R1=R2=100;
L=0.1;
c=47*(10^(-6));
rce={0==iU[t]+iR1[t],
iR1[t]==iL[t]+iC[t],
iC[t]==iR2[t],
u1[t]==uz[t],
u1[t]-u2[t]==R1*iR1[t],
u2[t]==L*iL'[t],
u2[t]-u3[t]==uC[t],
iC[t]==c*uC'[t],
u3[t]==R2*iR2[t]
};
nezname=Cases[rce,_Symbol[t],{0,∞}]//Union;
poc=Cases[rce,a_'[t]:>a[0]==0,{0,∞}]//Union;
tmax=0.04;
sol=NDSolve[Union[rce,poc],nezname,{t,0,tmax},StartingStepSize->(10^(-13))];
Plot[{uz[t],u3[t]/.sol},{t,0,tmax},PlotStyle->Thick];

sol[[1,1,2]]//FullForm

Quiet[Remove["Global`*"]];
z=3+4I;
{Im[z],Re[z],Abs[z],Arg[z]};
ampl=3;
fi=0.569;
ω=314;
fazor=ampl*Exp[I*fi];
Plot[{ampl*Sin[ω*t+fi],Im[fazor*Exp[I*ω*t]]},{t,0,0.04}];

Quiet[Remove["Global`*"]];
rce={0==iR1[t]+iU[t],
iR1[t]+iZ[t]+iL[t]==0,
0==iC[t]+iZ[t]+iL[t],
u1[t]==uZ[t],
u1[t]-u2[t]==R1*iR1[t],
u3[t]-u2[t]==L*iL'[t],
iC[t]==c*u3'[t]
};
(rce/.{uZ[t]->UzFazor,iZ[t]->iZFazor})/.{a_'[t]:>I*ω*a,a_Symbol[t]:>a};
sol=Solve[%,{iR1 ,iU,iL,iC,u1,u2,u3}][[1]];
dos={UzFazor->1,iZFazor->0.1,R1->1000,L->0.001,c->2.2*(10^(-6))};
u3Vysl=u3/.sol/.dos
LogLogPlot[Abs[u3Vysl],{ω,0.1,(10^7)},AxesLabel->{"ω [(s^(-1))]","Abs[u3] [V]"},PlotStyle->{Thick,Black},GridLines->Automatic]

n=5;
rce=0==(∑_(i=0)^n)(Subscript[a, i])*(x^i)
Solve[rce,x]

Quiet[Remove["Global`*"]];
par[list_List]:=((Total[(list^(-1))])^(-1));
ser[list_List]:=Total[list];
Solve[((Uin-Uout)/R1)==((Uout-0)/R2),Uout];
z1=par[{(1/(I*ω*C1)),ser[{R1,I*ω*L1}]}];
z2=par[{(1/(I*ω*C2)),ser[{R2,I*ω*L2}]}];
prenos=(z2/(z1+z2));
proTisk=Abs[prenos]//.{R1->0.1,L1->0.1,C1->(10^(-6)),R2->0.1,L2->0.1L1,C2->0.1C1};
LogLogPlot[proTisk,{ω,0.001,(10^7)},PlotStyle->{Thick,Red},GridLines->Automatic,AxesLabel->{"ω [(s^(-1))]","Abs[P] [-]"},PlotRange->All]

Quiet[Remove["Global`*"]];
iD[uD_]:=(10^(-7))*(Exp[19uD]-1);
Plot[iD[uD],{uD,-1,1},PlotStyle->Thick,PlotRange->All,AxesLabel->{"uD [V]","iD [A]"}];
R=20;
c=(10^(-3));
u1[t_]:=10*(Sqrt[2])*Sin[2*Pi*50*t];
rce={id[t]==iC[t]+iR[t],
id[t]==iD[u1[t]-u2[t]],
iC[t]==c*u2'[t],
u2[t]==R*iR[t]
};
nezname=Cases[rce,_Symbol[t],{0,∞}]//Union;
poc=Cases[rce,a_'[t]:>a[0]==0,{0,∞}]//Union;
tmax=0.04;
sol=NDSolve[Union[rce,poc],nezname,{t,0,tmax},StartingStepSize->(10^(-13)),MaxSteps->(10^6)];
Plot[{u2[t]/.sol},{t,0,tmax},PlotStyle->Thick]

Quiet[Remove["Global`*"]];
iD[uD_]:=(10^(-7))*(Exp[19uD]-1);
Plot[iD[uD],{uD,-1,1},PlotStyle->Thick,PlotRange->All,AxesLabel->{"uD [V]","iD [A]"}];
R=20;
c=(10^(-3));
u1[t_]:=10*(Sqrt[2])*Sin[2*Pi*50*t];
rce={id[t]==iC[t]+iR[t],
D[id[t]==iD[u1[t]-u2[t]],t],
iC[t]==c*u2'[t],
u2[t]==R*iR[t]
};
nezname=Cases[rce,_Symbol[t],{0,∞}]//Union;
poc=Cases[rce,a_'[t]:>a[0]==0,{0,∞}]//Union;
tmax=0.04;
sol=NDSolve[Union[rce,poc],nezname,{t,0,tmax},StartingStepSize->(10^(-13)),MaxSteps->(10^6)];
Plot[{u2[t]/.sol},{t,0,tmax},PlotStyle->Thick];

Quiet[Remove["Global`*"]];
iD[uD_]:=(10^(-7))*(Exp[19uD]-1);
Plot[iD[uD],{uD,-1,1},PlotStyle->Thick,PlotRange->All,AxesLabel->{"uD [V]","iD [A]"}];
R=20;
Manipulate[
u1[t_]:=10*(Sqrt[2])*Sin[2*Pi*50*t];
rce={id[t]==iC[t]+iR[t],
D[id[t]==iD[u1[t]-u2[t]],t],
iC[t]==c*u2'[t],
u2[t]==R*iR[t]
};
nezname=Cases[rce,_Symbol[t],{0,∞}]//Union;
poc=Cases[rce,a_'[t]:>a[0]==0,{0,∞}]//Union;
tmax=0.08;
sol=NDSolve[Union[rce,poc],nezname,{t,0,tmax},StartingStepSize->(10^(-13)),MaxSteps->(10^6),MaxStepSize->(0.02/100)];
Plot[{u2[t]/.sol},{t,0,tmax},PlotStyle->Thick,PlotRange->{Automatic,{0,10*(Sqrt[2.])}}],
{c,(10^(-3)),20*(10^(-3))}]

Quiet[Remove["Global`*"]];
iD[uD_]:=(10^(-7))*(Exp[19uD]-1);
Plot[iD[uD],{uD,-1,1},PlotStyle->Thick,PlotRange->All,AxesLabel->{"uD [V]","iD [A]"}];
R=20;
Manipulate[
u1[t_]:=10*(Sqrt[2])*Sin[2*Pi*50*t];
rce={id[t]==iC[t]+iR[t],
D[id[t]==iD[u1[t]-u2[t]],t],
iC[t]==c*u2'[t],
u2[t]==R*iR[t]
};
nezname=Cases[rce,_Symbol[t],{0,∞}]//Union;
poc=Cases[rce,a_'[t]:>a[0]==0,{0,∞}]//Union;
tmax=0.08;
sol=NDSolve[Union[rce,poc],nezname,{t,0,tmax},StartingStepSize->(10^(-13)),MaxSteps->(10^6),MaxStepSize->(0.02/100)];
Plot[{iD[u1[t]-u2[t]]/.sol},{t,0,tmax},PlotStyle->Thick,PlotRange->{Automatic,{0,10*(Sqrt[2.])}}],
{c,(10^(-3)),20*(10^(-3))}]

Quiet[Remove["Global`*"]];
(*Interpolace *)
data=Table[{x,Sin[x]},{x,0.,2.Pi,((2Pi)/10)}];
intSin=Interpolation[data,InterpolationOrder->3];
Plot[{intSin''[x],Sin''[x]},{x,0.,2.Pi},PlotStyle->Thick,PlotRange->All];

intSin=Interpolation[data,InterpolationOrder->3];
{t1,t2}=intSin[[1,1]];
Plot[{intSin''[x],Sin''[x]},{x,t1,t2},PlotStyle->Thick,PlotRange->All];

ClearAll[f1];
f1[y_]:=x/.FindRoot[x+Exp[x]==y,{x,0}];
Timing[Table[f1[y],{y,0,10,0.001}]][[1]]

dataInv=Table[{x+Exp[x],x},{x,-0.6,3,0.01}];
f2=Interpolation[dataInv];
yTry=Random[]
{f1[yTry],f2[yTry]};
Timing[Table[f2[y],{y,0,10,0.001}]][[1]]

Quiet[Remove["Global`*"]];
(*regrese*)
amplSum=0.1;
SeedRandom[1];
sum:=amplSum*RandomReal[NormalDistribution[0.0,1]];
vyr[x_]:=(x^2)-2x+1;
data=Table[{x,vyr[x]+sum},{x,0,2,0.01}];
ListPlot[data];
norm[Δ_]:=(Δ^2);
err[{x_,y_}]:=norm[a*(x^2)+b*x+c-y];
errCelk=(err/@data)/.List->Plus;
0==D[errCelk,#]&/@{a,b,c};
dosabc=Solve[%][[1]];
Show[Plot[vyr[x]/.dosabc,{x,0,2},PlotStyle->{Red,Thick}],ListPlot[data]];
nahr[x_]=Fit[data,{1,x,(x^2)},x];
dosabc;

Quiet[Remove["Global`*"]];
data=Table[{t,5-3*Exp[((-t)/3)]},{t,0.,10,0.1}];
graf=ListPlot[data];
SetDirectory[NotebookDirectory[]];
(*Export["graf.png",graf,ImageResolution->300];*)
SetAttributes[exp,{HoldAll,Listable}];
exp[co_]:=Module[{a,graf},a=ToString[Unevaluated[co]];graf:=Evaluate[co];Export[Evaluate[a<>".png"],graf,ImageResolution->300]];
(*exp[graf]*)

Quiet[Remove["Global`*"]];
data=Table[{t,5-3*Exp[((-t)/3)]},{t,0.,10,0.1}];
graf=ListPlot[data];
FindFit[data,a-b*Exp[((-t)/c)],{a,b,c},t]

Quiet[Remove["Global`*"]];
(*identifikace R L *)
uz[t_]=Sum[((Sin[i*2*Pi*50*t])/(i^2)),{i,1,50,3}];
tmax=0.04;
Plot[uz[t],{t,0,tmax}];
R=10;
L=0.05;
sol=NDSolve[{uz[t]==R*i[t]+L*i'[t],i[0]==0},i,{t,0,tmax}][[1]];
dataUz=Table[{t,uz[t]},{t,0,tmax,(tmax/500)}];
dataI=Table[{t,i[t]/.sol},{t,0,tmax,(tmax/500)}];
intU=Interpolation[dataUz];
intI=Interpolation[dataI];
{t1,t2}=intI[[1,1]];
dataProFit=Table[{intI[t],intI'[t],intU[t]},{t,t1,t2,((t2-t1)/500)}];
Fit[dataProFit,{i[t],i'[t]},{i[t],i'[t]}]

Quiet[Remove["Global`*"]];
(*identifikace R L *)
uz[t_]=Sum[((Sin[i*2*Pi*50*t])/(i^2)),{i,1,50,3}];
tmax=0.04;
Plot[uz[t],{t,0,tmax}];
amplSum=0.1;
SeedRandom[1];
sum:=amplSum*RandomReal[NormalDistribution[0.0,1]];
R=10;
L=0.05;
sol=NDSolve[{uz[t]==R*i[t]+L*i'[t],i[0]==0},i,{t,0,tmax}][[1]];
dataUz=Table[{t,uz[t]+0.5sum},{t,0,tmax,(tmax/1500)}];
dataI=Table[{t,(i[t]/.sol)+(10^(-2))sum},{t,0,tmax,(tmax/1500)}];
ListPlot[MovingAverage[dataUz,20]]

(*(Subscript[a, #])&/@Range[20]
MovingAverage[%,3]*)

mVAv:=MovingAverage[#,30]&
intU=Interpolation[mVAv@dataUz];
intI=Interpolation[mVAv@dataI];

{t1,t2}=intI[[1,1]];
dataProFit=Table[{intI[t],intI'[t],intU[t]},{t,t1,t2,((t2-t1)/1500)}];
Fit[dataProFit,{i[t],i'[t]},{i[t],i'[t]}]

Quiet[Remove["Global`*"]];
vyr[x_]:=a*(x^2)+b*x+c;
xPlus=x0+Δx;
xMinus=x0-Δx;
rce={vyr[x0]==f0,vyr[xPlus]==fPlus,vyr[xMinus]==fMinus};
 dosabs=Solve[rce,{a,b,c}][[1]];
integrand=vyr[x]/.dosabs;
integral=Integrate[integrand,{x,xMinus,xPlus}]//Simplify

Quiet[Remove["Global`*"]];
integral[{f_,xMin_,xMax_},n_?OddQ]:=Module[{hodnoty,Δx},
Δx=((xMax-xMin)/(n-1.));
hodnoty=f/@Range[xMin,xMax,((xMax-xMin)/(n-1))];
((Δx)/3.)*Total[({1.,4.,1.}.#&/@Partition[hodnoty,3,2])]

];
integral[{Sin,0.,Pi},5];
Integrate[Sin[x],{x,0,Pi}];

nPoly=7;
f[x_]=(∑_(i=0)^nPoly)(Subscript[a, i])*(x^i);
error[n_?OddQ]:=integral[{f,0.,1},n]-Integrate[f[x],{x,0,1}];
error[13]//Simplify

ClearAll[vydejKoeficienty];
vydejKoeficienty[n_Integer]:=Module[{vyr,x,eqns,decka,dosd,integrand,integral,koefky,d,x1,f,Δx,t},
vyr=Sum[(Subscript[d, i])*((#)^(i-1)),{i,n}]&;
x[i_]:=x1+Δx*(i-1);
eqns=f[#]==vyr[x[#]]&/@Range[n];
decka=(Subscript[d, #])&/@Range[n];
dosd=Solve[eqns,decka][[1]];
integrand=vyr[t]/.dosd;
integral=Integrate[integrand,{t,x1,x[n]}];
koefky=Coefficient[Simplify[(integral/(Δx))],f[#]]&/@Range[n]
];
vydejKoeficienty[1]:={1};
{#,vydejKoeficienty[#]}&/@Range[7]

Quiet[Remove["Global`*"]];
n=8;
vyr=(∑_(i=0)^n)((Subscript[a, i])*Cos[i*((2*Pi)/T)*t]+(Subscript[b, i])*Sin[i*((2*Pi)/T)*t]);
Integrate[Sin[7*((2*Pi)/T)*t]*vyr,{t,0,T}]

Quiet[Remove["Global`*"]];
f=50;
T=(1/f);
ω=2*Pi*f;
u[t_]:=10*Tanh[10*Sin[ω*t+0.987]];
plOrig=Plot[u[t],{t,0,2T},PlotStyle->{Red,Thick},AxesLabel->{"t[s]","u [V]"}];
aNIntegrate[i_Integer]:=NIntegrate[u[t]*Cos[i*ω*t],{t,0,T}];
bNIntegrate[i_Integer]:=NIntegrate[u[t]*Sin[i*ω*t],{t,0,T}];
nHarm=20;
acka=Quiet@(aNIntegrate/@Range[nHarm]);
bcka=Quiet@(bNIntegrate/@Range[nHarm]);

plNahrada[n_Integer]:=Module[{nahrada,siny,cosiny},
siny=(Sin[#*ω*t]&/@Range[n]).Take[bcka,n];
cosiny=(Cos[#*ω*t]&/@Range[n]).Take[acka,n];
Show[Plot[(2/T)(siny+cosiny),{t,0,2T},PlotStyle->{Blue,Thick},AxesLabel->{"t[s]","u [V]"}],plOrig]
];
plNahrada[3]

Manipulate[plNahrada[i],{i,1,nHarm,1}]

(*"dukaz" ze rovnice n-teho radu ma stejne koreny jako matice vlastni cisla*)
Quiet[Remove["Global`*"]];
mf=MatrixForm;
mrank=5;
origEqn=D[y[t],{t,mrank}]+(∑_(i=0)^(mrank-1))(Subscript[a, i])*D[y[t],{t,i}]
vars=(Subscript[x, #])[t]&/@Range[mrank];
eqns1=(Subscript[x, #-1])'[t]==(Subscript[x, #])[t]&/@Range[2,mrank];
eqnn=(Subscript[x, mrank])'[t]==-(∑_(i=1)^mrank)(Subscript[a, i-1])*(Subscript[x, i])[t];
eqnsTogether=Append[eqns1,eqnn]
{b,m}=CoefficientArrays[eqnsTogether,vars]//Normal
Thread[b==-m.vars]
A=-m;
mf@A
Det[A-λ*IdentityMatrix[mrank]]
origEqn/.{(Derivative[n_][y][t]):>(λ^n),y[t]->1}

Quiet[Remove["Global`*"]];
myLpl[f_]:=LaplaceTransform[f,t,s];
rce=y''[t]+2y'[t]+3y[t]==u[t];
myLpl[rce]/.{y[0]->0,y'[0]->0,LaplaceTransform[y[t],t,s]->Y[s],LaplaceTransform[u[t],t,s]->U[s]}
Solve[%,Y[s]]

myLpl[(E^((-t)/τ))*Sin[ω*t]]

rce=y''[t]+2y'[t]+3y[t]==u[t];
myLpl[rce]/.{y[0]->0,y'[0]->0,LaplaceTransform[y[t],t,s]->Y[s],LaplaceTransform[u[t],t,s]->U[s]}
Solve[%,Y[s]];
myLpl[rce]/.{LaplaceTransform[y[t],t,s]->Y[s],LaplaceTransform[u[t],t,s]->U[s]}
Solve[%,Y[s]]

y''[t]+2y'[t]+3y[t]==u[t]
Solve[3+2 s+(s^2)==0]

Quiet[Remove["Global`*"]];
derivace[{t_,{x1_,x2_}}]:={x2,Sin[t]-2x2-3x1};
start={0.,{1.,0.}};
tmax=20;
nKroku=500;
Δt=(tmax/nKroku);
krokEuler[bod:{t_,x12:{x1_,x2_}}]:={t+Δt,x12+Δt*derivace[bod]};
sol=NestList[krokEuler,start,nKroku];
ListPlot[sol/.{t_,{x1_,x2_}}:>{t,x1}]