ClearAll[Evaluate[Context[]<>"*"]]
SetDirectory[NotebookDirectory[]];
ClearAll;
Rv1=1.;
mH=(10^(-3));
Lv1=3.mH;
Rv2=0.2Rv1;
Lv2=0.2Lv1;
Lz=300mH;
Rz=100.;
U=230.;
f=50;
ω=2*Pi*f;

rceObvod=((U-Uz)/(Rv1+I*ω*Lv1))==(Uz/(I*ω*Lz))+(Uz/Rz)+(Uz/(Rv2+I*ω*Lv2+(1/(I*ω*kap))));
resObvodSol=Solve[rceObvod,Uz][[1]];

ztraty=Rv1*(((Abs[((U-Uz)/(Rv1+I*ω*Lv1))]))^2)+Rv2*(((Abs[(Uz/(Rv2+I*ω*Lv2+(1/(I*ω*kap))))]))^2)/.resObvodSol;

FindMinimum[ztraty,{kap,(10^(-6))}]

(*dioda*)

ClearAll[U]

U=15*Sin[314*t];
id[ud_]:=(10^(-7))*((E^(19ud))-1);
R=2.3;

rceProNDSolve=id[U-UR[t]]==((UR[t])/R)+0.00001UR'[t]

resND=UR[t]/.NDSolve[{rceProNDSolve,UR[0]==0},UR[t],{t,0,0.06},StartingStepSize->(10^(-40))][[1]]

(1/0.02)NIntegrate[(U-resND)*(resND/R),{t,0.02,0.04}]

Plot[(U-resND)*(resND/R),{t,0,0.06}]

(*import*)

data=Import["dataUloha10.csv"];
ListPlot[data]

model=(1/(a*(x^4)+b*(x^3)+c*(x^2)+d*x+e));

modelfunkce=model/.FindFit[data,model,{a,b,c,d,e},x];

Plot[modelfunkce,{x,-2,2}];

krok=data[[2,1]]-data[[1,1]];

Length[Table[{x,modelfunkce},{x,-2,2.0001,krok}]]

ClearAll[modelfunkce2,x];

ffit=Fit[data/.{x_,y_}:>{x,(1/y)},{1,x,(x^2),(x^3),(x^4)},x]
modelfunkce2[x_]=(1/ffit);
errdata=data/.{x_,y_}:>{x,y-modelfunkce2[x]};
Max[data/.{x_,y_}:>Abs[y-modelfunkce2[x]]]

U[t_]:=15*Sin[314*t]
rceProFindRoot[t_]:={U[t]==iD*R+ud,iD==id[ud]}

sol[t_]:={iD,ud}/.FindRoot[rceProFindRoot[t],{iD,0},{ud,0}]

T=(1/50.);
dats={#,sol[#]}&/@Range[0,T,(T/500)];

ListPlot[dats/.{t_,{id_,ud_}}:>{t,id}];
ListPlot[dats/.{t_,{id_,ud_}}:>{t,ud}];

intP=Interpolation[dats/.{t_,{id_,ud_}}:>{t,id*ud}];

strP=(1/T)NIntegrate[intP[t],{t,0,T}]