function u = sol1Dwave(c,t,x)
% function taking the speed c, time points stored in the vector t ....
%....and space points stored in the vector x to produce the solution ....
%....of the 1D wave equation, u, as decsribed in the class
T=length(t);
% length of time vector t
L=length(x);
% length of space vector x
Q=zeros(T,L);
u=zeros(T,L); %initialization 
% solution u will be a matric with T rows and L columns. Each row will...
%...represent the solution at the time t(i) as a function of ...
%...space points x(j), j=1,L

for i=1:T
    %for loop in time...for each time t(i) with i going from 1 to T do
 cr1=x+c*t(i); % first characteristic line
 cr2=x-c*t(i); % second characteristic line
 phi1 = initpos(cr1); 
 % propagation of the initial position along the 1-st characteristic line
 phi2 = initpos(cr2);
 % propagation of the initial position along the 2-nd characteristic line
 for j=1:L
     %for loop in space... for given time t(i) compute the solution...
     %...u(i,j)=u(t(i),x(j)) for all j going from 1 to L
 Q(i,j) = integral(@(s)initmom(s,1),x(j)-c*t(i),x(j)+c*t(i));
 %Q computes the integral in the D'Alembert formula
 end
 u(i,:)=(1/2)*(phi1+phi2)+(1/(2*c))*Q(i,:);
 % computes the solution u(t(i),x) with x the vector of position points...
 % and stores this information in the i-th row of the matrix u
 %u(i,:) denotes the i-th row of the matrix u
end

