# Reinventing 2D: What a difference a matrix makes

How derivatives of matrices are being used in your day-to-day lives Manhattan is a Cartesian plane brought to life. The original design plan for the streets of Manhattan, known as the Commissioners’ Plan of 1811, put in place the grid plan that defines Manhattan to this day. Using rectangular grids in urban planning is common practice but Manhattan went as far as naming its streets and avenues with numbers: 1st Street, 42nd Street, Fifth Avenue and so on.

The idea of a system of coordinates was first published in 1637 by René Descartes (hence Cartesian) and revolutionised mathematics by providing a link between geometry and algebra. According to legend, school boy René was lying in bed, sick, when he noticed a fly on the ceiling. He realised that he could describe the position of the fly using two numbers, each measuring the perpendicular distance of the fly to the walls of the room. Voilà! The Cartesian plane was born.

It is only natural then that we interpret the Cartesian plane in terms of spatial coordinates but what happens if we take the same old Cartesian plane and re-invent the 2D space as a space of functions?

### A coordinate system of functions

Consider the following family of functions: $$y=a{e}^{x}\sin x+b{e}^{x}\cos x$$ where $a$ and $b$ are real.

We call it a family of functions because different values of $a$ and $b$ will result in different functions. For example, for $a = 2$ and $b = -1$, we have $y=2{e}^{x}\sin x-{e}^{x}\cos x$.

Now let’s make a rule that whenever we write down a member of this family of functions we will always write the term in ${e}^{x}\sin x$ first and then the term in ${e}^{x}\cos x$ . If that’s the case then we only need a pair of numbers in order to define a function belonging to this family since we have agreed that the first number refers to the coefficient of ${e}^{x}\sin x$ and the second number to the coefficient of ${e}^{x}\cos x$. Do you see what I’m getting at?

Once that is established, $y=2{e}^{x}\sin x-{e}^{x}\cos x$ can be represented by $(2, -1)$. We might even choose to write  $a$ and  $b$ as the vector $\left ( \begin{matrix} a\\ b \end{matrix} \right )$. So we have that   $\left ( \begin{matrix} 2\\ -1 \end{matrix} \right )$ is in fact  $y=2{e}^{x}\sin x-{e}^{x}\cos x$ and $\left ( \begin{matrix} \sqrt{2}\\ \pi \end{matrix} \right )$  is  $y=\sqrt{2}{e}^{x}\sin x+\pi{e}^{x}\cos x$ and so on.

If we represent $y={e}^{x}\sin x$ as $y={e}^{x}\sin x+0{e}^{x}\cos x$, its vector form is then simply $\left ( \begin{matrix} 1\\ 0 \end{matrix} \right )$ and similarly $y={e}^{x}\cos x$ is $\left ( \begin{matrix} 0\\ 1 \end{matrix} \right )$, exactly like $\bf{i}$ and $\bf{j}$ in vector notation. We can think of ${e}^{x}\sin x$ and  ${e}^{x}\cos x$ as the building blocks of our functions or, to use mathematical terminology, the components of our functions. Our Cartesian plane is now used to describe a function space rather than spatial coordinates.

### Making a difference with a matrix

It’s all very well but so what? One very interesting feature of this family of functions becomes apparent when we differentiate $y=a{e}^{x}\sin x+b{e}^{x}\cos x$. Using the product rule, we have

\begin{equation*}
y’=a{e}^{x}\sin x+ a{e}^{x}\cos x+b{e}^{x}\cos x-b{e}^{x}\sin x
\end{equation*}

and, collecting like terms, we obtain

\begin{equation*}
y’= (a-b) {e}^{x}\sin x + (a+b) {e}^{x}\cos x.
\end{equation*}

It turns out that $y’$ is also composed of one component in ${e}^{x}\sin x$ and one in ${e}^{x}\cos x$, and therefore belongs to our family of functions. In this case we say that the function space is closed under differentiation.

Given a general function $y=\left ( \begin{matrix} a\\ b \end{matrix} \right )$  in the family, its derivative is then given by $y’=\left ( \begin{matrix} a-b\\ a+b \end{matrix} \right )$.

This is a surprising result and one that doesn’t apply to all families of functions. If you consider $y=ax{e}^{x} + b\cos x$, you can check that its derivative does not belong to the same family. But in our family it so happens that the derivative of both components, i.e. $y={e}^{x}\sin x=\left ( \begin{matrix} 1\\ 0 \end{matrix} \right )$ and $y={e}^{x}\cos x=\left ( \begin{matrix} 0\\ 1 \end{matrix} \right )$, belong to the family as well.

That means that we can build a matrix that will differentiate any function in the family, just like a transformation matrix. We wish to find a $2\times 2$ matrix $\mathbf{M}_{\text{diff}}$  such that

