function wave(F,G,A,dt,N)

% Animates solution to u_tt = u_xx with u(0,t) = u(1,t) = 0,
% u(x,0) = F(x), u_t(x,0) = G'(x).
%
% You must define F and G so that F is the odd periodic
% extension of u(x,0) and G' is the odd periodic extension
% of u_t(x,0), with period 2.  (Thus, G must be even with
% period 2.)  Also, F and G must be vectorized; if X is a
% vector of x values, then F(X) and G(X) must output vectors
% of corresponding values of F(x) and G(x).
%
% Each frame of the movie will extend from u = -A to u = A,
% and t will increase by dt from one frame to the next, for a
% total of N+1 frames.  Thus, the movie will extend from
% t = 0 to t = N*dt, for a total of N*dt/2 cycles of the
% solution.  The movie will play twice, generally at
% different rates; the rates are both proportional to dt.

x = 0:0.001:1;
for n = 0:N
   plot(x,(F(x-n*dt) + F(x+n*dt) + G(x+n*dt) - G(x-n*dt))/2)
   axis([0 1 -A A])
   M(n+1) = getframe;
end
movie(M)
    