The simple discretization

Here is an example of what can be done with the work from this section:

As mentioned earlier, we are going to approximate the value of the function of in a discrete domain. To do this, ñets start by defining a discrete domain:

D={(xi,tj)xi=Xmin+iΔxtj=jΔyi=0,...,Nxj=0,...,NtΔx=XmaxXminNxΔt=tfNt}\begin{align} D = \{(x_{i},t_{j}) | x_{i} &= X_{min} + i\Delta x \nonumber\\ t_{j} &= j\Delta y \nonumber\\ i &= 0, ... ,N_x \nonumber\\ j &= 0, ... ,N_t \nonumber\\ \Delta x &= \frac{X_{max} - X_{min}}{N_x} \nonumber\\ \Delta t &= \frac{t_f}{N_t} \} \end{align}

In every point of space and time, the function f will be defined, to simplify the notation, we shall define:

fij=f(xi,tj)f_i^j = f(x_i,t_j)

We will now remember a very useful formula from calculus. It helps us calculate second order derivatives:

2fx2(xi,tj)=fi+1j2fij+fi1jΔx2+O(Δx2)\frac{\partial^2 f}{\partial x^2}(x_i,t_j) = \frac{f_{i+1}^j-2f_i^j+f_{i-1}^j}{\Delta x^2} + {\cal O}(\Delta x^2)

With this formula in mind, we can substitute the partial derivatives inside the wave equation with these substactions, the result is the following:

fij12fij+fij+1v2Δt2fi1j2fij+fi+1jΔx2=O(Δt2,Δx2).\frac{f_i^{j-1} - 2f_i^j + f_i^{j+1}}{v^2\Delta t^2} - \frac{f_{i-1}^{j} - 2f_i^j + f_{i+1}^{j}}{\Delta x^2} = {\cal O}(\Delta t^2, \Delta x^2).

The nice thing about the obtained expresion is that we can solve for f at a later time in terms of known values from the past:

fij+1=(vΔtΔx)2[fi1j2fij+fi+1j]+2fijfij1f_i^{j+1} = \left( \frac{v\Delta t}{\Delta x} \right)^2 [f_{i-1}^{j} - 2f_i^j + f_{i+1}^{j}] + 2f_i^j - f_i^{j-1}

With this expression, we can calculate the function on a later time if we know the value of the function on the 2 prior times. To start the evolution, we require initial conditions. We must have the initial function (called g(x)) and the time partial derivative (called h(x)). With these two functions we can calculate 2 time steps and get the evolution going. The first time step would be:

fi0=g(xi)f_i^0 = g(x_i)

But, for the second time step, we are gonna have to taylor expand the function to the past:

fi1=fi0fi0˙Δt+12!fi0¨Δt2+O(Δt3)=fi0hiΔt+12!2fx2v2Δt2+O(Δt3)\begin{align} f_i^{-1} &= f_i^0 - \dot{f_i^0}\Delta t + \frac{1}{2!}\ddot{f_i^0}\Delta t^2 + {\cal O}(\Delta t^3)\nonumber\\ &= f_i^0 - h_i\Delta t + \frac{1}{2!}\frac{\partial^2f}{\partial x^2}v^2\Delta t^2 + {\cal O}(\Delta t^3)\nonumber \end{align}

The second derivative that appears in the expression can be computed using the same approximation used above. And this is all what we need to solve the wave equation in one dimension. The only detail missing are the boundary contidions, which will be discussed in the next section. To replicate the animations from above, the parameters and initial conditions needed are:

v(x) = 1.0 # Speed of the wave
dx = 0.006666666666666667
dt = 0.0033333333333333335
Nt = 1200

# Initial conditions
f_0(x) = 0.75*(1-x**2)*cos(2.0*x+1.0) # Initial value of the function
f'_0(x) = 0.0 # Initial value of the time derivative

# Boundary conditions
f(-1) = f(1) = 0

Last updated