function [u2] = waveu2(x, delt, al, x0l, deltal, ar, x0r, deltar)
% waveu2 Initialization function for wave [PHYS210-fda]
%
% Initializes the second time step of the O(h^2) FDA solution of 
% the wave equation using left- and right-moving gaussians.
%
% Assumes that x is monotonically increasing.

   % Define default vector to be 0 length
   err = 0;
   u2  = zeros(0,0);
   if ~ isvector(x) 
      errmsg('x is not a vector');
      return;
   end
   % Initialize u2 to 0 vector 
   u2 = zeros(1,length(x));
   if deltal == 0
      errmsg('deltal = 0');
      err = 1;
   end
   if deltar == 0
      errmsg('deltar = 0');
      err = 1;
   end
   if err
      return
   end
   % Compute left- and right-moving gaussian profiles, and 1st & 2nd 
   % derivatives using 'gaussian'
   [gl dgl ddgl] = gaussian(x, al, x0l, deltal);
   [gr dgr ddgr] = gaussian(x, ar, x0r, deltar);
   u2 = (gl + gr) + delt .* (dgl - dgr) + 0.5*delt^2 .* (ddgl + ddgr);
   % Ensure that initial data is compatible with boundary conditions
   u2([1 length(u2)]) = 0;
end

function [] = errmsg(errstr)
   fprintf(stderr,'waveu1: %s\n',errstr);
end