\begin{equation*}
\mathbf{M}_{\text{diff}} \left ( \begin{matrix} a\\ b \end{matrix} \right ) = \left ( \begin{matrix} a-b\\ a+b \end{matrix} \right )
\end{equation*}

It’s not hard to see that $\mathbf{M}_{\text{diff}} = \left ( \begin{matrix} 1 & -1 \\ 1 & 1 \end{matrix} \right )$ will do the trick.

For $y=2{e}^{x}\sin x-{e}^{x}\cos x$, we have $y’=3{e}^{x}\sin x+{e}^{x}\cos x$. In vector notation, $y=\left ( \begin{matrix} 2\\ -1 \end{matrix} \right )$ and its derivative is given by

\begin{equation*}
y’ = \left ( \begin{matrix} 1 & -1 \\ 1 & 1 \end{matrix} \right )  \left ( \begin{matrix} 2\\ -1 \end{matrix} \right ) = \left ( \begin{matrix} 3 \\ 1 \end{matrix} \right )
\end{equation*}

which is equivalent to $y’=3{e}^{x}\sin x+{e}^{x}\cos x$.

Of course this should always work since we have used the general form $y=a{e}^{x}\sin x+b{e}^{x}\cos x$ of the function to come up with the differentiating matrix. In our function space, differentiation is but a linear transformation of a function vector.

### Integrating matrices with calculus Manhattan, minus the hotdog sellers and yellow cabs everywhere.

Our next question is: would that work for integration as well? One might expect that it would, since integration is the inverse operation of differentiation, i.e. if you integrate the derivative of a function, you get back to the original function (disregarding the elusive $+C$). Probably, then, integration would generate functions within the family. We can always check.

Let’s use integration by parts on each of the components and then combine them to integrate $y=a{e}^{x}\sin x+b{e}^{x}\cos x$.

Starting with

\begin{equation*}
\int {e}^{x}\sin x \; \d x = {e}^{x}\sin x – \int {e}^{x}\cos x \; \d x
\end{equation*}

and using integration by parts again, we have

\begin{equation*}
\int {e}^{x}\sin x \; \d x = {e}^{x}\sin x – ({e}^{x}\cos x +\int {e}^{x}\sin x \; \d x).
\end{equation*}

\begin{equation*}
2 \int {e}^{x}\sin x \; \d x = {e}^{x}\sin x – {e}^{x}\cos x
\end{equation*}

and therefore

\begin{equation*}
\hspace{60pt} \int {e}^{x}\sin x \; \d x  = \frac{1}{2} {e}^{x}\sin x – \frac{1}{2} {e}^{x}\cos x. \hspace{50pt} (1)
\end{equation*}

Similarly we can show that

\begin{equation*}
\hspace{60pt} \int {e}^{x}\cos x \; \d x = \frac{1}{2} {e}^{x}\sin x + \frac{1}{2} {e}^{x}\cos x.  \hspace{50pt} (2)
\end{equation*}

Using (1) and (2),

\begin{align*}
\int (a{e}^{x}\sin x + b {e}^{x}\cos x) \d x &= a \left( \frac{1}{2} {e}^{x}\sin x – \frac{1}{2} {e}^{x}\cos x \right)  + b \left( \frac{1}{2} {e}^{x}\sin x + \frac{1}{2} {e}^{x}\cos x \right)
\end{align*}

and, re-arranging into components, we reach

\begin{equation*}
\int (a{e}^{x}\sin x + b {e}^{x}\cos x) \d x =  \frac{1}{2} (a+b) {e}^{x}\sin x + \frac{1}{2} (-a+b)  {e}^{x}\cos x .
\end{equation*}

As expected, our function space is also closed under integration. Similarly to differentiation we can therefore build an integrating matrix as follows:

\begin{equation*}
\mathbf{M}_{\text{int}} =  \left ( \begin{matrix}  \frac{1}{2} &  \frac{1}{2} \\ \\ –  \frac{1}{2}  &  \frac{1}{2} \end{matrix}  \right )
\end{equation*}

Here comes the punchline. And this really blows me away so I hope you will feel the same.

If integration is the inverse operation of differentiation, does it follow that the inverse of the differentiating matrix is the integrating matrix for our family of functions and vice-versa? Of course you know what the answer is: a resounding yes!

We found that the differentiating matrix is  $\mathbf{M}_{\text{diff}} = \left ( \begin{matrix} 1 & -1 \\ 1 & 1 \end{matrix} \right )$. Therefore its inverse is ${\mathbf{M}^{-1}_{\text{diff}}}= \frac{1}{2} \left ( \begin{matrix} 1 & 1 \\ -1 & 1 \end{matrix} \right )$ and so we have a precise equation

\begin{equation*}
{\mathbf{M}_{\text{int}}} =  {\mathbf{M}^{-1}_{\text{diff}}} = \frac{1}{2} \left ( \begin{matrix}  1 &  1  \\ -1 & 1 \end{matrix}  \right )
\end{equation*}

