Optical Wave Packet Propagation by Finite Difference Matrix

This animation will show that an optical wave packet propagation through a transparent slab has the expected speed and wavelength variation and agrees with the Fresnel reflection and transmission coefficients as expected. While it would be easy to perform the same calculations by the boundary matching method used to derive the Fresnel coefficients, this propagation method is valid for a transparent barrier's relative dielectric constant epsilon(x) of arbitrary variation with x and therefore is a more general way to compute optical transmission and reflection. This one dimensional method could easily be used for a more general dielectric constant profile but here it is just a prelude to the use of the same method in 2 dimensions where devices like lenses and gratings can be explored. To convince the learner that the propagation is correct, the first surface reflection amplitude and the full transit transmission amplitude are compared with the same results computed using the Fresnel coefficients. While it would be interesting to see the coherent effects of multiple reflections inside the transparent slab, those effects require a wider packet width and much more time so the propagation is ended after the transmitted packet completes its first transit of the transparent slab. Because the spatial length of gridded region is finite, reflections from the ends would also confuse the results if the propagation were continued longer. The following link is to a document that shows the algebra of computing the second derivative used in the Schrodinger equation.
The initial wave packet is complex and has the form E={real:cosine(k*x).imaginary:sin(k*x)}*exp(-x^2/sigma^2) where k is the wave vector. The program time iterates E using the wave equation:
epsilon(x)*d2E/dt2=d2E/dx2
where epsilon(x) is the relative dielectric constant of the dielectric slab and the speed of light is c=1. Since the initial E packet has no time directionality it will be noticed that the packet splits into 2 equal parts that move in opposite directions each moving at speed c=1. For this propagation the 5 point finite difference matrix coefficients are the default. Improved Second Derivative Approximation For 3, 5, 7 and 9 points the coefficients in the sparse finie difference matrix are:
cA3=[1,-2,1]/dx^2
cA5=[-1/12,4/3,-5/2,4/3,-1/12]/dx^2
cA7=[1/90,-3/20,3/2,-49/18,3/2,-3/20,1/90]/dx^2
cA9=[-(1/560), 8/315, -(1/5), 8/5, -(205/72), 8/5, -(1/5), 8/315, -(1/560)]/dx^2