ClearAll[Evaluate[Context[]<>"*"]]

SetDirectory[NotebookDirectory[]];

ClearAll;

data=Import["dataUloha10.csv"];
krok=data[[2,1]]-data[[1,1]];

ListPlot[data]

resModelu=(1/(a*(x^4)+b*(x^3)+c*(x^2)+d*x+e))/.FindFit[data,(1/(a*(x^4)+b*(x^3)+c*(x^2)+d*x+e)),{a,b,c,d,e},x];

Plot[resModelu,{x,-2,2.0001}];

dataModel=Table[{b,resModelu/.x->b},{b,-2,2.0001,krok}];

chyba=Plus@@Table[Abs[(dataModel-data)[[a,2]]],{a,1,Length[data]}]

(*dioda*)

u=15Sin[314t];
id[Ud_]:=(10^(-7))((E^(19*Ud))-1)
R=2.3;

rce={id[u-UR[t]]==((UR[t])/R)+0.0001UR'[t],UR[0]==0}

resNDsol=NDSolve[rce,UR[t],{t,0,0.06},StartingStepSize->(10^(-40))]

Plot[{(u-UR[t])*id[u-UR[t]]}/.resNDsol,{t,0,0.06}]

((UR[t]/.resNDsol)/2.3)

(1/0.02)NIntegrate[(u-UR[t])*id[u-UR[t]]/.resNDsol,{t,0,0.02}]

(*2.resenidioda*)

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}]

ClearAll[U]

Rv1=1.;
mH=(10^(-3));
Lv1=3.mH;
Rv2=0.2Rv1;
Lv2=0.2Lv1;
Lz=300mH;
Rz=100.;
U=230.;

rce=((U-Uz)/(Rv1+I*314*Lv1))==(Uz/(I*314*Lz))+(Uz/Rz)+(Uz/(Rv2+I*314Lv2+(1/(I*314*kap))))

dosUz=Solve[rce,Uz][[1]];

proMinimum=Rv1*(((Abs[((U-Uz)/(Rv1+I*314*Lv1))]))^2)+Rv2*(((Abs[(Uz/(Rv2+I*314Lv2+(1/(I*314*kap))))]))^2)/.dosUz;

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

proMinimum/.kap->(10^(-12))

Limit[proMinimum,kap->0]