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]