(*Instand 2D berechnung*)
count=50;
dz=0.1;
dt=dz/10;
const=dt/dz;
eArray=Table[0,{count}];
hArray=Table[0,{count}];
t=0;
InputFunction[t_]:=If[t>1&&t<100,0.5*Sin[2*Pi*t/100],0]; (*Volle Sinusperiode*)
(*InputFunction[t_]:=0.5Sign[Sin[4*Pi*t/100]];*)
(*InputFunction[t_]:=If[t<10,1,0];*)
Dynamic[
Do[eArray[[i]]=eArray[[i]]+const*(hArray[[i-1]]-hArray[[i]]),{i,1,count-1}];
eArray[[1]]=hArray[[1]]=eArray[[-1]]=hArray[[-1]]=0;
eArray[[2]]=InputFunction[t];
Do[hArray[[i]]=hArray[[i]]+const*(eArray[[i]]-eArray[[i+1]]),{i,1,count-1}];
t+=1;
Show[ListPlot[eArray,PlotStyle->Blue,PlotRange->{All,{-1,1}},PlotTheme->"Scientific",AspectRatio->1/4,ImageSize->1000],ListPlot[hArray,PlotStyle->Red]]
]

(*2D Gif export*)
outImgArray={};
count=50;
dz=0.01;
dt=dz/10;
const=dt/dz;
eArray=Table[0,{count}];
hArray=Table[0,{count}];
t=0;
Do[
Do[eArray[[i]]=eArray[[i]]+const*(hArray[[i-1]]-hArray[[i]]),{i,1,count-1}];
Do[hArray[[i]]=hArray[[i]]+const*(eArray[[i]]-eArray[[i+1]]),{i,1,count-1}];
eArray[[1]]=hArray[[1]]=eArray[[-1]]=hArray[[-1]]=0;
eArray[[2]]=If[t>1&&t<100,0.5*Sin[2*Pi*t/100],0];
t+=1;
AppendTo[outImgArray,
Show[ListPlot[eArray,PlotStyle->Blue,PlotRange->{All,{-1,1}},PlotTheme->"Scientific",AspectRatio->1/4,ImageSize->1000],ListPlot[hArray,PlotStyle->Red]]]
,{i,1,3000}]
Export["theoSinusImpuls.gif",outImgArray]

(*instant 3D berechnung*)
count=100;
dz=0.1;
dt=dz/5;
const=dt/dz;
eArray=Table[0,{count}];
hArray=Table[0,{count}];
t=0;
Dynamic[
Do[eArray[[i]]=eArray[[i]]+const*(hArray[[i-1]]-hArray[[i]]),{i,1,count-1}];
eArray[[1]]=hArray[[1]]=eArray[[-1]]=hArray[[-1]]=0;
eArray[[2]]=0.5*Sin[2*Pi*t/100];
Do[hArray[[i]]=hArray[[i]]+const*(eArray[[i]]-eArray[[i+1]]),{i,1,count-1}];
t+=1;
eFence=Table[{i/Length[eArray],eArray[[i]],0},{i,1,Length[eArray]}];
hFence=Table[{i/Length[hArray],0,hArray[[i]]},{i,1,Length[hArray]}];
Legended[
Show[
ListPointPlot3D[eFence,PlotStyle->Blue,PlotRange->{{0,1},{-1,1},{-1,1}},BoxRatios->{2, 1, 1},ImageSize->Large],
Graphics3D[{Blue,Line[eFence]}],ListPointPlot3D[hFence,PlotStyle->Red],
Graphics3D[{Red,Line[hFence]}],
Graphics3D[{Gray,Line[{{0,0,0},{1,0,0}}]}],
Graphics3D[{Gray,Line[{{0,-1,0},{0,1,0}}]}],
Graphics3D[{Gray,Line[{{0,0,-1},{0,0,1}}]}],
Graphics3D[{Gray,Line[{{1,-1,0},{1,1,0}}]}],
Graphics3D[{Gray,Line[{{1,0,-1},{1,0,1}}]}],
Graphics3D[{Opacity[0.3,Blue]}~Join~Table[Line[{{i/Length[eArray],0,0},eFence[[i]]}],{i,1,Length[eArray]}]],
Graphics3D[{Opacity[0.3,Red]}~Join~Table[Line[{{i/Length[hArray],0,0},hFence[[i]]}],{i,1,Length[hArray]}]],
Graphics3D[{Green,Line[{{0,0,0},{0,eArray[[2]],hArray[[2]]}}],Line[{{1,0,0},{1,eArray[[-2]],hArray[[-2]]}}]}],
ListPointPlot3D[{{0,eArray[[2]],hArray[[2]]},{1,eArray[[-2]],hArray[[-2]]}},PlotStyle->Green]
],LineLegend[{Blue,Red,Green},{"electrical field","magnetic field","field-addition on borders"},LegendMarkers->{"●","●","●"}]]]

(*avi/gif export der 3D Berechnung*)
count=100;
dz=0.1;
dt=dz/5;
const=dt/dz;
eArray=Table[0,{count}];
hArray=Table[0,{count}];
animTable3D=Table[
Do[eArray[[i]]=eArray[[i]]+const*(hArray[[i-1]]-hArray[[i]]),{i,1,count-1}];
eArray[[1]]=hArray[[1]]=eArray[[-1]]=hArray[[-1]]=0;
eArray[[2]]=0.5*Sin[2*Pi*t/100];
Do[hArray[[i]]=hArray[[i]]+const*(eArray[[i]]-eArray[[i+1]]),{i,1,count-1}];
eFence=Table[{i/Length[eArray],eArray[[i]],0},{i,1,Length[eArray]}];
hFence=Table[{i/Length[hArray],0,hArray[[i]]},{i,1,Length[hArray]}];
Legended[
Show[
ListPointPlot3D[eFence,PlotStyle->Blue,PlotRange->{{0,1},{-1,1},{-1,1}},BoxRatios->{2, 1, 1},ImageSize->Large],
Graphics3D[{Blue,Line[eFence]}],ListPointPlot3D[hFence,PlotStyle->Red],
Graphics3D[{Red,Line[hFence]}],
Graphics3D[{Gray,Line[{{0,0,0},{1,0,0}}]}],
Graphics3D[{Gray,Line[{{0,-1,0},{0,1,0}}]}],
Graphics3D[{Gray,Line[{{0,0,-1},{0,0,1}}]}],
Graphics3D[{Gray,Line[{{1,-1,0},{1,1,0}}]}],
Graphics3D[{Gray,Line[{{1,0,-1},{1,0,1}}]}],
Graphics3D[{Opacity[0.3,Blue]}~Join~Table[Line[{{i/Length[eArray],0,0},eFence[[i]]}],{i,1,Length[eArray]}]],
Graphics3D[{Opacity[0.3,Red]}~Join~Table[Line[{{i/Length[hArray],0,0},hFence[[i]]}],{i,1,Length[hArray]}]],
Graphics3D[{Green,Line[{{0,0,0},{0,eArray[[2]],hArray[[2]]}}],Line[{{1,0,0},{1,eArray[[-2]],hArray[[-2]]}}]}],
ListPointPlot3D[{{0,eArray[[2]],hArray[[2]]},{1,eArray[[-2]],hArray[[-2]]}},PlotStyle->Green]
],LineLegend[{Blue,Red,Green},{"electrical field","magnetic field","field-addition on borders"},LegendMarkers->{"●","●","●"}]],{t,0,2000}];

Export["C:\\Users\\Julien\\Desktop\\fullTheoCalcSinusAvi.avi",animTable3D,"FrameRate"->60]

Beep[]