# Constructing two matrices that do not commute

I need to construct square matrices $A$ and $B$ such that $AB=0$ but $BA \neq 0$.

I know matrix multiplication is not commutative, but I don't know how to construct such matrices. Thanks in advance.

Edit: looking for some simple way

• If you just want a special case, I provide $A=\left( \begin{matrix} 1& 0\\ 0& 0\end{matrix} \right),$ and $B=\left( \begin{matrix} 0& 1\\ 0& 0\end{matrix} \right).$ Just do some trick to make the columns and rows satisfy. – tommy xu3 Jan 2 '17 at 9:53
• Do you know how matrix multiplication works? Are you aware that there are infinitely many solutions to this problem? – pseudoeuclidean Jan 2 '17 at 9:54
• You could look at sufficient conditions for matrices to commute, and then try out some examples that do not satisfy these conditions. – TastyRomeo Jan 2 '17 at 9:55
• @pseudoeuclidean I don't know there are infinity solutions but I know how multiplication of matrix works. – Fawad Jan 2 '17 at 9:55
• @Ramanujan: oops my bad, sorry, ignore my comment. – Yves Daoust Jan 2 '17 at 10:42

## 8 Answers

A whole family: $$A=\begin{bmatrix}0&a\\0&a'\end{bmatrix}, \quad B=\begin{bmatrix}b&b'\\0&0\end{bmatrix}$$ with non-orthogonal vectors $(a,a')$ and $(b, b')$.

The problem reduces to solving a system of linear equations.

Let

$$x=\left( \begin{array}{cc} a & b \\ c & d \\ \end{array} \right)$$

$$y=\left( \begin{array}{cc} e & f \\ g & h \\ \end{array} \right)$$

Now solve the 4 linear equations resulting from $x.y=0$

The solution with the maximum number of free parameters (which is the one with $a\neq 0,b\neq 0$) is

$$xs=\left( \begin{array}{cc} a & b \\ c & \frac{b c}{a} \\ \end{array} \right)$$

$$ys=\left( \begin{array}{cc} e & f \\ -\frac{a e}{b} & -\frac{a f}{b} \\ \end{array} \right)$$

it contains 5 free parameters and the products are

$$xs.ys = \left( \begin{array}{cc} 0 & 0 \\ 0 & 0 \\ \end{array} \right)$$

$$ys.xs = \left( \begin{array}{cc} a e+c f & b e+\frac{b c f}{a} \\ -\frac{e a^2}{b}-\frac{c f a}{b} & -a e-c f \\ \end{array} \right)$$

The choice

$$\{a\to 1,b\to 1,c\to 0,e\to 1,f\to 0\}$$

gives

$$xx = \left( \begin{array}{cc} 1 & 1 \\ 0 & 0 \\ \end{array} \right)$$

$$yy = \left( \begin{array}{cc} 1 & 0 \\ -1 & 0 \\ \end{array} \right)$$

EDIT

As to the number of free parameters: to begin with we have 8 parameters, the elemnts of the two matrices. The 4 euqations would reduce them to 8-4 = 4, but as at most three equations are independent, the number is 5.

• thanks a lot. and values of a,b,c,e,f choice is ours? – Fawad Jan 2 '17 at 10:35
• Yes, the values of these 5 parameters are up to your choice. – Dr. Wolfgang Hintze Jan 2 '17 at 10:38

$A = \begin{bmatrix} 1 & 0 \\ 0 & 0 \end{bmatrix}$, $B = \begin{bmatrix} 0 & 0 \\ 1 & 0\end{bmatrix}.$ When thinking of examples try to think of most trivial ones like $O$, $I_n$ etc. These are also kind of trivial right?

$\newcommand{\im}{\mathrm{im}}$Perhaps it is worth recording a strategy to construct such an example, which may turn useful in other circumstances.

Will start with a $2 \times 2$ example, and then generalize.

First of all, both matrices have to have rank $1$. For, if $A$ has rank $2$, that is, it is invertibile, then $A B = 0$ implies $B = 0$ so that $B A = 0$ as well. If $A$ has rank zero, then $A = 0$, and both products are zero.

