Alex Loftus
← Back to the lesson

A matrix can calculate running sums and averages

A staircase of ones accumulates inputs. The result is a running total.
A staircase of ones accumulates inputs. The result is a running total.

A matrix can remember the running total

For the input (1,2,3)(1,2,3), the running totals are 11, then 1+2=31+2=3, then 1+2+3=61+2+3=6. Put those three rules into rows:

S=[100110111],S[123]=[136].S=\begin{bmatrix}1&0&0\\1&1&0\\1&1&1\end{bmatrix}, \qquad S\begin{bmatrix}1\\2\\3\end{bmatrix} =\begin{bmatrix}1\\3\\6\end{bmatrix}.

The staircase of ones shows which inputs each output includes. A zero means “leave this input out.”

Turn each total into an average

Divide the first row by 1, the second by 2, and the third by 3:

M=[10012120131313].M=\begin{bmatrix} 1&0&0\\ \frac12&\frac12&0\\ \frac13&\frac13&\frac13 \end{bmatrix}.

Then the input (5,10,15)(5,10,15) becomes

M[51015]=[57.510].M\begin{bmatrix}5\\10\\15\end{bmatrix} =\begin{bmatrix}5\\7.5\\10\end{bmatrix}.

Each row averages a longer prefix. The first output averages one number; the final output averages all three.

Why both rules are linear

The coefficients are fixed. Scaling every input scales each total or average by the same factor. Adding two input lists before applying the rule gives the same outputs as processing the lists separately and adding the results:

T(ax)=aT(x),T(x+y)=T(x)+T(y).T(ax)=aT(x),\qquad T(x+y)=T(x)+T(y).

With fixed finite-dimensional bases, every linear map can be represented by a matrix. These running-total and running-average matrices are concrete examples.

Test the rule

What are the running averages of (2,4,6)(2,4,6)?

Answer: (2,3,4)(2,3,4). Each output uses a different number of inputs, but a fixed row of weights.