function y=PconvP(p,nhar) % This function computes the discrete convolution necessary to % represent the nonlinearity in the Burgers equation. % % Translated into MATLAB by Ronald Kumon, 21 Oct 1995 y=zeros(1,nhar); % Initialize convolution vector for q=1:nhar % Compute one component per loop sum=0; % Initialize cumulative sum variable for m=1:q-1 % Sum frequencies contribution sum=sum+p(m)*p(q-m); end for m=nhar:-1:q+1 % Difference frequencies contribution sum=sum+2*p(m)*conj(p(m-q)); end y(q)=sum; % Put result into convolution vector end