# Solving for vector contained in a diagonal matrix

Consider the following system of equations:

$$\mathbf{y}D_{\mathbf{x}}+\mathbf{z}D_{\mathbf{y}}=\mathbf{u}D_{\mathbf{z}}$$

where $$\mathbf{x}$$, $$\mathbf{y}$$, $$\mathbf{z}$$, and $$\mathbf{u}$$ are $$1\times n$$ vectors and $$D_{\mathbf{x}}$$, $$D_{\mathbf{y}}$$, and $$D_{\mathbf{z}}$$ are diagonal $$n\times n$$ matrices with $$\mathbf{x}$$, $$\mathbf{y}$$, and $$\mathbf{z}$$, respectively, along their diagonals (i.e., $$D_{\mathbf{x}} = \mathrm{diag}(\mathbf{x})$$).

My question is whether it is possible to solve for $$\mathbf{y}$$ here – both the $$\mathbf{y}$$ as a vector and the $$\mathbf{y}$$ along the diagonal of $$D_{\mathbf{y}}$$. The problem is that I do not know of operations to pull $$\mathbf{y}$$ out of $$D_{\mathbf{y}}$$. The one possibility that I have considered is to use the Hadamard product since this can be used to convert a vector into a diagonal matrix and vice versa, as discussed here. But I am not sure how this would work in this case, as it would be necessary to distribute $$\mathbf{y}$$ out of the resulting expression, and I don't know if this would be possible given the properties of the Hadamard product. That is, we could write

$$(\mathbf{y}e^T) \odot I_n = D_{\mathbf{y}}$$

where $$\odot$$ is the Hadamard product and $$e^T = (1,1,\ldots)\in\mathbb R^n$$. So, would it be possible to distribute out $$\mathbf{y}$$ and then move the remaining terms to the other side of the first equation above? For example, we couldn't do something like left-hand side since that would just be equal to $$\mathbf{y}$$, not $$D_{\mathbf{y}}$$:

$$\mathbf{y}(e^T \odot I_n) \neq D_{\mathbf{y}}$$

Edit: Oh, it seems that extracting $$\mathbf{y}$$ in this case would be a simple as rewriting the equation above as

$$\mathbf{y}D_{\mathbf{x}}+\mathbf{y}D_{\mathbf{z}}=\mathbf{u}D_{\mathbf{z}}$$

because rewriting the equation this way would not change the terms along the diagonal of $$\mathbf{z}D_{\mathbf{y}}$$. Then we can write

$$\mathbf{y}=\mathbf{u}D_{\mathbf{z}}D_{\mathbf{x+z}}^{-1}$$

But then how would solve for $$\mathbf{y}$$ in the following?

$$\mathbf{y}D_{\mathbf{x}}+\mathbf{y}D_{\mathbf{y}}=\mathbf{u}D_{\mathbf{z}}$$

I think that in this case, it would not be possible to solve for a single vector $$\mathbf{y}$$ as in the previous case. Instead, we would have a system of polynomials:

$$\mathbf{y^2} + \mathbf{y}D_{\mathbf{x}} = \mathbf{u}D_{\mathbf{z}}$$

where $$\mathbf{y^2}$$ is a vector where the elements are the squares of the corresponding elements of $$\mathbf{y}$$ – that is, $$\mathbf{y^2} = \begin{pmatrix} y_{1}^2 & y_{2}^2 & \cdots & y_{n}^2 \end{pmatrix}$$.

Next, what if we had an equation as follows?

$$\mathbf{y}D_{\mathbf{x}}+\mathbf{y}D_{\mathbf{yM}}=\mathbf{u}D_{\mathbf{z}}$$

where $$\mathbf{M}$$ is an $$n \times n$$ matrix. Unlike the other matrices, it is not a diagonal matrix. Thus, in each element along the diagonal of $$D_{\mathbf{yM}}$$, we have some linear combination.

I think in this case, the polynomial system of equations would be rather complicated. We would have the vector $$\mathbf{y^2}$$ again, but this time multiplied by some diagonal matrix based on the elements of $$\mathbf{M}$$ and $$D_{\mathbf{x}}$$ that is multiplied by a scalar ($$n$$, I believe). Then, we would have a set of vectors ($$n-1$$, I believe) that each have as elements different products of the elements in $$\mathbf{y}$$ (e.g., $$y_1 y_3$$) and are each multiplied by a scalar and a diagonal matrix composed of permutations of the elements in $$\mathbf{M}$$ and $$D_{\mathbf{x}}$$.

So, I have two questions here:

1. Is my general intuition about what this equation would look like correct?
2. Are there techniques to solve for the elements of $$\mathbf{y}$$ in this system?

I am not sure what the notation $$D_\mathbf{x}$$, $$D_\mathbf{y}$$, and $$D_\mathbf{z}$$ represent and if the importance is significant, but assuming $$D_{\mathbf{x}}$$ is invertible, you may solve for $$\mathbf{y}$$ as follows given the original equation:

$$\mathbf{y}D_{\mathbf{x}}+\mathbf{z}D_{\mathbf{y}}=\mathbf{u}D_{\mathbf{z}}$$ $$\mathbf{y}D_{\mathbf{x}}=\mathbf{u}D_{\mathbf{z}}-\mathbf{z}D_{\mathbf{y}}$$ $$\mathbf{y}=\bigr( \mathbf{u}D_{\mathbf{z}}-\mathbf{z}D_{\mathbf{y}} \bigr) D_{\mathbf{x}}^{-1}$$

Note: I can't verify that your edit is correct because I don't understand what $$D_{\mathbf{x} + \mathbf{z}}$$ represents.

Edit 1:

Thank you for the response as I didn't realize the meaning of the matrices $$D_{\mathbf{x}}$$, $$D_{\mathbf{y}}$$, and $$D_{\mathbf{z}}$$. Yes, your edit is correct, but perhaps, I can provide how I would work the problem if that is of use to you.

Since $$D_{\mathbf{x}} = \text{diag}(\mathbf{x})$$ and similarly for the other matrices, we have

$$\begin{bmatrix} y_1 & \cdots & y_n \end{bmatrix} \begin{bmatrix} x_1 & & \\ & \ddots & \\ & & x_n\end{bmatrix} + \begin{bmatrix} z_1 & \cdots & z_n \end{bmatrix} \begin{bmatrix} y_1 & & \\ & \ddots & \\ & & y_n\end{bmatrix} = \mathbf{u}D_{\mathbf{z}}$$

and multiplying through we have

\begin{align} \begin{bmatrix} y_1 x_1 & \cdots & y_n x_n \end{bmatrix} + \begin{bmatrix} y_1 z_1 & \cdots & y_n z_n \end{bmatrix} &= \mathbf{u}D_{\mathbf{z}}\\ \begin{bmatrix} y_1 x_1 + y_1 z_1 & \cdots & y_n x_n + y_n z_n \end{bmatrix} &= \mathbf{u}D_{\mathbf{z}} \\ \begin{bmatrix} y_1 (x_1 + z_1) & \cdots & y_n(x_n + z_n) \end{bmatrix} &= \mathbf{u}D_{\mathbf{z}} \\ \end{align}

Therefore, this can be written in matrix form as

$$\begin{bmatrix} y_1 & \cdots & y_n \end{bmatrix} \begin{bmatrix} x_1 + z_1 & & \\ & \ddots & \\ & & x_n + z_n \end{bmatrix} = \mathbf{u}D_{\mathbf{z}}$$

or more concisely as

$$\mathbf{y} (D_{\mathbf{x}} + D_{\mathbf{z}} ) = \mathbf{u} D_{\mathbf{z}}$$

which is exactly what is given in your edit:

$$\mathbf{y} = \mathbf{u} D_{\mathbf{z}} (D_{\mathbf{x}} + D_{\mathbf{z}} ) ^{-1}$$

Edit 2:

As for the case where you have $$\mathbf{y}^2 + \mathbf{y} D_{\mathbf{x}} = \mathbf{u} D_{\mathbf{z}}$$ where $$\mathbf{y}^2 = \begin{bmatrix} y_1^2 & \cdots & y_n^2 \end{bmatrix}$$, you would not be able to solve for $$\mathbf{y}$$ as far as I can tell... To see this, multiply together the matrices, which would give the following result (skipping intermediate steps):

$$\begin{bmatrix} x_1 & \cdots & x_n \end{bmatrix} \begin{bmatrix} y_1^2 + y_1 & & \\ & \ddots & \\ & & y_n^2 + y_n \end{bmatrix} = \mathbf{u}D_{\mathbf{z}}$$

where we cannot solve for the matrix containing the $$y$$ variables because we cannot eliminate $$\mathbf{x}$$ from the left side of the equation.

• My notation for, for example, $D_{\mathbf{x}}$ was intended to refer to $\mathrm{diag}(\mathbf{x})$. Thus, $D_{\mathbf{x+y}}$ means $\mathrm{diag}(\mathbf{x+y})$. Sorry if that was unclear. Furthermore, in the solution you provided, $\mathbf{y}$ is still along the diagonal of $D_{\mathbf{y}}$. My aim is to remove it so we can have an non-implicit expression for $\mathbf{y}$. Mar 31, 2021 at 5:45
• @RyandaSilva Ah. Thanks. I apologize I misunderstood the notation. I edited my question of how I would work the problem if that may be of any use to you. Your edit is indeed correct. Best of luck! Mar 31, 2021 at 6:15
• Thank you very much for the help and the kind wishes. If you have time, I have added a bit more to my original post that I would love to get your feedback on. Mar 31, 2021 at 17:38
• @RyandaSilva You're welcome! I made a mistake, so I updated my answer. Please, see the changes. I provided a hint for your additional edit but only for the $\mathbf{y}^2$ case. If you have a matrix with off diagonal terms, then the matrix multiplication will be slightly more complicated, but I suggest working out the multiplication by hand, so you can see the result. Mar 31, 2021 at 18:47