Now consider the underlying linear maps $\alpha, \beta$. We will have $\dim(\ker(\beta)) = \dim(\im(\beta)) = 1$.

Consider first the case when $\ker(\beta) \ne \im(\beta)$, so that if you choose non-zero vectors in $e_1 \in \ker(\beta)$ and $e_2 \in \im(\beta)$ you will get a basis of the underlying vector space. With respect to this basis you have $$B = \begin{bmatrix} 0 & 0\\ 0 & \lambda\\ \end{bmatrix}$$ with $\lambda \ne 0$.

If you want $A B = 0$, you need $A$ to be of the form $$A = \begin{bmatrix} x & 0\\ y & 0\\ \end{bmatrix}$$ or considering $\alpha$, you need $\alpha(e_2) = 0$, so that $\alpha(\im(\beta)) = 0$. Now compute $$B A = \begin{bmatrix} 0 & 0\\ \lambda y & 0\\ \end{bmatrix},$$ to see that $B A \ne 0$ iff $y \ne 0$. So you might as well choose $\lambda = y = 1$, $x = 0$.

When $\ker(\beta) = \im(\beta)$, let $e_1 \in \ker(\beta)$ be non-zero, and choose $e_2 \notin \ker(\beta)$ to get $$B = \begin{bmatrix} 0 & \lambda\\ 0 & 0\\ \end{bmatrix}$$ for some non-zero $\lambda$. For $A B = 0$ we need $$A = \begin{bmatrix} 0 & x\\ 0 & y\\ \end{bmatrix}$$ or $\alpha(e_1) = 0$. Now $$B A = \begin{bmatrix} 0 & \lambda y\\ 0 & 0\\ \end{bmatrix},$$ so again choose $y \ne 0$.

If you want an $n \times n$ example, with $n \ge 2$, take $n \times n$ block matrices $$\begin{bmatrix} A & 0\\ 0 & 0\\ \end{bmatrix}, \begin{bmatrix} B & 0\\ 0 & 0\\ \end{bmatrix}$$ where $A, B$ are as above, and $0$ are zero matrices of the appropriate size.

