pom=pom;
Remove["Global`*"];
Off[FindMinimum::sszero];
$HistoryLength=2;
SetDirectory[NotebookDirectory[]];
Off[NIntegrate::ncvb];

((Subscript[R, #])=0.000669)&/@Range[3];

Print["{(Subscript[R, 1]),(Subscript[R, 2]),(Subscript[R, 3])}=",(Subscript[R, #])&/@Range[3]]

Rs=0.001;
Ls=0.000001;
L=0.000000173;
(Subscript[R, 1])=0.000669;
(Subscript[R, 2])=0.000669;
(Subscript[R, 3])=0.000669;
Ampl=500.;
ω=314.;
T=((2*Pi)/ω);
ut1=Ampl*Sin[ω*t];
ut2=Ampl*Sin[ω*t-((2π)/3)];
ut3=Ampl*Sin[ω*t+((2π)/3)];
(Subscript[ut, 1,2])=ut1-ut2;
(Subscript[ut, 1,3])=ut1-ut3;
(Subscript[ut, 3,2])=ut3-ut2;
Gmin=0.00008;
(Subscript[Lg, 1])=10+0*Sin[0.1*ω*t];
SeedRandom[1];
(Subscript[Lg, 2])=10+0*Sin[0.08*ω*t+Random[]];
(Subscript[Lg, 3])=10+0*Sin[0.11*ω*t+Random[]];
α=0.05;
(*pripadne 0.0005*)
I0=10(*A*);
ϕ0=0.0001;
ϕ1=0.0001;
P0=1000;
A=40;
B=10(*V na cm*);
g0=100.;(*poc vodivost*)

ClearAll[derg];
derg[i_,g_,Lg_]:=Module[{ena,den,nom},
ena=(E^((((-(i^2))/(I0^2)))));
den=(-ϕ0-ϕ1*(E^((-α*Abs[i]))));
nom=g-Gmin-((i^2)/(g*(((A+B*Lg))^2)))*(1-ena)-((i^2)/P0)*ena;
(nom/den)

];

matMrel=(({{1, 0.5, 0.4}, {0.5, 1, 0.5}, {0.4, 0.5, 1}}));(*Matrix of relative mutual inductances *)
dersis={(Subscript[i, 1])'[t],(Subscript[i, 2])'[t],(Subscript[i, 3])'[t]};

uf:=Union[Flatten[#]]&;
rceg:={(Subscript[g, #])[t]*(Subscript[u, #])[t]==(Subscript[i, #])[t],(Subscript[g, #])'[t]==derg[(Subscript[i, #])[t],(Subscript[g, #])[t],(Subscript[Lg, #])],(Subscript[g, #])[0]==g0}&;
rg=uf@(rceg/@Range[3]);
rcePrivod:={(Subscript[uin, #])[t]-(Subscript[u, #])[t]==(Subscript[R, #])*(Subscript[i, #])[t]+L*(matMrel.dersis)[[#]],(Subscript[i, #])[0]==0}&;
rp=uf@(rcePrivod/@Range[3]);
rTrafo[{k1_,k2_}]:={(Subscript[uin, k1])[t]-(Subscript[uin, k2])[t]==Ls*(Subscript[i, k1,k2])'[t]+(Subscript[i, k1,k2])[t]*Rs+(Subscript[ut, k1,k2]),(Subscript[i, k1,k2])[0]==0};
rT=uf@(rTrafo/@{{1,2},{1,3},{3,2}});
r123={0==(Subscript[i, 1])[t]+(Subscript[i, 1,2])[t]+(Subscript[i, 1,3])[t],(Subscript[i, 2])[t]==(Subscript[i, 3,2])[t]+(Subscript[i, 1,2])[t],(Subscript[i, 3])[t]==-(Subscript[i, 3,2])[t]+(Subscript[i, 1,3])[t]};
rDohr=Union[rg,rp,rT,r123];
nezname=Union[Cases[rDohr,_[t],{0,∞}]/.{a_'[t]:>a,a_[t]:>a}];
tmax=5T;
res=NDSolve[rDohr,nezname,{t,0,tmax},StartingStepSize->(10^(-16)),MaxSteps->(10^6),SolveDelayed->False,MaxStepSize->(10^(-3))T,AccuracyGoal->6,PrecisionGoal->4][[1]];


obrazek=Plot[Evaluate[{(Subscript[i, 1,2])[t],(Subscript[i, 1,3])[t],(Subscript[i, 3,2])[t]}/.res],{t,tmax-T,tmax},PlotRange->All,AxesLabel->{"t [s]","i123 [A]"}]

ClearAll[exp];
SetAttributes[exp,{HoldAll,Listable}];
exp[co_]:=Module[{a,graf},a=ToString[Unevaluated[co]];graf:=Evaluate[co];Export[Evaluate[a<>".png"],graf,ImageResolution->300]];

(*exp[obrazek]*)