Answer to Quiz 12 Fri 27 Apr 2007

  1. Take two random vectors x and y of length 10. (use rand). Multiply their FFT transform componentwise and apply the inverse FFT transform to the result. Compare the last coefficient in the result with the 10-th entry in conv(x,y).
    Give all relevant MATLAB commands you used.

    Answer:

           x = rand(1,10);  y = rand(1,10);
           fx = fft(x);     fy = fft(y);
           fz = fx .* fy;
           z1 = conv(x,y);
           z2 = ifft(fz);
           z1(10) - z2(10)
    
  2. Give all MATLAB commands to create a sparse 100-by-100 matrix of the form
        
            1   2   3   ...  100 
            2   1   0   ...   0 
            3   0   1   ...   0
            :   :   :         :
           100  0   0   ...   1 
    

    Answer:

              i = [1:100};
              e = ones(1,100);
              a = sparse(i,i,e);
              b = sparse(e,i,i);
              m = a + b + a';
              m(1,1) = 1;