between the integrating matrix and the inverse of the differentiating matrix.

Even though we created a system whereby functions are represented as vectors, and differentiation and integration become linear transformations in the plane, the inherent invertibility of differentiation and integration is reflected in the invertibility of their corresponding matrices.

Another fascinating result arises when we consider higher order derivatives. We found that the derivative of $y = \left ( \begin{matrix} a \\ b \end{matrix} \right )$ is given by $y’ = \mathbf{M}_{\text{diff}} \left ( \begin{matrix} a \\ b \end{matrix} \right ) = \left ( \begin{matrix} a-b \\ a+b \end{matrix} \right )$ with $\mathbf{M}_{\text{diff}} = \left ( \begin{matrix} 1 & -1 \\ 1 & 1 \end{matrix} \right )$. If we now want to find the second derivative of  $y$, which in turn is the first derivative of $y’$, we only need to use $\mathbf{M}_{\text{diff}}$ to differentiate $y’$ as follows:

\begin{equation*}
y” = {\mathbf{M}_{\text{diff}}} y’ =  {\mathbf{M}_{\text{diff}} \mathbf{M}_{\text{diff}}} y
\end{equation*}

which leads to $y” = {\mathbf{M}^{2}_{\text{diff}}} y$. Following a similar inductive argument, we can conclude that the $n$th derivative of $y$ will be given by $y^{(n)} = {\mathbf{M}^{n}_{\text{diff}}} y$. So if we raise $\mathbf{M}_{\text{diff}}$ to the power of $n$ we construct a matrix that calculates the $n$th derivative of any member of our family of functions!

### Beyond the punchline

These ideas can be extended to higher dimensions as long as we define a family of functions that is closed under differentiation and integration. For example,  $y = a\sin x + b \cos x + c e^{x}$ is composed of three components and forms a function space which is closed under differentiation and integration. As this is a 3-dimensional space, its differentiating and integrating matrices are $3 \times 3$. And we don’t have to stop here. Think of $y = a\sin x + b \cos x + c e^{x} + de^{x}\sin x + fe^{x}\cos x$  — note that I used $f$  instead of $e$ to avoid confusion with $e^{x}$. The official address of the Empire State Building is $-34e^x \sin x + 5e^x \cos x$ (honestly… look it up!)

The connection between inverse operations and inverse matrices suggests that, given a function space closed under differentiation, the differentiating matrix will unfailingly render an inverse matrix that represents integration. However, this is not always the case. Consider the family of functions defined by $y = a +bx$. If we re-write $y$ as $y = ax^{0} + bx^{1}$, we can use vector notation to represent $y$ as $y = \left ( \begin{matrix} a \\ b \end{matrix} \right )$. This function space is closed under differentiation since $y’ = b = bx^{0} + 0x^{1} = \left ( \begin{matrix} b \\ 0 \end{matrix} \right )$ and hence $y’$ belongs to the function space. The differentiating matrix is therefore given by $\mathbf{M}_{\text{diff}} = \left ( \begin{matrix} 0 & 1 \\ 0 & 0 \end{matrix} \right )$.  Since $\det {\mathbf{M}_{\text{diff}}} = 0$,  $\mathbf{M}_{\text{diff}}$ has no inverse. Does that mean that it is not possible to integrate $y$? Of course not; we know how to integrate this function and the integral is $\int (a+bx) \d x=ax+\frac{1}{2}b{x}^{2}(+C)$. So why does $\mathbf{M}_{\text{diff}}$ have no inverse? Integration adds a quadratic term which is not a component of our family of functions. Therefore our function space is not closed under integration, i.e. integration generates a function that is outside our family of functions. As a result,  $\mathbf{M}_{\text{diff}}$ is non-invertible. If  $\mathbf{M}_{\text{diff}}$ had an inverse then that would be the integrating matrix and hence the function space would be closed under integration, which is not the case.

We have re-invented the 2D space as a function space. In our new construct, vectors represent functions and we can find matrix transformations that map functions to their derivatives and vice versa. Inherent properties of invertibility are preserved and we can even extend all these concepts to higher dimensions. Function space appears in various areas of mathematics from set theory to topology, but this particular use of matrices is not that well known. This seems the right place to profess our debt to Prof. FEA Johnson who teaches this topic at UCL.

I wonder if this more abstract approach to the Cartesian plane would be of any use in urban planning. Perhaps coordinate pairs could represent subjective qualities such as excitement and joy instead of addresses. Just imagine what Manhattan would look like. Dr Luciano Rila works in the Department of Mathematics at UCL and is also an Area Coordinator for the Further Maths Support Programme. He is keen to promote the beauty of mathematics and he also teaches static trapeze. Niki is a PhD student at UCL, working in analytic number theory.