• I think the OP asked for general square matrices of any order. – vidyarthi Jan 2 '17 at 11:02
• what ker and im means? – Fawad Jan 2 '17 at 11:04
• @vidyarthi You are right, thanks, but everyone is giving $2 \times 2$ examples. Will edit. – Andreas Caranti Jan 2 '17 at 11:04
• @Ramanujan ker means kernel(Null space) and im means (Image), which are standard terms used in linear algebra – vidyarthi Jan 2 '17 at 11:06
• @vidyarthi, thanks once more. In other words, if $\gamma$ is a linear map on the vector space $V$, then, $\ker(\gamma) = \{v \in V : \gamma(v) = 0\}$ and $\newcommand{\im}{\mathrm{im}}$$\im(\gamma) = \{ \gamma(v) : v \in V \}. – Andreas Caranti Jan 2 '17 at 11:09 We can think of constructing such matrices by using the Rank-Nullity theorem. Note that one matrix should be singular by taking the determinant on both sides. Now choose columns arbitrarily in the singular matrix A such that the column space doesn't equal dimension of full space, i.e, choose at least one less linearly independent column than the order of matrix. But we must choose atleast one non-zero vector. For the other matrix B choose columns which are exactly in the null space of the first matrix. Then, we would get AB=O, whereas by virtue of there being some linearly independent vectors in A, we would get BA\neq O. I think taking examples in second order matrices and generalizing using block matrices would as Andreas answer has done it above. • why the downvote? – vidyarthi Jan 2 '17 at 10:25 • It is not true that one of the matrices has to be singular. – user2520938 Jan 2 '17 at 11:02 • @user2520938 The matrices are square, hence one of them must be singular, isnt it? – vidyarthi Jan 2 '17 at 11:03 • @vidyarthi yes. Otherwise you could multiply by an inverse and get the other one must be 0. This causes issues when you want to say that BA\neq 0. – Mark Jan 2 '17 at 11:07 • @user2520938 ok, give me an example of both non-singular matrices with their product zero. – vidyarthi Jan 2 '17 at 11:09 Pick \mathrm u, \mathrm v, \mathrm w \in \mathbb R^n \setminus \{0_n\} such that \neg (\mathrm u \perp \mathrm v) and \mathrm v \perp \mathrm w. Define$$\mathrm A := \mathrm u \mathrm v^{\top} \qquad \qquad \qquad \mathrm B := \mathrm w \mathrm v^{\top}$$whose traces are$$\mbox{tr} (\mathrm A) = \mathrm v^{\top} \mathrm u \neq 0 \qquad \qquad \qquad \mbox{tr} (\mathrm B) = \mathrm v^{\top} \mathrm w = 0$$Hence$$\mathrm A \mathrm B = \mathrm u \underbrace{\mathrm v^{\top} \mathrm w}_{= \mbox{tr} (\mathrm B)} \mathrm v^{\top} = \mbox{tr} (\mathrm B) \cdot \mathrm u \mathrm v^{\top} = \mbox{tr} (\mathrm B) \cdot \mathrm A = \mathrm O_n\mathrm B \mathrm A = \mathrm w \underbrace{\mathrm v^{\top}\mathrm u}_{= \mbox{tr} (\mathrm A)} \mathrm v^{\top} = \mbox{tr} (\mathrm A) \cdot \mathrm w \mathrm v^{\top} = \mbox{tr} (\mathrm A) \cdot \mathrm B \neq \mathrm O_n$$There is a quite easy general way to get an example. Saying AB=0 means that the image space of B must be contained in the kernel of A, while BA\neq0 means the image of A is not contained in the kernel of B. Clearly you won't get an example by choosing A or B to be zero or invertible, so their images and kernels have to be proper nonzero subspaces of the whole space V=K^n these matrices act upon. Now the rank-nullity theorem ties the dimensions of the kernel and image of the same matrix to each other (their sum must be~n), but that is the only inevitable relation. So you can start with a simple example for which AB=0, and if it happens that BA=0 too, you can modify say B in such a way that you keep its image space unchanged, but modify its kernel (to not contain the image of A). For instance, let A be a projection on some subspace U of V parallel to a complementary subspace W. To keep things simple take U the span of an initial k standard basis vectors and W the span of the remaining n-k vectors, so A is diagonal with first k diagonal entries equal to~1 and the remaining n-k diagonal entries equal to~0. You can assure AB=0 by having B be a projection on the subspace W (which is the kernel of A). Now the kernel of B has dimension~k, and we want this to not contain~U, image of A which does have dimension~k (so we just need those subspaces to differ). That excludes the most obvious choice of taking for~B the projection~P parallel to the complement U of~W (that's the diagonal matrix with entries 0 where A has~1 and vice versa). There are at least two ways to fix this. One is to simply choose a different complement U' of~W. This is easy to achieve, for instance by just changing one of the spanning (standard basis) vectors of U to have a nonzero coordinate for one of the (final standard basis) vectors spanning W. An easier and more concrete approach is to take the (diagonal) matrix of P, and perform some column operation(s) on it, which will not change the image (column space), but it will in general change the kernel. For instance just permute some of the zero columns with nonzero columns, which will work fine. Quite likely the result will no longer be a projection matrix at all, so this is a more radical change than obtained by projecting parallel to a different complementary subspace. Yet another more powerful (and maybe more "advanced"): Let A be a given matrix, now AB-BA can be rewritten with help of matrix multiplication and vectorization as: M_{AR}\text{vec}(B) - M_{AL}\text{vec}(B), where M_{AR} is a matrix performing multiplication from the Right by A and M_{AL} from Left by A. We can now first pick a vectorization \text{vec} and an objective matrix C and try to solve$$\min_B\{\|(M_{AR}-M_{AL})\text{vec}(B)-\text{vec}(C)\|\}$$Where$C = AB-BA\$ is something we can choose.