# Definition of a matrix by matching two vectors

There are two vectors:

$$\boldsymbol{\hat{y}} = (\hat{y_1}, \hat{y_2}, \dots, \hat{y_n})$$

$$\boldsymbol{{y}} = ({y_1}, {y_2}, \dots, {y_n})$$

The vectors $$\boldsymbol{\hat{y}}$$ and $$\boldsymbol{{y}}$$ have some matches, but also some values that do not match. From these vectors I would like to create a matrix, which contains like the identity matrix in the diagonal ones, but only if the values match, otherwise zero.

For example:

$$\boldsymbol{\hat{y}} = (1.0, 2.0, 3.0, 4.0)$$

$$\boldsymbol{{y}} = (1.0, 2.2, 3.0, 4.0)$$

From these vectors results:

$$M= \left(\begin{matrix}1&0&0&0\\0&0&0&0\\0&0&1&0\\0&0&0&1\end{matrix}\right)$$

Is there a way to describe the definition of $$M$$ mathematically?

[The] matrix, which contains like the identity matrix in the diagonal ones, but only if the values match, otherwise zero.

is a very mathematical description. Don't confuse lack of formulas for lack of mathematics. Personally, I would maybe write it a little differently, but that's mostly just to remove any potential for misinterpretation. For instance, saying that the matrix is diagonal, and explicitly stating that the non-zero entries are $$1$$ is a bit clearer than saying "contains like the identity matrix". At least to people who are used to reading mathematical texts.

Here is my suggestion:

The diagonal $$n\times n$$ matrix with $$1$$ in the diagonal entries corresponding to where $$y$$ and $$\hat y$$ are equal, and $$0$$ otherwise.

Alternately, if you really want some formulas, one can use matrix algebra to say

The maximal rank diagonal matrix $$A$$ with only $$0$$ and $$1$$ as entries for which $$Ay = A\hat y$$

• Many thanks for the effort! – Anne Bierhoff Oct 16 '19 at 6:40

An alternate way is as follows:

Let $$\hat y=(\hat y_1,\hat y_2,...,\hat y_n)$$ and $$y=( y_1, y_2,..., y_n)$$.

Define $$M=diag(a_{11}, a_{22},....,a_{nn})$$ as $$a_{ii}=1$$ if $$\hat y_i=y_i$$ and $$a_{ii}=0$$, otherwise.

• You could even use the $\delta$-function (or at least one of the variations on it) and let $a_{ii} = 1-\delta(\hat y_i-y_i)$. If you really want to fill in with formulas. – Arthur Oct 16 '19 at 7:06
• @Arthur...yes. I highly agree. Thanks a lot for pointing out, – Nitin Uniyal Oct 16 '19 at 11:03