We could use equation eq:FTCS to numerically solve the classical wave equation
by setting
. Let's test this algorithm for a delta function.
Set all but two of the values in yVec
and yPrevVec
equal to zero.
Assume a value of
has just propagated during the third time step, n=3, from
the fifteenth to the sixteenth grid point. Then eq:FTCS gives the
following result for the next time step:
![]()
with all other values of
. The algorithm tells us
that the pulse continues to move to the right with velocity of 1.
This result is exact since
is an analytical solution of the scaled wave equation.
A similar argument can be
made to show that
is the solution for a left-traveling wave. Since the equation
is linear, these solutions can be added together to obtain a general solution.
Rather than performing the extensive calculations given by eq:FTCS at every time step,
we use the above results to simplify the calculation.
We store the left- and right-going components in yVec
and
yPrevVec
and then shift the elements of these vectors by one grid index every time step.
The above method method must, however, be modified for a nonuniform medium.
Since eq:FTCS requires that
,
we need to change the grid-point spacing in order to reflect changes in the index of
refraction,
. A nonuniform
grid is the price we pay for a simple algorithm. This new grid is called the optical grid,
, and has the property that the optical path difference,
, is the same between any two points. You will notice this nonuniform grid if
you compare the spacing between data points on the screen inside and outside a segment.
Finally, we must incorporate the reflections caused by a change in index of refraction into
the model. A reflection will couple the left-going and right-going waves and is included through the calculation of a reflection coefficient,
, at every grid point. The coefficient depends on the change in index of refraction which can be related to the change in grid spacing on the optical grid as follows
![]()
Notice that if the medium becomes more dense, then
decreases, and the reflection coefficient is negative, indicating a phase change.