Now that we know something about waves and about about how to plot data using MATLAB, let us try to visualize a wave in MATLAB. We said a function of the form p=f(x - c t) where f is an arbitrary function represents a forward going wave.
If we look at the function
for a speed of c=1,
we can plot it for times t=0 and t=5 as a function of x by using
the following MATLAB statements:
pbegin=exp(-(xlist - 1*0).^ 2);
pend=exp(-(xlist - 1*5).^ 2);
plot(xlist, pbegin, xlist, pend)
xlabel('x')
ylabel('p')
xlist = linspace(-10,10,200);
One can clearly see that the wave is a pulse which is moving forward in the x direction.