Needs["JLink`"]
ReinstallJava[JVMArguments -> "-Xmx1024m"]

Data=Import[SetDirectory[NotebookDirectory[]],"ukazkova_data.xlsx"];

Un=22*(10^3);
rk=0.4*(10^(-3));
xk=6.2*(10^(-3));
xprac=7.44*(10^(-3));
pom=1.2;
Sn=50*(10^6);
odbocka=732;

dat0=Data[[1,4;;All,Range[5,20,1]]];

odb=odbocka/1.732;
h1=odb-80;
h2=odb+0;
lim1=50;
lim2=20;
dat=Select[dat0,#[[1]]>h1&&#[[1]]<h2&&Abs[#[[1]]-#[[3]]]<lim1 &&Abs[#[[1]]-#[[2]]]<lim1 &&Abs[#[[2]]-#[[3]]]<lim1&];

Length[dat]

Reaktanční poměr

cosf[data_,n_]:=Module[{p,q,cos},
p=data[[All,9+n-1]];
q=data[[All,13+n-1]];
cos=Table[Cos[ArcTan[((q[[x]])/(p[[x]]))]],{x,1, Length[p]}]
]
cos1=cosf[dat,1];
cos2=cosf[dat,2];
cos3=cosf[dat,3];



fcePomer[cos_,n_]:=Module[{pomer,p,u,i,q},

p=dat[[All,9+n-1]];
u=dat[[All,1+n-1]];
i=dat[[All,5+n-1]];
q=dat[[All,13+n-1]];
pomer=Table[{cos[[x]],((((u[[x]])^2)/((q[[x]])))/xk)},{x,1,Length[i]}]
]
Pomer1=Sort[fcePomer[cos1,1],#1[[1]]<#2[[1]]&];
Pomer11=Select[Pomer1,#[[2]]>0&&#[[2]]<10&];
Pomer2=Sort[fcePomer[cos2,2],#1[[1]]<#2[[1]]&];
Pomer21=Select[Pomer2,#[[2]]>0&&#[[2]]<10&];
Pomer3=Sort[fcePomer[cos3,3],#1[[1]]<#2[[1]]&];
Pomer31=Select[Pomer3,#[[2]]>0&&#[[2]]<10&];
ListPlot[{Pomer11,Pomer21,Pomer31},AxesOrigin->{0,0},PlotRange->Automatic]

kompC[data_,n_]:=Module[{q,p,c,u},
p=data[[All,9+n-1]];
q=data[[All,13+n-1]];
u=dat[[All,1+n-1]];
c=Table[{Cos[ArcTan[((q[[x]])/(p[[x]]))]],((q[[x]])/(314*((u[[x]])^2)))},{x,1, Length[p]}]
]
kompC1=kompC[dat,1];
kompC2=kompC[dat,2];
kompC3=kompC[dat,3];
kompC1S=Sort[fcePomer[cos1,1],#1[[1]]<#2[[1]]&]; 
Pomer11=Select[Pomer1,#[[2]]>0&&#[[2]]<10&];
kompC2S=Sort[fcePomer[cos2,2],#1[[1]]<#2[[1]]&];
Pomer21=Select[Pomer2,#[[2]]>0&&#[[2]]<10&];
kompC3S=Sort[fcePomer[cos3,3],#1[[1]]<#2[[1]]&];
Pomer31=Select[Pomer3,#[[2]]>0&&#[[2]]<10&];

par1=FindFit[Pomer11,(a1/((1-(x^6.9))))-2.2,{a1,b1,c1},x,MaxIterations->1000]
par2=FindFit[Pomer21,(a2/((1-(x^7))))-3.7,{a2,b2,c2},x,MaxIterations->1000]
par3=FindFit[Pomer31,(a3/((1-(x^6.9))))-2.2,{a3,b3,c3},x,MaxIterations->1000]

(*Show[ListPlot[{Pomer11,Pomer21,Pomer31},AxesOrigin->{0,0},PlotStyle->{Red,Blue,Green},Joined->False,PlotRange->{{0,1},{0.9,5}},Frame->True,GridLines->Automatic],Plot[{(a1/((1-(x^1.7))))+0.3/.par1,(a2/((1-(x^1.7))))+0.27/.par2,0.26+(a3/((1-(x^2))))/.par3},{x,0.1,1},AxesOrigin->{0,0}, PlotStyle->{Red,Blue,Green}]]*)
p1=Show[ListPlot[{Pomer11},AxesOrigin->{0,0},PlotStyle->{Black},Joined->False,PlotRange->{{0,1},{0.9,5}},Frame->True,FrameLabel->{{"\!\(\*SubscriptBox[\(V\), \(\(r\)\(\\ \)\)]\)[-]",""},{"cosφ [-]","Faze 1 - 732V"}},FrameStyle->{Directive[10,Black,Thickness[0.00025]],Directive[10,Black,Thickness[0.00025]]},GridLines->Automatic,GridLinesStyle->Directive[Black, Thickness[0.0012]]],
Plot[{(3.2/((1-(x^6.8))))-2.2/.par1},{x,0.1,1},AxesOrigin->{0,0}, PlotStyle->{Black,Thickness[0.003]}]];
p2=Show[ListPlot[{Pomer21},AxesOrigin->{0,0},PlotStyle->{Black},Joined->False,PlotRange->{{0,1},{0.9,5}},Frame->True,FrameLabel->{{"\!\(\*SubscriptBox[\(V\), \(\(r\)\(\\ \)\)]\)[-]",""},{"cosφ[-]","Faze 2 - 732V"}},FrameStyle->{Directive[10,Black,Thickness[0.0012]],Directive[10,Black,Thickness[0.00025]]},GridLines->Automatic,GridLinesStyle->Directive[Black, Thickness[0.002]]],
Plot[{(3.2/((1-(x^6.7))))-2.2/.par2},{x,0.1,1},AxesOrigin->{0,0}, PlotStyle->{Black,Thickness[0.003]}]];
p3=Show[ListPlot[{Pomer31},AxesOrigin->{0,0},PlotStyle->{Black},Joined->False,PlotRange->{{0,1},{0.9,5}},Frame->True,FrameLabel->{{"\!\(\*SubscriptBox[\(V\), \(\(r\)\(\\ \)\)]\)[-]",""},{"cosφ [-]","Faze 3 - 732V"}},FrameStyle->{Directive[10,Black,Thickness[0.0012]],Directive[10,Black,Thickness[0.00025]]},GridLines->Automatic,GridLinesStyle->Directive[Black, Thickness[0.0012]]],
Plot[{(a3/((1-(x^6.9))))-2.2/.par3},{x,0.1,1},AxesOrigin->{0,0}, PlotStyle->{Black,Thickness[0.003]}]];
p4=Plot[{(3.2/((1-(x^6.8))))-2.2/.par1,(3.2/((1-(x^6.7))))-2.2/.par2,(a3/((1-(x^6.9))))-2.2/.par3},{x,0.1,1},AxesOrigin->{0,0.95}, PlotStyle->{{Black,Thickness[0.003]},{Black,Dashed,Thickness[0.003]},{Black,Dotted,Thickness[0.003]}},Frame->True,PlotLegends->LineLegend[{"Fáze 1","Fáze 2","Fáze 3"},LabelStyle->{10,Black,FontFamily->"Arial"}],FrameLabel->{{"\!\(\*SubscriptBox[\(V\), \(\(r\)\(\\ \)\)]\)[-]",""},{"cosφ [-]","732V"}},FrameStyle->{Directive[10,Black,Thickness[0.0025]],Directive[10,Black,Thickness[0.0025]]},GridLines->Automatic,GridLinesStyle->Directive[Black, Thickness[0.0012]]]

p1
p2
p3
Export["pomery1.pdf",p1,ImageResolution->600]
Export["pomery2.pdf",p2,ImageResolution->600]
Export["pomery3.pdf",p3,ImageResolution->600]
Export["pomeryvse.pdf",p4,ImageResolution->600]

p5=
Plot[{(5/((1-(x^8))))-4},{x,0.1,1},AxesOrigin->{0,0},PlotStyle->{Black,Thickness[0.003]},PlotRange->{{0,1},{0.9,5}},Frame->True,FrameLabel->{{"\!\(\*SubscriptBox[\(V\), \(\(r\)\(\\ \)\)]\)[-]",""},{"cosφ [-]",""}},FrameStyle->{Directive[10,Black,Thickness[0.0025]],Directive[10,Black,Thickness[0.0025]]},GridLines->Automatic,GridLinesStyle->Directive[Black, Thickness[0.0012]]]
Export["pomery5.pdf",p5,ImageResolution->600]

pomer1=Table[{x,(3.2/((1-(x^6.8))))-2.2/.par1},{x,0.1,0.95,0.001}];
inpom1=Interpolation[pomer1];
pomer2=Table[{x,(3.2/((1-(x^6.7))))-2.2/.par2},{x,0.1,0.95,0.001}];
inpom2=Interpolation[pomer2];
pomer3=Table[{x,(3.2/((1-(x^7))))-2.2/.par3},{x,0.1,0.95,0.001}];
inpom3=Interpolation[pomer3];

Zavislost odporu oblouku

fceOdpor1[ucinik_]:=Module[{odpcos,intodp},
odpcos=Table[{Cos[Arg[2*rk+ro+I*2*xk*inpom1[ucinik]]],ro},{ro,0,70,0.0035}];
intodp=Interpolation[odpcos];
intodp[ucinik]
]
fceOdpor2[ucinik_]:=Module[{odpcos,intodp},
odpcos=Table[{Cos[Arg[2*rk+ro+I*2*xk*inpom2[ucinik]]],ro},{ro,0,70,0.0035}];
intodp=Interpolation[odpcos];
intodp[ucinik]
]
fceOdpor3[ucinik_]:=Module[{odpcos,intodp},
odpcos=Table[{Cos[Arg[2*rk+ro+I*2*xk*inpom3[ucinik]]],ro},{ro,0,70,0.0035}];
intodp=Interpolation[odpcos];
intodp[ucinik]
]

Odp1=Table[{ucinik,fceOdpor1[ucinik]},{ucinik,0.1,0.95,0.01}];
Odp2=Table[{ucinik,fceOdpor2[ucinik]},{ucinik,0.1,0.95,0.01}];
Odp3=Table[{ucinik,fceOdpor3[ucinik]},{ucinik,0.1,0.95,0.01}];

ListLinePlot[{Odp1,Odp2,Odp3},PlotRange->{{0,0.95},{0,0.05}}, Frame->True,GridLines->Automatic,PlotStyle->{Black,Blue,Red},FrameLabel->{"cosf[-]","R[Ω]"}]
Export["odpory1.pdf",ListLinePlot[{Odp1,Odp2,Odp3},PlotRange->{{0,0.85},{0,0.05}}, Frame->True,GridLines->Automatic,GridLinesStyle->Directive[Black,Thickness[0.0012]],PlotLegends->LineLegend[{"Fáze 1","Fáze 2","Fáze 3"},LabelStyle->{10,Black,FontFamily->"Arial"}],PlotStyle->{{Black,Thickness[0.003]},{Black,Dashed,Thickness[0.003]},{Black,Dotted,Thickness[0.003]}},FrameLabel->{{"(Subscript[R, o])[Ω]",""},{"cosφ [-]","732V"}},FrameStyle->{Directive[10,Black,Thickness[0.0025]],Directive[10,Black,Thickness[0.0025]]}],ImageResolution->600]

Export["odpor.pdf",ListLinePlot[{Odp1},PlotRange->{{0,0.85},{0,0.05}}, Frame->True,GridLines->Automatic,GridLinesStyle->Directive[Black,Thickness[0.0012]],LabelStyle->{10,Black,FontFamily->"Arial"},PlotStyle->{Black,Thickness[0.003]},FrameLabel->{{"(Subscript[R, o])[Ω]",""},{"cosφ [-]",""}},FrameStyle->{Directive[10,Black,Thickness[0.0025]],Directive[10,Black,Thickness[0.0025]]}],ImageResolution->600]

Kruhové diagramy - bez kompenzace, bez zařazení pecních zařízení

xt=0.12*((Un^2)/Sn);
xl=2.5;
kruhDiag1[cos_]:=Module[{imp,proud,cin,jal,ucin},
imp=(fceOdpor1[cos])+(I*(inpom1[cos]*xk));
proud=((odbocka/(Sqrt[3]))/imp)*(10^(-3));
cin=Re[(odbocka/(Sqrt[3]))*Conjugate[proud]*(10^3)]*(10^(-6));
jal= Im[(((odbocka/(Sqrt[3]))*Conjugate[proud]*(10^3))/(Sqrt[3]))]*(10^(-6));
ucin=((Re[(odbocka/(Sqrt[3]))*Conjugate[proud]])/(Abs[(odbocka/(Sqrt[3]))*Conjugate[proud]]));

{Abs[proud],cin,jal,ucin,cos,Im[imp]}


]
kruhDiag2[cos_]:=Module[{imp,proud,cin,jal,ucin,imp1,proud1,jal1},
imp=((fceOdpor2[cos]))+(I*1*(inpom2[cos]*xk));
proud=((odbocka/(Sqrt[3]))/imp)*(10^(-3));
cin=Re[(odbocka/(Sqrt[3]))*Conjugate[proud]*(10^3)]*(10^(-6));
jal= Im[(((odbocka/(Sqrt[3]))*Conjugate[proud]*(10^3))/(Sqrt[3]))]*(10^(-6));
ucin=((Re[(odbocka/(Sqrt[3]))*Conjugate[proud]])/(Abs[(odbocka/(Sqrt[3]))*Conjugate[proud]]));

{Abs[proud],cin,jal,ucin,cos,Im[imp],jal1}


]
kruhDiag3[cos_]:=Module[{imp,proud,cin,jal,ucin},
imp=(fceOdpor3[cos])+(I*1*(inpom3[cos]*xk));
proud=((odbocka/(Sqrt[3]))/imp)*(10^(-3));
cin=Re[(odbocka/(Sqrt[3]))*Conjugate[proud]*(10^3)]*(10^(-6));
jal= Im[(((odbocka/(Sqrt[3]))*Conjugate[proud]*(10^3))/(Sqrt[3]))]*(10^(-6));
ucin=((Re[(odbocka/(Sqrt[3]))*Conjugate[proud]])/(Abs[(odbocka/(Sqrt[3]))*Conjugate[proud]]));

{Abs[proud],cin,jal,ucin,cos,Im[imp]}


]

kruhDAt1=Table[kruhDiag1[c],{c,0.1,0.95,0.01}];
kruhDAt2=Table[kruhDiag2[c],{c,0.1,0.95,0.01}];
kruhDAt3=Table[kruhDiag3[c],{c,0.1,0.95,0.01}];

zavPI1=Table[kruhDAt1[[x,{1,2}]],{x,1,Length[kruhDAt1]}];
intPI1=Interpolation[zavPI1];
zavQI1=Table[kruhDAt1[[x,{1,3}]],{x,1,Length[kruhDAt1]}];
intQI1=Interpolation[zavQI1];

zavPI2=Table[kruhDAt2[[x,{1,2}]],{x,1,Length[kruhDAt2]}];
intPI2=Interpolation[zavPI2];
zavQI2=Table[kruhDAt2[[x,{1,3}]],{x,1,Length[kruhDAt2]}];
intQI2=Interpolation[zavQI2];

zavPI3=Table[kruhDAt3[[x,{1,2}]],{x,1,Length[kruhDAt3]}];
intPI3=Interpolation[zavPI3];
zavQI3=Table[kruhDAt3[[x,{1,3}]],{x,1,Length[kruhDAt3]}];
intQI3=Interpolation[zavQI3];

zav3fP=Table[{zavPI1[[x,1]],zavPI1[[x,2]]+zavPI2[[x,2]]+zavPI3[[x,2]]},{x,1,Length[kruhDAt1],1}];
int3fP=Interpolation[zav3fP];
zav3fQ=Table[{zavQI1[[x,1]],zavQI1[[x,2]]+zavQI2[[x,2]]+zavQI3[[x,2]]},{x,1,Length[kruhDAt1],1}];
int3fQ=Interpolation[zav3fQ];

pqidat1=dat0[[All,{5,9,13}]];
pidat1=Sort[pqidat1[[All,{1,2}]],#1[[1]]<#2[[1]]&];
pqidat2=dat0[[All,{6,10,14}]];
pidat2=Sort[pqidat2[[All,{1,2}]],#1[[1]]<#2[[1]]&];
pqidat3=dat0[[All,{7,11,15}]];
pidat3=Sort[pqidat3[[All,{1,2}]],#1[[1]]<#2[[1]]&];

zavPI11=Table[kruhDAt1[[x,{1,2}]],{x,1,Length[kruhDAt1]}];
intPI11=Interpolation[zavPI1];
zavQI11=Table[kruhDAt1[[x,{1,3}]],{x,1,Length[kruhDAt1]}];
intQI11=Interpolation[zavQI1];
pidatprep1=Table[pidat1[[x]]*{(10^(-3)),(10^(-6))},{x,1,Length[pidat1]}];
qidat1=Sort[pqidat1[[All,{1,3}]],#1[[1]]<#2[[1]]&];
qidatprep1=Table[qidat1[[x]]*{(10^(-3)),(10^(-6))},{x,1,Length[pidat1]}];

zavPI22=Table[kruhDAt2[[x,{1,2}]],{x,1,Length[kruhDAt2]}];
intPI22=Interpolation[zavPI2];
zavQI22=Table[kruhDAt2[[x,{1,3}]],{x,1,Length[kruhDAt2]}];
intQI22=Interpolation[zavQI2];
pidatprep2=Table[pidat2[[x]]*{(10^(-3)),(10^(-6))},{x,1,Length[pidat2]}];
qidat2=Sort[pqidat2[[All,{1,3}]],#1[[1]]<#2[[1]]&];
qidatprep2=Table[qidat2[[x]]*{(10^(-3)),(10^(-6))},{x,1,Length[pidat2]}];

zavPI33=Table[kruhDAt3[[x,{1,2}]],{x,1,Length[kruhDAt3]}];
intPI33=Interpolation[zavPI3];
zavQI33=Table[kruhDAt3[[x,{1,3}]],{x,1,Length[kruhDAt3]}];
intQI33=Interpolation[zavQI3];
pidatprep3=Table[pidat3[[x]]*{(10^(-3)),(10^(-6))},{x,1,Length[pidat3]}];
qidat3=Sort[pqidat3[[All,{1,3}]],#1[[1]]<#2[[1]]&];
qidatprep3=Table[qidat3[[x]]*{(10^(-3)),(10^(-6))},{x,1,Length[pidat3]}];

f1=Show[ListLinePlot[{zavPI11,zavQI11},PlotRange->All,PlotLegends->LineLegend[{"P(I)","Q(I)"},LabelStyle->{10,Black,FontFamily->"Arial"}],PlotStyle->{{Black,Thickness[0.003]},{Red,Thickness[0.003]}},Frame->True,FrameLabel->{{"P [MW], Q [MVAr]",""},{"I [kA]","Faze 1: proložení naměřených dat"}},GridLines->Automatic,GridLinesStyle->Directive[Black,Thickness[0.0012]]],ListPlot[{pidatprep1,qidatprep1},PlotRange->All,PlotStyle->{{Black,PointSize[0.0002]},{Red,PointSize[0.0002]}}]]
f2=Show[ListLinePlot[{zavPI22,zavQI22},PlotLegends->LineLegend[{"P(I)","Q(I)"},LabelStyle->{10,Black,FontFamily->"Arial"}],PlotRange->All,PlotStyle->{{Black,Thickness[0.003]},{Red,Thickness[0.003]}},Frame->True,FrameLabel->{{"P [MW], Q [MVAr]",""},{"I [kA]","Faze 2: proložení naměřených dat"}},GridLines->Automatic,GridLinesStyle->Directive[Black, Thickness[0.0012]]],ListPlot[{pidatprep2,qidatprep2},PlotRange->All,PlotStyle->{{Black,PointSize[0.0002]},{Red,PointSize[0.0002]}}]]
f3=Show[ListLinePlot[{zavPI33,zavQI33},PlotLegends->LineLegend[{"P(I)","Q(I)"},LabelStyle->{10,Black,FontFamily->"Arial"}],PlotRange->All,PlotStyle->{{Black,Thickness[0.003]},{Red,Thickness[0.003]}},Frame->True,FrameLabel->{{"P [MW], Q [MVAr]",""},{"I [kA]","Faze 3: proložení naměřených dat"}},GridLines->Automatic,GridLinesStyle->Directive[Black,Thickness[0.0012]]],ListPlot[{pidatprep3,qidatprep3},PlotRange->All,PlotStyle->{{Black,PointSize[0.0002]},{Red,PointSize[0.0002]}}]]

Export["faze.pdf",{f1,f2,f3}]
Export["faze1.pdf",f1,ImageResolution->600]
Export["faze2.pdf",f2,ImageResolution->600]
Export["faze3.pdf",f3,ImageResolution->600]

kruhPlot1=Plot[{intPI1[i],intQI1[i]},{i,1.350,75.000},AxesOrigin->{0,0},PlotLegends->LineLegend[{"P1(I)","Q1(I)"},LabelStyle->{10,Black,FontFamily->"Arial"}],PlotRange->{{0,75.000},{0,5*10}},Frame->True,GridLines->Automatic,GridLinesStyle->Directive[Black, Thickness[0.0012]],PlotStyle->{{Black,Thickness[0.003]},{Black,Dashed,Thickness[0.003]}},FrameLabel->{"I[kA]","P[MW],Q[MVAr]"},FrameStyle->{Directive[10,Black,Thickness[0.00025]],Directive[10,Black,Thickness[0.00025]]}];

kruhPlot2=Plot[{intPI2[i],intQI2[i]},{i,1.350,75.000},AxesOrigin->{0,0},PlotLegends->LineLegend[{"P2(I)","Q2(I)"},LabelStyle->{10,Black,FontFamily->"Arial"}],PlotRange->{{0,75.000},{0,5*10}},Frame->True,GridLines->Automatic,GridLinesStyle->Directive[Black, Thickness[0.0012]],PlotStyle->{{Hue[0.7],Thickness[0.003]},{Hue[0.7],Dashed,Thickness[0.003]}},FrameLabel->{"I[kA]","P[MW],Q[MVAr]"},FrameStyle->{Directive[Black,Thickness[0.00025]],Directive[8,Black,Thickness[0.00025]]}];

kruhPlot3=Plot[{intPI3[i],intQI3[i]},{i,1.350,75.000},AxesOrigin->{0,0},PlotLegends->LineLegend[{"P3(I)","Q3(I)"},LabelStyle->{10,Black,FontFamily->"Arial"}],PlotRange->{{0,75.000},{0,5*10}},Frame->True,GridLines->Automatic,GridLinesStyle->Directive[Black, Thickness[0.0012]],PlotStyle->{{Red,Thickness[0.003]},{Red,Dashed,Thickness[0.003]}},FrameLabel->{"I[kA]","P[MW],Q[MVAr]"},FrameStyle->{Directive[Black,Thickness[0.00025]],Directive[8,Black,Thickness[0.00025]]}];

kruhPlot4=Plot[{int3fP[i],int3fQ[i]},{i,1.350,75.000},AxesOrigin->{0,0},PlotLegends->LineLegend[{"P3f(I)","Q3f(I)"},LabelStyle->{10,Black,FontFamily->"Arial"}],PlotRange->{{0,75.000},{0,5*10}},Frame->True,GridLines->Automatic,GridLinesStyle->Directive[Black, Thickness[0.0012]],PlotStyle->{{Purple,Thickness[0.003]},{Purple,Dashed,Thickness[0.003]}},FrameLabel->{"I[kA]","P[MW],Q[MVAr]"},FrameStyle->{Directive[Black,Thickness[0.00025]],Directive[8,Black,Thickness[0.00025]]}];

kruhy=Show[kruhPlot1,kruhPlot2,kruhPlot3,kruhPlot4]

Export["kruh.pdf",kruhy,ImageResolution->600]

Kruhové diagramy - přepočteny na hladinu 22 kV, uvažována pecní zařízení

xt=0.10*((Un^2)/Sn);
xl=2.5;
kruhDiagP1[cos_]:=Module[{imp,proud,cin,jal,ucin},
imp=(fceOdpor1[cos]*((((Un/odbocka)))^2))+(I*(inpom1[cos]*xk*((((Un/odbocka)))^2)));
proud=((Un/(Sqrt[3]))/imp)*(10^(-3));
cin=Re[(Un/(Sqrt[3]))*Conjugate[proud]*(10^3)]*(10^(-6));
jal= ((Im[(Un/(Sqrt[3]))*Conjugate[proud]*(10^3)]*(10^(-6)))/(Sqrt[3]));
ucin=((Re[(Un/(Sqrt[3]))*Conjugate[proud]])/(Abs[(Un/(Sqrt[3]))*Conjugate[proud]]));

{Abs[proud],cin,jal,ucin,cos,Im[proud]}


]
kruhDiagP2[cos_]:=Module[{imp,proud,cin,jal,ucin,imp1,proud1,jal1},
imp=((fceOdpor2[cos]*((((Un/odbocka)))^2)))+(I*1*(inpom2[cos]*xk*((((Un/odbocka)))^2)));
proud=((Un/(Sqrt[3]))/imp)*(10^(-3));
cin=Re[(Un/(Sqrt[3]))*Conjugate[proud]*(10^3)]*(10^(-6));
jal= ((Im[(Un/(Sqrt[3]))*Conjugate[proud]*(10^3)]*(10^(-6)))/(Sqrt[3]));
ucin=((Re[(Un/(Sqrt[3]))*Conjugate[proud]])/(Abs[(Un/(Sqrt[3]))*Conjugate[proud]]));

{Abs[proud],cin,jal,ucin,cos,Im[imp],jal1}


]
kruhDiagP3[cos_]:=Module[{imp,proud,cin,jal,ucin},
imp=(fceOdpor3[cos]*((((Un/odbocka)))^2))+(I*1*(inpom3[cos]*xk*((((Un/odbocka)))^2)));
proud=((Un/(Sqrt[3]))/imp)*(10^(-3));
cin=Re[(Un/(Sqrt[3]))*Conjugate[proud]*(10^3)]*(10^(-6));
jal= ((Im[(Un/(Sqrt[3]))*Conjugate[proud]*(10^3)]*(10^(-6)))/(Sqrt[3]));
ucin=((Re[(Un/(Sqrt[3]))*Conjugate[proud]])/(Abs[(Un/(Sqrt[3]))*Conjugate[proud]]));

{Abs[proud],cin,jal,ucin,cos,Im[imp]}


]

kruhDAtP1=Table[kruhDiagP1[c],{c,0.1,0.95,0.01}];
kruhDAtP2=Table[kruhDiagP2[c],{c,0.1,0.95,0.01}];
kruhDAtP3=Table[kruhDiagP3[c],{c,0.1,0.95,0.01}];

zavPIP11=Table[kruhDAtP1[[x,{1,2}]],{x,1,Length[kruhDAtP1]}];
intPIP11=Interpolation[zavPIP11];
zavQIP11=Table[kruhDAtP1[[x,{1,3}]],{x,1,Length[kruhDAtP1]}];
intQIP11=Interpolation[zavQIP11];
cos11=Table[kruhDAtP1[[x,{1,4}]],{x,1,Length[kruhDAtP1]}];

zavPIP22=Table[kruhDAtP2[[x,{1,2}]],{x,1,Length[kruhDAtP2]}];
intPIP22=Interpolation[zavPIP22];
zavQIP22=Table[kruhDAtP2[[x,{1,3}]],{x,1,Length[kruhDAtP2]}];
intQIP22=Interpolation[zavQIP22];
cos22=Table[kruhDAtP2[[x,{1,4}]],{x,1,Length[kruhDAtP2]}];


zavPIP33=Table[kruhDAtP3[[x,{1,2}]],{x,1,Length[kruhDAtP3]}];
intPIP33=Interpolation[zavPIP33];
zavQIP33=Table[kruhDAtP3[[x,{1,3}]],{x,1,Length[kruhDAtP3]}];
intQIP33=Interpolation[zavQIP33];
cos33=Table[kruhDAtP3[[x,{1,4}]],{x,1,Length[kruhDAtP3]}];
intcos33=Interpolation[cos33];


fP1=Show[ListLinePlot[{zavPIP11,zavQIP11},PlotRange->All,PlotLegends->LineLegend[{"P[MW]","Q[MVAr]"},LabelStyle->{10,Black,FontFamily->"Arial"}],PlotStyle->{{Black,Thickness[0.003]},{Black,Dashed,Thickness[0.003]}},Frame->True,FrameLabel->{{"P [MW], Q [MVAr]",""},{"I [kA]","Faze 1"}},FrameStyle->{Directive[10,Black,Thickness[0.0025]],Directive[10,Black,Thickness[0.0025]]},GridLines->Automatic,GridLinesStyle->Directive[Black, Thickness[0.0012]]]]



fP2=Show[ListLinePlot[{zavPIP22,zavQIP22},PlotLegends->LineLegend[{"P[MW]","Q[MVAr]"},LabelStyle->{10,Black,FontFamily->"Arial"}],PlotRange->All,PlotStyle->{{Black,Thickness[0.003]},{Black,Dashed,Thickness[0.003]}},Frame->True,FrameLabel->{{"P [MW], Q [MVAr]",""},{"I [kA]","Faze 2"}},FrameStyle->{Directive[10,Black,Thickness[0.0025]],Directive[10,Black,Thickness[0.0025]]},GridLines->Automatic,GridLinesStyle->Directive[Black, Thickness[0.0012]]]]
fP3=Show[ListLinePlot[{zavPIP33,zavQIP33},PlotLegends->LineLegend[{"P[MW]","Q[MVAr]"},LabelStyle->{10,Black,FontFamily->"Arial"}],PlotRange->All,PlotStyle->{{Black,Thickness[0.003]},{Black,Dashed,Thickness[0.003]}},Frame->True,FrameLabel->{{"P [MW], Q [MVAr]",""},{"I [kA]","Faze 3"}},FrameStyle->{Directive[10,Black,Thickness[0.0025]],Directive[10,Black,Thickness[0.0025]]},GridLines->Automatic,GridLinesStyle->Directive[Black, Thickness[0.0012]]]]

Export["pepoctena1.pdf",fP1,ImageResolution->600]
Export["pepoctena2.pdf",fP2,ImageResolution->600]
Export["pepoctena3.pdf",fP3,ImageResolution->600]

cosplot=Show[ListLinePlot[{cos11,cos22,cos33},PlotRange->All,PlotLegends->LineLegend[{"(Subscript[cosφ, 1])","(Subscript[cosφ, 2])","(Subscript[cosφ, 3])"},LabelStyle->{10,Black,FontFamily->"Arial"}],PlotStyle->{{Black,Thickness[0.003]},{Red,Thickness[0.003]},{Hue[0.7],Thickness[0.003]}},Frame->True,FrameLabel->{{"cosφ [-]",""},{"I [kA]","Závislost cosφ(I)"}},FrameStyle->{Directive[10,Black,Thickness[0.0025]],Directive[10,Black,Thickness[0.0025]]},GridLines->Automatic,GridLinesStyle->Directive[Black, Thickness[0.0012]]]]

Export["cos.pdf",cosplot,ImageResolution->600]

Kruhové diagramy - přepočteny na hladinu 22 kV, uvažována pecní zařízení, kompenzace

(*kapcos1[cos_]:=Module[{c,int},c=Table[{kruhDAtP1[[x,4]],(10^6)*((kruhDAtP1[[x,3]])/(((((22000/(Sqrt[3]))))^2)*314))},{x,1,Length[kruhDAtP1],1}];

int=Interpolation[c,InterpolationOrder->1];
int[cos]
(*x,(1/(314*inpom1[x]*xk*((((Un/odbocka)))^2)))*)
]*)

cap=Table[{kruhDAtP1[[x,4]],(10^6)*(((kruhDAtP1[[x,3]])^2)/((((22000))^2)*314*3*1.9))},{x,1,Length[kruhDAtP1],1}];
capi=Interpolation[cap];


cap2=Table[{kruhDAtP2[[x,4]],(10^6)*(((kruhDAtP2[[x,3]])^2)/((((22000))^2)*314*3*1.65))},{x,1,Length[kruhDAtP2],1}];
capi2=Interpolation[cap2];


cap3=Table[{kruhDAtP3[[x,4]],(10^6)*(((kruhDAtP3[[x,3]])^2)/((((22000))^2)*314*3*1.65))},{x,1,Length[kruhDAtP3],1}];
capi3=Interpolation[cap3];

capproud=Table[{kruhDAtP3[[x,1]],(10^6)*(((10^6)*((kruhDAtP3[[x,3]])^2))/(((((22000/(Sqrt[3]))))^2)*314*3*7))},{x,1,Length[kruhDAtP3],1}];

ccomp=ListLinePlot[capproud,PlotRange->All,AxesOrigin->{0,0},PlotStyle->{{Black,Thickness[0.003]}},

Frame->True,FrameLabel->{{"C [μF]",""},{"I [kA]","Závislost velikosti kondenzátoru na proudu"}},FrameStyle->{Directive[10,Black,Thickness[0.0025]],Directive[10,Black,Thickness[0.0025]]},GridLines->Automatic,GridLinesStyle->Directive[Black, Thickness[0.0012]]]

Export["ckomp.pdf",ccomp,ImageResolution->600]

reakL=Table[kruhDAtP1[[x,{5,6}]],{x,1,Length[kruhDAtP1]}];
reakLI=Interpolation[reakL];
f=Table[{cos,Im[((-I)/(314*(1/(314*reakLI[cos]))))]},{cos,0.1,0.95,0.01}];
Show[ListLinePlot[f,PlotRange->{{0,0.95},{-20,20}},GridLines->Automatic],Plot[reakLI[x],{x,0.1,0.93},PlotStyle->Red]]
(*Plot[{(1/(314*reakLI[cos])),kapcos[cos]},{cos,0.11,0.95}]*)

kruhDatKomp1[cos_]:=Module[{imp,impBez,xc,proudPec,proudKomp,proudCelk,p,q,x},
impBez=(fceOdpor1[cos])*((((Un/odbocka)))^2)+(I*(xk*inpom1[cos]*((((Un/odbocka)))^2)));

xc=((-I)/(314*(capi[cos])));
imp=((xc*impBez)/(xc+impBez));
proudKomp=(Un/((Sqrt[3])*xc))*(10^(-3));
proudCelk=(Un/((Sqrt[3])*imp))*(10^(-3));
p=Re[(Un/(Sqrt[3]))*Conjugate[proudCelk]*(10^3)]*(10^(-6));
q=((Im[(Un/(Sqrt[3]))*Conjugate[proudCelk]*(10^3)]*(10^(-6)))/(Sqrt[3]));
{Abs[proudCelk],p,q,capi[cos],Abs[proudCelk-proudKomp]}
]

kruhDatKomp2[cos_]:=Module[{imp,impBez,xc,proudPec,proudKomp,proudCelk,p,q,x},
impBez=(fceOdpor2[cos])*((((Un/odbocka)))^2)+(I*(xk*inpom2[cos]*((((Un/odbocka)))^2)));
x=I*(xk*inpom2[cos]*((((Un/odbocka)))^2)+xl+xt);
xc=((-I)/(314*(capi2[cos])));
imp=((xc*impBez)/(xc+impBez));
proudKomp=(Un/((Sqrt[3])*xc));
proudCelk=(Un/((Sqrt[3])*imp))*(10^(-3));
p=Re[(Un/(Sqrt[3]))*Conjugate[proudCelk]*(10^3)]*(10^(-6));
q=((Im[(Un/(Sqrt[3]))*Conjugate[proudCelk]*(10^3)]*(10^(-6)))/(Sqrt[3]));
{Abs[proudCelk],p,q,capi2[cos]}
]

kruhDatKomp3[cos_]:=Module[{imp,impBez,xc,proudPec,proudKomp,proudCelk,p,q,x},
impBez=(fceOdpor3[cos])*((((Un/odbocka)))^2)+(I*(xk*inpom3[cos]*((((Un/odbocka)))^2)));
x=I*(xk*inpom3[cos]*((((Un/odbocka)))^2)+xl+xt);
xc=((-I)/(314*(capi3[cos])));
imp=((xc*impBez)/(xc+impBez));
proudKomp=(Un/((Sqrt[3])*xc));
proudCelk=(Un/((Sqrt[3])*imp))*(10^(-3));
p=Re[(Un/(Sqrt[3]))*Conjugate[proudCelk]*(10^3)]*(10^(-6));
q=((Im[(Un/(Sqrt[3]))*Conjugate[proudCelk]*(10^3)]*(10^(-6)))/(Sqrt[3]));
{Abs[proudCelk],p,q}
]

kruhDatKompKonst1[cos_]:=Module[{imp,impBez,xc,proudPec,proudKomp,proudCelk,p,q,x},
impBez=(rk+fceOdpor1[cos])*((((Un/odbocka)))^2)+(I*(xk*inpom1[cos]*((((Un/odbocka)))^2)));
x=I*(xk*inpom1[cos]*((((Un/odbocka)))^2)+xl+xt);
xc=((-I)/(314*(capi[0.65])));
imp=((xc*impBez)/(xc+impBez));
proudKomp=(Un/((Sqrt[3])*xc));
proudCelk=(Un/((Sqrt[3])*imp))*(10^(-3));
p=Re[(Un/(Sqrt[3]))*Conjugate[proudCelk]*(10^3)]*(10^(-6));
q=((Im[(Un/(Sqrt[3]))*Conjugate[proudCelk]*(10^3)]*(10^(-6)))/(Sqrt[3]));
{Abs[proudCelk],p,q}
]

kruhDatKompKonst2[cos_]:=Module[{imp,impBez,xc,proudPec,proudKomp,proudCelk,p,q,x},
impBez=(rk+fceOdpor2[cos])*((((Un/odbocka)))^2)+(I*(xk*inpom2[cos]*((((Un/odbocka)))^2)));
x=I*(xk*inpom2[cos]*((((Un/odbocka)))^2)+xl+xt);
xc=((-I)/(314*(capi2[0.65])));
imp=((xc*impBez)/(xc+impBez));
proudKomp=(Un/((Sqrt[3])*xc));
proudCelk=(Un/((Sqrt[3])*imp))*(10^(-3));
p=Re[(Un/(Sqrt[3]))*Conjugate[proudCelk]*(10^3)]*(10^(-6));
q=((Im[(Un/(Sqrt[3]))*Conjugate[proudCelk]*(10^3)]*(10^(-6)))/(Sqrt[3]));
{Abs[proudCelk],p,q}
]

kruhDatKompKonst3[cos_]:=Module[{imp,impBez,xc,proudPec,proudKomp,proudCelk,p,q,x},
impBez=(rk+fceOdpor3[cos])*((((Un/odbocka)))^2)+(I*(xk*inpom3[cos]*((((Un/odbocka)))^2)));
x=I*(xk*inpom3[cos]*((((Un/odbocka)))^2)+xl+xt);
xc=((-I)/(314*(capi3[0.65])));
imp=((xc*impBez)/(xc+impBez));
proudKomp=(Un/((Sqrt[3])*xc));
proudCelk=(Un/((Sqrt[3])*imp))*(10^(-3));
p=Re[(Un/(Sqrt[3]))*Conjugate[proudCelk]*(10^3)]*(10^(-6));
q=((Im[(Un/(Sqrt[3]))*Conjugate[proudCelk]*(10^3)]*(10^(-6)))/(Sqrt[3]));
{Abs[proudCelk],p,q}
]

kruhDiagKomp1=Table[kruhDatKomp1[c],{c,0.2,0.9,0.01}];
kruhDiagKompKonst1=Table[kruhDatKompKonst1[c],{c,0.1,0.65,0.01}];

kruhDiagKomp2=Table[kruhDatKomp2[c],{c,0.65,0.9,0.01}];
kruhDiagKompKonst2=Table[kruhDatKompKonst2[c],{c,0.1,0.65,0.01}];

kruhDiagKomp3=Table[kruhDatKomp3[c],{c,0.65,0.9,0.01}];
kruhDiagKompKonst3=Table[kruhDatKompKonst3[c],{c,0.1,0.65,0.01}];

zavPIC1=Table[kruhDiagKomp1[[x,{1,2}]],{x,1,Length[kruhDiagKomp1]}];
intPIC1=Interpolation[zavPIC1];
zavQIC1=Table[kruhDiagKomp1[[x,{1,3}]],{x,1,Length[kruhDiagKomp1]}];

intQIC1=Interpolation[zavQIC1];

zavPIC2=Table[kruhDiagKomp2[[x,{1,2}]],{x,1,Length[kruhDiagKomp2]}];
intPIC2=Interpolation[zavPIC2];
zavQIC2=Table[kruhDiagKomp2[[x,{1,3}]],{x,1,Length[kruhDiagKomp2]}];
intQIC2=Interpolation[zavQIC2];

zavPIC3=Table[kruhDiagKomp3[[x,{1,2}]],{x,1,Length[kruhDiagKomp3]}];
intPIC3=Interpolation[zavPIC3];
zavQIC3=Table[kruhDiagKomp3[[x,{1,3}]],{x,1,Length[kruhDiagKomp3]}];
intQIC3=Interpolation[zavQIC3];

zavPIK1=Table[kruhDiagKompKonst1[[x,{1,2}]],{x,1,Length[kruhDiagKompKonst1],1}];
zavPIK2=Table[kruhDiagKompKonst2[[x,{1,2}]],{x,1,Length[kruhDiagKompKonst2],1}];
zavPIK3=Table[kruhDiagKompKonst3[[x,{1,2}]],{x,1,Length[kruhDiagKompKonst3],1}];

zavQIK1=Table[kruhDiagKompKonst1[[x,{1,3}]],{x,1,Length[kruhDiagKompKonst1]}];
zavQIK2=Table[kruhDiagKompKonst2[[x,{1,3}]],{x,1,Length[kruhDiagKompKonst2]}];
zavQIK3=Table[kruhDiagKompKonst3[[x,{1,3}]],{x,1,Length[kruhDiagKompKonst3]}];

zavpecP=Table[kruhDiagKomp1[[x,{5,2}]],{x,1,Length[kruhDiagKomp1]}];


k=Show[ListLinePlot[{zavPIC1,zavQIC1,zavPIK1,zavQIK1,zavPIP11,zavQIP11},PlotRange->All,AxesOrigin->{0,0},PlotStyle->{{Red,Thickness[0.003]},{Red,Dashed,Thickness[0.003]},
{Red,Thickness[0.003]},
{Red,Dashed,Thickness[0.003]},
{Black,Thickness[0.003]},
{Black,Dashed,Thickness[0.003]}},

Frame->True,FrameLabel->{{"P[MW]",""},{"I [kA]","Kompenzace - faze 1"}},FrameStyle->{Directive[10,Black,Thickness[0.0025]],Directive[10,Black,Thickness[0.0025]]},GridLines->Automatic,GridLinesStyle->Directive[Black, Thickness[0.0012]]]]
l=Show[ListLinePlot[{zavPIC2,zavQIC2,zavPIK2,zavQIK2,zavPIP22,zavQIP22},PlotRange->Automatic,AxesOrigin->{0,0},PlotStyle->{{Red,Thickness[0.003]},{Red,Dashed,Thickness[0.003]},
{Red,Thickness[0.003]},
{Red,Dashed,Thickness[0.003]},
{Black,Thickness[0.003]},
{Black,Dashed,Thickness[0.003]}},

Frame->True,FrameLabel->{{"P[MW]",""},{"I [kA]","Kompenzace - faze 2"}},FrameStyle->{Directive[10,Black,Thickness[0.0025]],Directive[10,Black,Thickness[0.0025]]},GridLines->Automatic,GridLinesStyle->Directive[Black, Thickness[0.0012]]]]
m=Show[ListLinePlot[{zavPIC3,zavQIC3,zavPIK3,zavQIK3,zavPIP33,zavQIP33},PlotRange->Automatic,AxesOrigin->{0,0},PlotStyle->{{Red,Thickness[0.003]},{Red,Dashed,Thickness[0.003]},
{Red,Thickness[0.003]},
{Red,Dashed,Thickness[0.003]},
{Black,Thickness[0.003]},
{Black,Dashed,Thickness[0.003]}},

Frame->True,FrameLabel->{{"P[MW]",""},{"I [kA]","Kompenzace - faze 3"}},FrameStyle->{Directive[10,Black,Thickness[0.0025]],Directive[10,Black,Thickness[0.0025]]},GridLines->Automatic,GridLinesStyle->Directive[Black, Thickness[0.0012]]]]

Export["kruhkomp1.pdf",k,ImageResolution->600]
Export["kruhkomp2.pdf",l,ImageResolution->600]
Export["kruhkomp3.pdf",m,ImageResolution->600]

cetnost=Show[Histogram[(10^(-6))dat0[[All,13]],{1,16,1},PlotRange->Automatic,AxesOrigin->{0,0},
Frame->True,FrameLabel->{{"Četnost",""},{"P [MW]","Fáze 1"}},FrameStyle->{Directive[10,Black,Thickness[0.0025]],Directive[10,Black,Thickness[0.0025]]},GridLines->Automatic,GridLinesStyle->Directive[Black, Thickness[0.0012]]],
ListLinePlot[{{7.50,0},{7.50,3500}},PlotStyle->{Black,Dashed,Thickness[0.003]}],ListLinePlot[{{13.50,0},{13.50,3500}},PlotStyle->{Black,Dashed,Thickness[0.003]}]]

cetnost2=Show[Histogram[(10^(-6))dat0[[All,10]],{1,16,1},PlotRange->Automatic,AxesOrigin->{0,0},
Frame->True,FrameLabel->{{"Četnost",""},{"P [MW]","Fáze 2"}},FrameStyle->{Directive[10,Black,Thickness[0.0025]],Directive[10,Black,Thickness[0.0025]]},GridLines->Automatic,GridLinesStyle->Directive[Black, Thickness[0.0012]]],
ListLinePlot[{{7.50,0},{7.50,3500}},PlotStyle->{Black,Dashed,Thickness[0.003]}],ListLinePlot[{{13.50,0},{13.50,3500}},PlotStyle->{Black,Dashed,Thickness[0.003]}]]

cetnost3=Show[Histogram[(10^(-6))dat0[[All,11]],{1,16,1},PlotRange->Automatic,AxesOrigin->{0,0},
Frame->True,FrameLabel->{{"Četnost",""},{"P [MW]","Fáze 3"}},FrameStyle->{Directive[10,Black,Thickness[0.0025]],Directive[10,Black,Thickness[0.0025]]},GridLines->Automatic,GridLinesStyle->Directive[Black, Thickness[0.0012]]],
ListLinePlot[{{7.50,0},{7.50,3500}},PlotStyle->{Black,Dashed,Thickness[0.003]}],ListLinePlot[{{13.50,0},{13.50,3500}},PlotStyle->{Black,Dashed,Thickness[0.003]}]]

Export["cetnost1.png",cetnost,ImageResolution->600]
Export["cetnost2.pdf",cetnost2,ImageResolution->600]
Export["cetnost3.pdf",cetnost3,ImageResolution->600]

kl=Show[ListLinePlot[{zavPIC2,zavQIC2,zavPIK2,zavQIK2,zavPIP22,zavQIP22},PlotRange->Automatic,AxesOrigin->{0,0},PlotStyle->{{Red,Thickness[0.003]},{Red,Dashed,Thickness[0.003]},
{Red,Thickness[0.003]},
{Red,Dashed,Thickness[0.003]},
{Black,Thickness[0.003]},
{Black,Dashed,Thickness[0.003]}},

Frame->True,FrameLabel->{{"P[MW]",""},{"I [kA]","Kolísání proudu fáze 2"}},FrameStyle->{Directive[10,Black,Thickness[0.0025]],Directive[10,Black,Thickness[0.0025]]},GridLines->Automatic,GridLinesStyle->Directive[Black, Thickness[0.0012]]],
Plot[7.5(x^0),{x,0,1.5},PlotStyle->{Hue[0.7],Dashed, Thickness[0.0025]}],
Plot[13.5(x^0),{x,0,1.5},PlotStyle->{Hue[0.7],Dashed, Thickness[0.0025]}],
ListLinePlot[{{0.58,-0.5},{0.58,8}},PlotStyle->{Hue[1],Dashed, Thickness[0.0025]}],
ListLinePlot[{{0.65,-0.5},{0.65,8}},PlotStyle->{Black,Dashed, Thickness[0.0025]}],
ListLinePlot[{{1.13,-0.5},{1.13,14}},PlotStyle->{Hue[1],Dashed, Thickness[0.0025]}],
ListLinePlot[{{1.38,-0.5},{1.38,14}},PlotStyle->{Black,Dashed, Thickness[0.0025]}]
]
Export["cetnostvgrafu1.pdf",kl,ImageResolution->600]