Manipulate[If[linked,n2=n3;η2=η3];Plot[electricField[{n1,η1,e1pQ,e1mQ},{n2,η2,e2pQ,e2mQ},{n3,η3,e3Q},l,z,t],{z,l/2-3,l/2+3},PlotStyle->AbsoluteThickness[2],PlotRange->4,Axes->None,Prolog->{Hue[.5-η1/20,.15,1-Abs[n1]/6],Rectangle[{l/2-3,-4},{0,4}],Hue[.5-η2/20,.15,1-Abs[n2]/6],Rectangle[{0,-4},{l,4}],Hue[.5-η3/20,.15,1-Abs[n3]/6],Rectangle[{l,-4},{l/2+3,4}]},ImageSize->750,PlotPoints->50],{t,0,1},{{l,1},0,5,.05},{{n1,1},-3,3},{{η1,1},0,10},{{e1pQ, True,"+"},{True,False}},{{e1mQ, True,"-"},{True,False}},{{n2,1},-3,3},{{η2,1},0,10},{{e2pQ, True,"+"},{True,False}},{{e2mQ, True,"-"},{True,False}},{{n3,1},-3,3},{{η3,1},0,10},{{e3Q, True,"+"},{True,False}},{linked,{True,False}},Initialization:> {electricField[{n1_,η1_,e1pQ_,e1mQ_},{n2_,η2_,e2pQ_,e2mQ_},{n3_,η3_,e3Q_},l_,z_,t_]=Re[(E^(I 2 π t))Piecewise[{{If[e1pQ,1,0](E^(-I n1 2 π z))+If[e1mQ,1,0]e1m (E^(I n1 2 π z)),z<0},{If[e2pQ,1,0]e2p (E^(-I n2 2 π z))+If[e2mQ,1,0]e2m (E^(I n2 2 π z)),0≤z≤l},{If[e3Q,1,0]e3 (E^(-I n3 2 π z)),l<z}}/.FullSimplify[Solve[ {1+e1m == e2p+e2m,e2p (E^(-I n2 2 π l))+e2m (E^(I n2 2 π l))== e3 (E^(-I n3 2 π l)),(1/(η1))-(e1m/(η1)) == (e2p/(η2))-(e2m/(η2)),(e2p/(η2)) (E^(-I n2 2 π l))-(e2m/(η2)) (E^(I n2 2 π l))== (e3/(η3)) (E^(-I n3 2 π l))}, {e1m, e2p,e2m,e3}]][[1]]]]}]