Exercise: Averaging matrixΒΆ

Task: Make an $n \times n$ matrix whose entries on the diagonal, $k$ superdiagonals, and $k$ subdiagonals, are one, and whose remaining entries are zero. E.g., for $k=2$ and $n=6$, the matrix looks like

      [[1., 1., 1., 0., 0., 0.],
       [1., 1., 1., 1., 0., 0.],
       [1., 1., 1., 1., 1., 0.],
       [0., 1., 1., 1., 1., 1.],
       [0., 0., 1., 1., 1., 1.],
       [0., 0., 0., 1., 1., 1.]]

Now modify the unit entries in each row to another constant such that all the row sums of the matrix equal one. We shall call the resulting matrix an averaging operator $A$. After making the $A$ matrix, do the following tasks:

  • Apply A to a vector $x$ whose entries are $x_j = (-1)^j$, say for $n=20,$ and $k=2.$ and comment on the resulting vector.

  • Apply A to a vector whose entries are values of $f(x) = x^2 + 2\sin(10 x)$, say at $n=1000$ equally spaced points in the interval [0, 10] and $k=100.$

In both cases investigate the effect of varying $k$, report any edge effects, and discuss your observations.