diff --git a/bench/data/groundtruth/math_mathjax_latex_4.jsonl b/bench/data/groundtruth/math_mathjax_latex_4.jsonl index ca96f3cf..4587cf0f 100644 --- a/bench/data/groundtruth/math_mathjax_latex_4.jsonl +++ b/bench/data/groundtruth/math_mathjax_latex_4.jsonl @@ -1 +1 @@ -{"url": "https://math.stackexchange.com/questions/4082284/solving-for-vector-contained-in-a-diagonal-matrix", "content": "Consider the following system of equations:\n\n$$\n\\mathbf{y}D_{\\mathbf{x}}+\\mathbf{z}D_{\\mathbf{y}}=\\mathbf{u}D_{\\mathbf{z}}\n$$\n\nwhere $\\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})$ ).\n\nMy 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\n\n$$\n(\\mathbf{y}e^T) \\odot I_n = D_{\\mathbf{y}}\n$$\n\nwhere $\\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}}$ :\n\n$$\n\\mathbf{y}(e^T \\odot I_n) \\neq D_{\\mathbf{y}}\n$$\n\nEdit: Oh, it seems that extracting $\\mathbf{y}$ in this case would be a simple as rewriting the equation above as\n\n$$\n\\mathbf{y}D_{\\mathbf{x}}+\\mathbf{y}D_{\\mathbf{z}}=\\mathbf{u}D_{\\mathbf{z}}\n$$\n\nbecause rewriting the equation this way would not change the terms along the diagonal of $\\mathbf{z}D_{\\mathbf{y}}$ . Then we can write\n\n$$\n\\mathbf{y}=\\mathbf{u}D_{\\mathbf{z}}D_{\\mathbf{x+z}}^{-1}\n$$\n\nBut then how would solve for $\\mathbf{y}$ in the following?\n\n$$\n\\mathbf{y}D_{\\mathbf{x}}+\\mathbf{y}D_{\\mathbf{y}}=\\mathbf{u}D_{\\mathbf{z}}\n$$\n\nI 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:\n\n$$\n\\mathbf{y^2} + \\mathbf{y}D_{\\mathbf{x}} = \\mathbf{u}D_{\\mathbf{z}}\n$$\n\nwhere $\\mathbf{y^2}$ is a vector where the elements are the squares of the corresponding elements of $\\mathbf{y}$ – that is,\\$\\mathbf{y^2} =\n\n$$\n\\begin{pmatrix} y_{1}^2 & y_{2}^2 & \\cdots & y_{n}^2 \\end{pmatrix}\n$$\n\n\\$.\n\nNext, what if we had an equation as follows?\n\n$$\n\\mathbf{y}D_{\\mathbf{x}}+\\mathbf{y}D_{\\mathbf{yM}}=\\mathbf{u}D_{\\mathbf{z}}\n$$\n\nwhere $\\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.\n\nI 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}}$ .\n\nSo, I have two questions here:\n\n1. Is my general intuition about what this equation would look like correct?\n2. Are there techniques to solve for the elements of $\\mathbf{y}$ in this system?\n\n## 1 Answer\n\n1\n\nI 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:\n\n$$\n\\mathbf{y}D_{\\mathbf{x}}+\\mathbf{z}D_{\\mathbf{y}}=\\mathbf{u}D_{\\mathbf{z}}\n$$\n\n$$\n\\mathbf{y}D_{\\mathbf{x}}=\\mathbf{u}D_{\\mathbf{z}}-\\mathbf{z}D_{\\mathbf{y}}\n$$\n\n$$\n\\mathbf{y}=\\bigr( \\mathbf{u}D_{\\mathbf{z}}-\\mathbf{z}D_{\\mathbf{y}} \\bigr) D_{\\mathbf{x}}^{-1}\n$$\n\nNote: I can't verify that your edit is correct because I don't understand what $D_{\\mathbf{x} + \\mathbf{z}}$ represents.\n\nEdit 1:\n\nThank 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.\n\nSince $D_{\\mathbf{x}} = \\text{diag}(\\mathbf{x})$ and similarly for the other matrices, we have\n\n$$\n\\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}}\n$$\n\nand multiplying through we have\n\n$$\n\\begin{align}\n\\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}}\\\\\n\\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}} \\\\\n\\begin{bmatrix} y_1 (x_1 + z_1) & \\cdots & y_n(x_n + z_n) \\end{bmatrix} &= \\mathbf{u}D_{\\mathbf{z}} \\\\\n\\end{align}\n$$\n\nTherefore, this can be written in matrix form as\n\n$$\n\\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}}\n$$\n\nor more concisely as\n\n$$\n\\mathbf{y} (D_{\\mathbf{x}} + D_{\\mathbf{z}} ) = \\mathbf{u} D_{\\mathbf{z}}\n$$\n\nwhich is exactly what is given in your edit:\n\n$$\n\\mathbf{y} = \\mathbf{u} D_{\\mathbf{z}} (D_{\\mathbf{x}} + D_{\\mathbf{z}} ) ^{-1}\n$$\n\nEdit 2:\n\nAs for the case where you have $\\mathbf{y}^2 + \\mathbf{y} D_{\\mathbf{x}} = \\mathbf{u} D_{\\mathbf{z}}$ where\\$\\mathbf{y}^2 =\n\n$$\n\\begin{bmatrix} y_1^2 & \\cdots & y_n^2 \\end{bmatrix}\n$$\n\n\\$, 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):\n\n$$\n\\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}}\n$$\n\nwhere we cannot solve for the matrix containing the $y$ variables because we cannot eliminate $\\mathbf{x}$ from the left side of the equation.\n\n- 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}$ . Commented Mar 31, 2021 at 5:45\n- 1 @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! – Ralff Commented Mar 31, 2021 at 6:15\n- 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. Commented Mar 31, 2021 at 17:38\n- @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. – Ralff Commented Mar 31, 2021 at 18:47\n\n## You must log in to answer this question.\n\n## Not the answer you're looking for? Browse other questions tagged\n\n## .\n", "main_html": "
\r\n \r\n\t\t\r\n
\r\n\r\n
\r\n \r\n\r\n\r\n\r\n
\r\n $\\begingroup$\r\n \r\n\r\n \r\n \r\n
\r\n\r\n\r\n\r\n\r\n \r\n \r\n
\r\n\r\n
\r\n\r\n

Consider the following system of equations:

\r\n

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

\r\n

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})$).

\r\n

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

\r\n

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

\r\n

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}}$:

\r\n

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

\r\n

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

\r\n

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

\r\n

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

\r\n

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

\r\n

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

\r\n

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

\r\n

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:

\r\n

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

\r\n

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}$.

\r\n

Next, what if we had an equation as follows?

\r\n

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

\r\n

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.

\r\n

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}}$.

\r\n

So, I have two questions here:

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

    \r\n 1 Answer\r\n \r\n

    \r\n
    \r\n \r\n
    \r\n
    \r\n\r\n\r\n\r\n\r\n
    \r\n
    \r\n
    \r\n\r\n
    \r\n \r\n \r\n
    \r\n1
    \r\n \r\n \r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n
    \r\n
    \r\n \r\n
    \r\n
    \r\n\r\n\r\n \r\n\r\n
    \r\n\r\n
    \r\n\r\n\r\n\r\n
    \r\n $\\begingroup$\r\n
    \r\n

    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:

    \r\n

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

    \r\n

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

    \r\n

    Edit 1:

    \r\n

    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.

    \r\n

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

    \r\n

    $$\r\n\\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}}\r\n$$

    \r\n

    and multiplying through we have

    \r\n

    $$\r\n\\begin{align}\r\n\\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}}\\\\\r\n\\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}} \\\\\r\n\\begin{bmatrix} y_1 (x_1 + z_1) & \\cdots & y_n(x_n + z_n) \\end{bmatrix} &= \\mathbf{u}D_{\\mathbf{z}} \\\\\r\n\\end{align}\r\n$$

    \r\n

    Therefore, this can be written in matrix form as

    \r\n

    $$\r\n\\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}}\r\n$$

    \r\n

    or more concisely as

    \r\n

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

    \r\n

    which is exactly what is given in your edit:

    \r\n

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

    \r\n

    Edit 2:

    \r\n

    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):

    \r\n

    $$\r\n\\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}}\r\n$$

    \r\n

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

    \r\n
    \r\n
    \r\n
    \r\n \r\n
    \r\n\r\n\r\n\r\n\r\n
    \r\n
    \r\n\r\n
    \r\n\r\n\r\n
    \r\n \r\n\r\n\r\n
    \r\n
    \r\n\r\n\r\n
    \r\n $\\endgroup$\r\n
    \r\n\r\n\r\n\r\n\r\n 4\r\n
    \r\n
    \r\n
      \r\n\r\n
    • \r\n
      \r\n
      \r\n
      \r\n
      \r\n
      \r\n
      \r\n $\\begingroup$\r\n 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}$.\r\n $\\endgroup$\r\n \r\n \r\n Commented\r\n Mar 31, 2021 at 5:45\r\n \r\n \r\n \r\n \r\n
      \r\n
      \r\n
    • \r\n
    • \r\n
      \r\n
      \r\n 1\r\n
      \r\n
      \r\n
      \r\n
      \r\n $\\begingroup$\r\n @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!\r\n $\\endgroup$\r\n
      \r\n– Ralff\r\n
      \r\n \r\n Commented\r\n Mar 31, 2021 at 6:15\r\n \r\n \r\n \r\n \r\n
      \r\n
      \r\n
    • \r\n
    • \r\n
      \r\n
      \r\n
      \r\n
      \r\n
      \r\n
      \r\n $\\begingroup$\r\n 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.\r\n $\\endgroup$\r\n \r\n \r\n Commented\r\n Mar 31, 2021 at 17:38\r\n \r\n
      \r\n
      \r\n
    • \r\n
    • \r\n
      \r\n
      \r\n
      \r\n
      \r\n
      \r\n
      \r\n $\\begingroup$\r\n @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.\r\n $\\endgroup$\r\n
      \r\n– Ralff\r\n
      \r\n \r\n Commented\r\n Mar 31, 2021 at 18:47\r\n \r\n
      \r\n
      \r\n
    • \r\n\r\n
    \r\n\t
    \r\n\r\n \r\n
    \r\n
    \r\n
    \r\n

    \r\n You must log in to answer this question.\r\n

    \r\n\r\n\r\n\r\n

    \r\n
    \r\nNot the answer you're looking for? Browse other questions tagged
      .
      \r\n

      \r\n
      \r\n ", "content_list": [[{"type": "paragraph", "raw_content": "

      Consider the following system of equations:

      ", "content": [{"c": "Consider the following system of equations:", "t": "text"}]}, {"type": "equation-interline", "raw_content": "

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

      ", "content": {"math_content": "\\mathbf{y}D_{\\mathbf{x}}+\\mathbf{z}D_{\\mathbf{y}}=\\mathbf{u}D_{\\mathbf{z}}", "math_type": "latex", "by": "mathjax"}}, {"type": "paragraph", "raw_content": "

      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})).

      ", "content": [{"c": "where", "t": "text"}, {"c": "\\mathbf{x}", "t": "equation-inline"}, {"c": ",", "t": "text"}, {"c": "\\mathbf{y}", "t": "equation-inline"}, {"c": ",", "t": "text"}, {"c": "\\mathbf{z}", "t": "equation-inline"}, {"c": ", and", "t": "text"}, {"c": "\\mathbf{u}", "t": "equation-inline"}, {"c": "are", "t": "text"}, {"c": "1\\times n", "t": "equation-inline"}, {"c": "vectors and", "t": "text"}, {"c": "D_{\\mathbf{x}}", "t": "equation-inline"}, {"c": ",", "t": "text"}, {"c": "D_{\\mathbf{y}}", "t": "equation-inline"}, {"c": ", and", "t": "text"}, {"c": "D_{\\mathbf{z}}", "t": "equation-inline"}, {"c": "are diagonal", "t": "text"}, {"c": "n\\times n", "t": "equation-inline"}, {"c": "matrices with", "t": "text"}, {"c": "\\mathbf{x}", "t": "equation-inline"}, {"c": ",", "t": "text"}, {"c": "\\mathbf{y}", "t": "equation-inline"}, {"c": ", and", "t": "text"}, {"c": "\\mathbf{z}", "t": "equation-inline"}, {"c": ", respectively, along their diagonals (i.e.,", "t": "text"}, {"c": "D_{\\mathbf{x}} = \\mathrm{diag}(\\mathbf{x})", "t": "equation-inline"}, {"c": ").", "t": "text"}]}, {"type": "paragraph", "raw_content": "

      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

      ", "content": [{"c": "My question is whether it is possible to solve for", "t": "text"}, {"c": "\\mathbf{y}", "t": "equation-inline"}, {"c": "here – both the", "t": "text"}, {"c": "\\mathbf{y}", "t": "equation-inline"}, {"c": "as a vector and the", "t": "text"}, {"c": "\\mathbf{y}", "t": "equation-inline"}, {"c": "along the diagonal of", "t": "text"}, {"c": "D_{\\mathbf{y}}", "t": "equation-inline"}, {"c": ". The problem is that I do not know of operations to pull", "t": "text"}, {"c": "\\mathbf{y}", "t": "equation-inline"}, {"c": "out of", "t": "text"}, {"c": "D_{\\mathbf{y}}", "t": "equation-inline"}, {"c": ". 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", "t": "text"}, {"c": "\\mathbf{y}", "t": "equation-inline"}, {"c": "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", "t": "text"}]}, {"type": "equation-interline", "raw_content": "

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

      ", "content": {"math_content": "(\\mathbf{y}e^T) \\odot I_n = D_{\\mathbf{y}}", "math_type": "latex", "by": "mathjax"}}, {"type": "paragraph", "raw_content": "

      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}}:

      ", "content": [{"c": "where", "t": "text"}, {"c": "\\odot", "t": "equation-inline"}, {"c": "is the Hadamard product and", "t": "text"}, {"c": "e^T = (1,1,\\ldots)\\in\\mathbb R^n", "t": "equation-inline"}, {"c": ". So, would it be possible to distribute out", "t": "text"}, {"c": "\\mathbf{y}", "t": "equation-inline"}, {"c": "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", "t": "text"}, {"c": "\\mathbf{y}", "t": "equation-inline"}, {"c": ", not", "t": "text"}, {"c": "D_{\\mathbf{y}}", "t": "equation-inline"}, {"c": ":", "t": "text"}]}, {"type": "equation-interline", "raw_content": "

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

      ", "content": {"math_content": "\\mathbf{y}(e^T \\odot I_n) \\neq D_{\\mathbf{y}}", "math_type": "latex", "by": "mathjax"}}, {"type": "paragraph", "raw_content": "

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

      ", "content": [{"c": "Edit: Oh, it seems that extracting", "t": "text"}, {"c": "\\mathbf{y}", "t": "equation-inline"}, {"c": "in this case would be a simple as rewriting the equation above as", "t": "text"}]}, {"type": "equation-interline", "raw_content": "

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

      ", "content": {"math_content": "\\mathbf{y}D_{\\mathbf{x}}+\\mathbf{y}D_{\\mathbf{z}}=\\mathbf{u}D_{\\mathbf{z}}", "math_type": "latex", "by": "mathjax"}}, {"type": "paragraph", "raw_content": "

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

      ", "content": [{"c": "because rewriting the equation this way would not change the terms along the diagonal of", "t": "text"}, {"c": "\\mathbf{z}D_{\\mathbf{y}}", "t": "equation-inline"}, {"c": ". Then we can write", "t": "text"}]}, {"type": "equation-interline", "raw_content": "

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

      ", "content": {"math_content": "\\mathbf{y}=\\mathbf{u}D_{\\mathbf{z}}D_{\\mathbf{x+z}}^{-1}", "math_type": "latex", "by": "mathjax"}}, {"type": "paragraph", "raw_content": "

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

      ", "content": [{"c": "But then how would solve for", "t": "text"}, {"c": "\\mathbf{y}", "t": "equation-inline"}, {"c": "in the following?", "t": "text"}]}, {"type": "equation-interline", "raw_content": "

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

      ", "content": {"math_content": "\\mathbf{y}D_{\\mathbf{x}}+\\mathbf{y}D_{\\mathbf{y}}=\\mathbf{u}D_{\\mathbf{z}}", "math_type": "latex", "by": "mathjax"}}, {"type": "paragraph", "raw_content": "

      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:

      ", "content": [{"c": "I think that in this case, it would not be possible to solve for a single vector", "t": "text"}, {"c": "\\mathbf{y}", "t": "equation-inline"}, {"c": "as in the previous case. Instead, we would have a system of polynomials:", "t": "text"}]}, {"type": "equation-interline", "raw_content": "

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

      ", "content": {"math_content": "\\mathbf{y^2} + \\mathbf{y}D_{\\mathbf{x}} = \\mathbf{u}D_{\\mathbf{z}}", "math_type": "latex", "by": "mathjax"}}, {"type": "paragraph", "raw_content": "

      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} =

      ", "content": [{"c": "where", "t": "text"}, {"c": "\\mathbf{y^2}", "t": "equation-inline"}, {"c": "is a vector where the elements are the squares of the corresponding elements of", "t": "text"}, {"c": "\\mathbf{y}", "t": "equation-inline"}, {"c": "– that is,$\\mathbf{y^2} =", "t": "text"}]}, {"type": "equation-interline", "raw_content": "

      \\begin{pmatrix} y_{1}^2 & y_{2}^2 & \\cdots & y_{n}^2 \\end{pmatrix}

      ", "content": {"math_content": "\\begin{pmatrix} y_{1}^2 & y_{2}^2 & \\cdots & y_{n}^2 \\end{pmatrix}", "math_type": "latex", "by": "mathjax"}}, {"type": "paragraph", "raw_content": "

      $.

      ", "content": [{"c": "$.", "t": "text"}]}, {"type": "paragraph", "raw_content": "

      Next, what if we had an equation as follows?

      ", "content": [{"c": "Next, what if we had an equation as follows?", "t": "text"}]}, {"type": "equation-interline", "raw_content": "

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

      ", "content": {"math_content": "\\mathbf{y}D_{\\mathbf{x}}+\\mathbf{y}D_{\\mathbf{yM}}=\\mathbf{u}D_{\\mathbf{z}}", "math_type": "latex", "by": "mathjax"}}, {"type": "paragraph", "raw_content": "

      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.

      ", "content": [{"c": "where", "t": "text"}, {"c": "\\mathbf{M}", "t": "equation-inline"}, {"c": "is an", "t": "text"}, {"c": "n \\times n", "t": "equation-inline"}, {"c": "matrix. Unlike the other matrices, it is not a diagonal matrix. Thus, in each element along the diagonal of", "t": "text"}, {"c": "D_{\\mathbf{yM}}", "t": "equation-inline"}, {"c": ", we have some linear combination.", "t": "text"}]}, {"type": "paragraph", "raw_content": "

      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}}.

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

      So, I have two questions here:

      ", "content": [{"c": "So, I have two questions here:", "t": "text"}]}, {"type": "list", "raw_content": "
      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?
      ", "content": {"items": [{"c": "Is my general intuition about what this equation would look like correct?"}, {"c": "Are there techniques to solve for the elements of $\\mathbf{y}$ in this system?"}], "list_attribute": "ordered", "list_nest_level": "1"}}, {"type": "title", "raw_content": "

      \n 1 Answer\n \n

      ", "content": {"title_content": "1 Answer", "level": "2"}}, {"type": "paragraph", "raw_content": "
      \n1
      ", "content": [{"c": "1", "t": "text"}]}, {"type": "paragraph", "raw_content": "

      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:

      ", "content": [{"c": "I am not sure what the notation", "t": "text"}, {"c": "D_\\mathbf{x}", "t": "equation-inline"}, {"c": ",", "t": "text"}, {"c": "D_\\mathbf{y}", "t": "equation-inline"}, {"c": ", and", "t": "text"}, {"c": "D_\\mathbf{z}", "t": "equation-inline"}, {"c": "represent and if the importance is significant, but assuming", "t": "text"}, {"c": "D_{\\mathbf{x}}", "t": "equation-inline"}, {"c": "is invertible, you may solve for", "t": "text"}, {"c": "\\mathbf{y}", "t": "equation-inline"}, {"c": "as follows given the original equation:", "t": "text"}]}, {"type": "equation-interline", "raw_content": "

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

      ", "content": {"math_content": "\\mathbf{y}D_{\\mathbf{x}}+\\mathbf{z}D_{\\mathbf{y}}=\\mathbf{u}D_{\\mathbf{z}}", "math_type": "latex", "by": "mathjax"}}, {"type": "equation-interline", "raw_content": "

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

      ", "content": {"math_content": "\\mathbf{y}D_{\\mathbf{x}}=\\mathbf{u}D_{\\mathbf{z}}-\\mathbf{z}D_{\\mathbf{y}}", "math_type": "latex", "by": "mathjax"}}, {"type": "equation-interline", "raw_content": "

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

      ", "content": {"math_content": "\\mathbf{y}=\\bigr( \\mathbf{u}D_{\\mathbf{z}}-\\mathbf{z}D_{\\mathbf{y}} \\bigr) D_{\\mathbf{x}}^{-1}", "math_type": "latex", "by": "mathjax"}}, {"type": "paragraph", "raw_content": "

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

      ", "content": [{"c": "Note: I can't verify that your edit is correct because I don't understand what", "t": "text"}, {"c": "D_{\\mathbf{x} + \\mathbf{z}}", "t": "equation-inline"}, {"c": "represents.", "t": "text"}]}, {"type": "paragraph", "raw_content": "

      Edit 1:

      ", "content": [{"c": "Edit 1:", "t": "text"}]}, {"type": "paragraph", "raw_content": "

      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.

      ", "content": [{"c": "Thank you for the response as I didn't realize the meaning of the matrices", "t": "text"}, {"c": "D_{\\mathbf{x}}", "t": "equation-inline"}, {"c": ",", "t": "text"}, {"c": "D_{\\mathbf{y}}", "t": "equation-inline"}, {"c": ", and", "t": "text"}, {"c": "D_{\\mathbf{z}}", "t": "equation-inline"}, {"c": ". Yes, your edit is correct, but perhaps, I can provide how I would work the problem if that is of use to you.", "t": "text"}]}, {"type": "paragraph", "raw_content": "

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

      ", "content": [{"c": "Since", "t": "text"}, {"c": "D_{\\mathbf{x}} = \\text{diag}(\\mathbf{x})", "t": "equation-inline"}, {"c": "and similarly for the other matrices, we have", "t": "text"}]}, {"type": "equation-interline", "raw_content": "

      $$\n\\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}}\n$$

      ", "content": {"math_content": "\\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}}", "math_type": "latex", "by": "mathjax"}}, {"type": "paragraph", "raw_content": "

      and multiplying through we have

      ", "content": [{"c": "and multiplying through we have", "t": "text"}]}, {"type": "equation-interline", "raw_content": "

      $$\n\\begin{align}\n\\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}}\\\\\n\\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}} \\\\\n\\begin{bmatrix} y_1 (x_1 + z_1) & \\cdots & y_n(x_n + z_n) \\end{bmatrix} &= \\mathbf{u}D_{\\mathbf{z}} \\\\\n\\end{align}\n$$

      ", "content": {"math_content": "\\begin{align}\n\\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}}\\\\\n\\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}} \\\\\n\\begin{bmatrix} y_1 (x_1 + z_1) & \\cdots & y_n(x_n + z_n) \\end{bmatrix} &= \\mathbf{u}D_{\\mathbf{z}} \\\\\n\\end{align}", "math_type": "latex", "by": "mathjax"}}, {"type": "paragraph", "raw_content": "

      Therefore, this can be written in matrix form as

      ", "content": [{"c": "Therefore, this can be written in matrix form as", "t": "text"}]}, {"type": "equation-interline", "raw_content": "

      $$\n\\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}}\n$$

      ", "content": {"math_content": "\\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}}", "math_type": "latex", "by": "mathjax"}}, {"type": "paragraph", "raw_content": "

      or more concisely as

      ", "content": [{"c": "or more concisely as", "t": "text"}]}, {"type": "equation-interline", "raw_content": "

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

      ", "content": {"math_content": "\\mathbf{y} (D_{\\mathbf{x}} + D_{\\mathbf{z}} ) = \\mathbf{u} D_{\\mathbf{z}}", "math_type": "latex", "by": "mathjax"}}, {"type": "paragraph", "raw_content": "

      which is exactly what is given in your edit:

      ", "content": [{"c": "which is exactly what is given in your edit:", "t": "text"}]}, {"type": "equation-interline", "raw_content": "

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

      ", "content": {"math_content": "\\mathbf{y} = \\mathbf{u} D_{\\mathbf{z}} (D_{\\mathbf{x}} + D_{\\mathbf{z}} ) ^{-1}", "math_type": "latex", "by": "mathjax"}}, {"type": "paragraph", "raw_content": "

      Edit 2:

      ", "content": [{"c": "Edit 2:", "t": "text"}]}, {"type": "paragraph", "raw_content": "

      As for the case where you have \\mathbf{y}^2 + \\mathbf{y} D_{\\mathbf{x}} = \\mathbf{u} D_{\\mathbf{z}} where $\\mathbf{y}^2 =

      ", "content": [{"c": "As for the case where you have", "t": "text"}, {"c": "\\mathbf{y}^2 + \\mathbf{y} D_{\\mathbf{x}} = \\mathbf{u} D_{\\mathbf{z}}", "t": "equation-inline"}, {"c": "where$\\mathbf{y}^2 =", "t": "text"}]}, {"type": "equation-interline", "raw_content": "

      \\begin{bmatrix} y_1^2 & \\cdots & y_n^2 \\end{bmatrix}

      ", "content": {"math_content": "\\begin{bmatrix} y_1^2 & \\cdots & y_n^2 \\end{bmatrix}", "math_type": "latex", "by": "mathjax"}}, {"type": "paragraph", "raw_content": "

      $, 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):

      ", "content": [{"c": "$, you would not be able to solve for", "t": "text"}, {"c": "\\mathbf{y}", "t": "equation-inline"}, {"c": "as far as I can tell... To see this, multiply together the matrices, which would give the following result (skipping intermediate steps):", "t": "text"}]}, {"type": "equation-interline", "raw_content": "

      $$\n\\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}}\n$$

      ", "content": {"math_content": "\\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}}", "math_type": "latex", "by": "mathjax"}}, {"type": "paragraph", "raw_content": "

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

      ", "content": [{"c": "where we cannot solve for the matrix containing the", "t": "text"}, {"c": "y", "t": "equation-inline"}, {"c": "variables because we cannot eliminate", "t": "text"}, {"c": "\\mathbf{x}", "t": "equation-inline"}, {"c": "from the left side of the equation.", "t": "text"}]}, {"type": "list", "raw_content": "", "content": {"items": [{"c": "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}$ . Commented Mar 31, 2021 at 5:45"}, {"c": "1 @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! – Ralff Commented Mar 31, 2021 at 6:15"}, {"c": "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. Commented Mar 31, 2021 at 17:38"}, {"c": "@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. – Ralff Commented Mar 31, 2021 at 18:47"}], "list_attribute": "unordered", "list_nest_level": "1"}}, {"type": "title", "raw_content": "

      \n You must log in to answer this question.\n

      ", "content": {"title_content": "You must log in to answer this question.", "level": "2"}}, {"type": "title", "raw_content": "

      \nNot the answer you're looking for? Browse other questions tagged

      ", "content": {"title_content": "Not the answer you're looking for? Browse other questions tagged", "level": "2"}}, {"type": "title", "raw_content": "

      .

      ", "content": {"title_content": ".", "level": "2"}}]], "html": "\r\n\r\n\r\n\r\n\r\n \r\n\r\n \r\n\r\n linear algebra - Solving for vector contained in a diagonal matrix - Mathematics Stack Exchange\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n\r\n \r\n \r\n\r\n\r\n\r\n \r\n \r\n\r\n\r\n\r\n\r\n \r\n\r\n\r\n \r\n\r\n\r\n \r\n \r\n\r\n\r\n \r\n \r\n\r\n\r\n\r\n \r\n \r\n \r\n \r\n\r\n\r\n
      \r\n\r\n\r\n\r\n\r\n\r\n
      \r\n
      \r\n
      \r\n\r\n\r\n
      \r\n Skip to main content\r\n\t
      \r\n\t\t\t\r\n\t\t\t
      \r\n\t\t\t\t
      \r\n\t\t\t
      \r\n\t\t\t\r\n\t\t\t
      \r\n\t\t\t\t
      \r\n\t\t\t\t\t

      Stack Exchange Network

      \r\n\t\t\t\t\t

      \r\n\t\t\t\t\t\tStack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.\r\n\t\t\t\t\t

      \r\n\t\t\t\t\tVisit Stack Exchange\r\n\t\t\t\t\t\r\n\t\t\t\t
      \r\n\t\t\t
      \r\n\r\n\r\n\r\n\r\n\r\n\t\t \r\n\r\n\r\n\r\n\r\n\r\n\t
      \r\n
      \r\n\r\n\t\r\n\r\n\r\n\r\n\r\n
      \r\n
      \r\n \r\n \"Mathematics\"\r\n \r\n\r\n
      \r\n
      \r\n\r\n
      \r\n\r\n\r\n\r\n\r\n
      \r\n
      \r\n \r\n
      \r\n\r\n\r\n\r\n
      \r\n
      \r\n\r\n
      \r\n

      Teams

      \r\n

      Q&A for work

      \r\n

      Connect and share knowledge within a single location that is structured and easy to search.

      \r\n \r\n Learn more about Teams\r\n \r\n
      \r\n\r\n
      \r\n \r\n
      \r\n
      \r\n\r\n\r\n\r\n\r\n
      \r\n\r\n\r\n\r\n
      \r\n\r\n\r\n\r\n
      \r\n \r\n\r\n
      \r\n\r\n\r\n \r\n
      \r\n
      \r\n Asked\r\n \r\n
      \r\n
      \r\n Modified\r\n 3 years, 9 months ago\r\n
      \r\n
      \r\n Viewed\r\n 234 times\r\n
      \r\n
      \r\n\r\n\r\n\r\n
      \r\n\r\n
      \r\n \r\n
      \r\n
      \r\n\t\t
      \r\n
      \r\n\r\n
      \r\n
      \r\n\r\n
      \r\n \r\n \r\n
      \r\n2
      \r\n \r\n \r\n \r\n \r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n \r\n\r\n
      \r\n\r\n
      \r\n\r\n\r\n\r\n
      \r\n $\\begingroup$\r\n
      \r\n\r\n

      Consider the following system of equations:

      \r\n

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

      \r\n

      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})$).

      \r\n

      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

      \r\n

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

      \r\n

      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}}$:

      \r\n

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

      \r\n

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

      \r\n

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

      \r\n

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

      \r\n

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

      \r\n

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

      \r\n

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

      \r\n

      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:

      \r\n

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

      \r\n

      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}$.

      \r\n

      Next, what if we had an equation as follows?

      \r\n

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

      \r\n

      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.

      \r\n

      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}}$.

      \r\n

      So, I have two questions here:

      \r\n
        \r\n
      1. Is my general intuition about what this equation would look like correct?
      2. \r\n
      3. Are there techniques to solve for the elements of $\\mathbf{y}$ in this system?
      4. \r\n
      \r\n
      \r\n\r\n
      \r\n
      \r\n
      \r\n\r\n \r\n
      \r\n
      \r\n
      \r\n\r\n
      \r\n
      \r\n
      \r\n\r\n\r\n\r\n
      \r\n\r\n
      \r\n\r\n
      \r\n Share\r\n
      \r\n\r\n
      \r\n \r\n
      \r\n\r\n\r\n
      \r\n \r\n
      \r\n\r\n\r\n\r\n\r\n\r\n\r\n
      \r\n
      \r\n
      \r\n
      \r\n\r\n
      \r\n
      \r\n
      \r\n \r\n\r\n
      \r\n
      \r\n\r\n
      \r\n
      \r\n Ryan da Silva\r\n
      \r\n\r\n
      \r\n
      \r\n
      \r\n
      \r\n
      \r\n
      \r\n
      \r\n
      \r\n asked Mar 29, 2021 at 23:19\r\n
      \r\n\r\n
      \r\n
      \r\n
      \"Ryan
      \r\n
      \r\n
      \r\n Ryan da SilvaRyan da Silva\r\n
      \r\n 6511 silver badge77 bronze badges\r\n
      \r\n
      \r\n
      \r\n\r\n\r\n
      \r\n
      \r\n
      \r\n $\\endgroup$\r\n
      \r\n\r\n\r\n\r\n\r\n \r\n
      \r\n
      \r\n
        \r\n\r\n
      \r\n\t
      \r\n\r\n \r\n
      \r\n
      \r\n\r\n
      \r\n\r\n\r\n\r\n\r\n
      \r\n \r\n
      \r\n
      \r\n
      \r\n

      \r\n 1 Answer\r\n 1\r\n

      \r\n
      \r\n
      \r\n\r\n\r\n
      \r\n
      \r\n \r\n \r\n Reset to default\r\n \r\n
      \r\n
      \r\n \r\n
      \r\n
      \r\n\r\n\r\n
      \r\n
      \r\n
      \r\n\r\n\r\n\r\n\r\n
      \r\n
      \r\n
      \r\n\r\n
      \r\n \r\n \r\n
      \r\n1
      \r\n \r\n \r\n \r\n \r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n
      \r\n
      \r\n \r\n
      \r\n
      \r\n\r\n\r\n \r\n\r\n
      \r\n\r\n
      \r\n\r\n\r\n\r\n
      \r\n $\\begingroup$\r\n
      \r\n

      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:

      \r\n

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

      \r\n

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

      \r\n

      Edit 1:

      \r\n

      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.

      \r\n

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

      \r\n

      $$\r\n\\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}}\r\n$$

      \r\n

      and multiplying through we have

      \r\n

      $$\r\n\\begin{align}\r\n\\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}}\\\\\r\n\\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}} \\\\\r\n\\begin{bmatrix} y_1 (x_1 + z_1) & \\cdots & y_n(x_n + z_n) \\end{bmatrix} &= \\mathbf{u}D_{\\mathbf{z}} \\\\\r\n\\end{align}\r\n$$

      \r\n

      Therefore, this can be written in matrix form as

      \r\n

      $$\r\n\\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}}\r\n$$

      \r\n

      or more concisely as

      \r\n

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

      \r\n

      which is exactly what is given in your edit:

      \r\n

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

      \r\n

      Edit 2:

      \r\n

      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):

      \r\n

      $$\r\n\\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}}\r\n$$

      \r\n

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

      \r\n
      \r\n
      \r\n
      \r\n \r\n
      \r\n\r\n\r\n\r\n
      \r\n\r\n
      \r\n\r\n
      \r\n Share\r\n
      \r\n\r\n
      \r\n \r\n
      \r\n\r\n\r\n
      \r\n \r\n
      \r\n\r\n\r\n\r\n\r\n\r\n\r\n
      \r\n
      \r\n
      \r\n
      \r\n
      \r\n
      \r\n
      \r\n \r\n\r\n
      \r\n
      \r\n\r\n
      \r\n
      \r\n\r\n
      \r\n\r\n
      \r\n
      \r\n
      \r\n
      \r\n\r\n\r\n
      \r\n
      \r\n
      \r\n
      \r\n answered Mar 30, 2021 at 8:19\r\n
      \r\n\r\n
      \r\n
      \r\n
      \"Ralff's
      \r\n
      \r\n
      \r\n RalffRalff\r\n
      \r\n 1,55199 silver badges2424 bronze badges\r\n
      \r\n
      \r\n
      \r\n\r\n\r\n
      \r\n
      \r\n\r\n\r\n
      \r\n $\\endgroup$\r\n
      \r\n\r\n\r\n\r\n\r\n 4\r\n
      \r\n
      \r\n
        \r\n\r\n
      • \r\n
        \r\n
        \r\n
        \r\n
        \r\n
        \r\n
        \r\n $\\begingroup$\r\n 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}$.\r\n $\\endgroup$\r\n
        \r\n– Ryan da Silva\r\n
        \r\n \r\n Commented\r\n Mar 31, 2021 at 5:45\r\n \r\n \r\n \r\n \r\n
        \r\n
        \r\n
      • \r\n
      • \r\n
        \r\n
        \r\n 1\r\n
        \r\n
        \r\n
        \r\n
        \r\n $\\begingroup$\r\n @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!\r\n $\\endgroup$\r\n
        \r\n– Ralff\r\n
        \r\n \r\n Commented\r\n Mar 31, 2021 at 6:15\r\n \r\n \r\n \r\n \r\n
        \r\n
        \r\n
      • \r\n
      • \r\n
        \r\n
        \r\n
        \r\n
        \r\n
        \r\n
        \r\n $\\begingroup$\r\n 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.\r\n $\\endgroup$\r\n
        \r\n– Ryan da Silva\r\n
        \r\n \r\n Commented\r\n Mar 31, 2021 at 17:38\r\n \r\n
        \r\n
        \r\n
      • \r\n
      • \r\n
        \r\n
        \r\n
        \r\n
        \r\n
        \r\n
        \r\n $\\begingroup$\r\n @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.\r\n $\\endgroup$\r\n
        \r\n– Ralff\r\n
        \r\n \r\n Commented\r\n Mar 31, 2021 at 18:47\r\n \r\n
        \r\n
        \r\n
      • \r\n\r\n
      \r\n\t
      \r\n\r\n \r\n
      \r\n
      \r\n
      \r\n

      \r\n You must log in to answer this question.\r\n

      \r\n\r\n\r\n\r\n

      \r\n
      \r\nNot the answer you're looking for? Browse other questions tagged .
      \r\n

      \r\n
      \r\n
      \r\n\r\n\r\n
      \r\n\r\n\r\n\r\n
      \r\n
      \r\n\t\t
      \r\n
      \r\n
      \r\n\t

      Linked

      \r\n\t \r\n
      \r\n\r\n\r\n\r\n\r\n\r\n \r\n \r\n\r\n\r\n\r\n\r\n\r\n
      \r\n

      \r\n \r\n Hot Network Questions\r\n \r\n

      \r\n \r\n\r\n \r\n more hot questions\r\n \r\n
      \r\n\r\n \r\n \r\n\r\n
      \r\n\r\n
      \r\n\r\n
      \r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n
      \r\n
      \r\n\r\n\r\n\r\n\r\n \r\n\r\n\r\n \r\n\r\n\r\n\r\n\r\n \r\n \r\n \r\n \r\n \r\n\r\n \r\n\r\n\r\n\r\n \r\n \r\n", "statics": {"paragraph": 28, "paragraph.text": 85, "equation-interline": 19, "paragraph.equation-inline": 57, "list": 2, "title": 4}} +{"url": "https://math.stackexchange.com/questions/4082284/solving-for-vector-contained-in-a-diagonal-matrix", "content": "Consider the following system of equations:\n\n$$\n\\mathbf{y}D_{\\mathbf{x}}+\\mathbf{z}D_{\\mathbf{y}}=\\mathbf{u}D_{\\mathbf{z}}\n$$\n\nwhere $\\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})$ ).\n\nMy 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\n\n$$\n(\\mathbf{y}e^T) \\odot I_n = D_{\\mathbf{y}}\n$$\n\nwhere $\\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}}$ :\n\n$$\n\\mathbf{y}(e^T \\odot I_n) \\neq D_{\\mathbf{y}}\n$$\n\nEdit: Oh, it seems that extracting $\\mathbf{y}$ in this case would be a simple as rewriting the equation above as\n\n$$\n\\mathbf{y}D_{\\mathbf{x}}+\\mathbf{y}D_{\\mathbf{z}}=\\mathbf{u}D_{\\mathbf{z}}\n$$\n\nbecause rewriting the equation this way would not change the terms along the diagonal of $\\mathbf{z}D_{\\mathbf{y}}$ . Then we can write\n\n$$\n\\mathbf{y}=\\mathbf{u}D_{\\mathbf{z}}D_{\\mathbf{x+z}}^{-1}\n$$\n\nBut then how would solve for $\\mathbf{y}$ in the following?\n\n$$\n\\mathbf{y}D_{\\mathbf{x}}+\\mathbf{y}D_{\\mathbf{y}}=\\mathbf{u}D_{\\mathbf{z}}\n$$\n\nI 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:\n\n$$\n\\mathbf{y^2} + \\mathbf{y}D_{\\mathbf{x}} = \\mathbf{u}D_{\\mathbf{z}}\n$$\n\nwhere $\\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}$ .\n\nNext, what if we had an equation as follows?\n\n$$\n\\mathbf{y}D_{\\mathbf{x}}+\\mathbf{y}D_{\\mathbf{yM}}=\\mathbf{u}D_{\\mathbf{z}}\n$$\n\nwhere $\\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.\n\nI 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}}$ .\n\nSo, I have two questions here:\n\n1. Is my general intuition about what this equation would look like correct?\n2. Are there techniques to solve for the elements of $\\mathbf{y}$ in this system?\n\n## 1 Answer\n\n1\n\nI 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:\n\n$$\n\\mathbf{y}D_{\\mathbf{x}}+\\mathbf{z}D_{\\mathbf{y}}=\\mathbf{u}D_{\\mathbf{z}}\n$$\n\n$$\n\\mathbf{y}D_{\\mathbf{x}}=\\mathbf{u}D_{\\mathbf{z}}-\\mathbf{z}D_{\\mathbf{y}}\n$$\n\n$$\n\\mathbf{y}=\\bigr( \\mathbf{u}D_{\\mathbf{z}}-\\mathbf{z}D_{\\mathbf{y}} \\bigr) D_{\\mathbf{x}}^{-1}\n$$\n\nNote: I can't verify that your edit is correct because I don't understand what $D_{\\mathbf{x} + \\mathbf{z}}$ represents.\n\nEdit 1:\n\nThank 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.\n\nSince $D_{\\mathbf{x}} = \\text{diag}(\\mathbf{x})$ and similarly for the other matrices, we have\n\n$$\n\\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}}\n$$\n\nand multiplying through we have\n\n$$\n\\begin{align}\n\\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}}\\\\\n\\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}} \\\\\n\\begin{bmatrix} y_1 (x_1 + z_1) & \\cdots & y_n(x_n + z_n) \\end{bmatrix} &= \\mathbf{u}D_{\\mathbf{z}} \\\\\n\\end{align}\n$$\n\nTherefore, this can be written in matrix form as\n\n$$\n\\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}}\n$$\n\nor more concisely as\n\n$$\n\\mathbf{y} (D_{\\mathbf{x}} + D_{\\mathbf{z}} ) = \\mathbf{u} D_{\\mathbf{z}}\n$$\n\nwhich is exactly what is given in your edit:\n\n$$\n\\mathbf{y} = \\mathbf{u} D_{\\mathbf{z}} (D_{\\mathbf{x}} + D_{\\mathbf{z}} ) ^{-1}\n$$\n\nEdit 2:\n\nAs 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):\n\n$$\n\\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}}\n$$\n\nwhere we cannot solve for the matrix containing the $y$ variables because we cannot eliminate $\\mathbf{x}$ from the left side of the equation.\n\n- 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}$. Commented Mar 31, 2021 at 5:45\n- 1 @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! – Ralff Commented Mar 31, 2021 at 6:15\n- 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. Commented Mar 31, 2021 at 17:38\n- @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. – Ralff Commented Mar 31, 2021 at 18:47\n\n## You must log in to answer this question.\n\n## Not the answer you're looking for? Browse other questions tagged\n\n## .\n", "main_html": "
      \r\n \r\n\t\t\r\n
      \r\n\r\n
      \r\n \r\n\r\n\r\n\r\n
      \r\n $\\begingroup$\r\n \r\n\r\n \r\n \r\n
      \r\n\r\n\r\n\r\n\r\n \r\n \r\n
      \r\n\r\n
      \r\n\r\n

      Consider the following system of equations:

      \r\n

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

      \r\n

      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})$).

      \r\n

      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

      \r\n

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

      \r\n

      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}}$:

      \r\n

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

      \r\n

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

      \r\n

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

      \r\n

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

      \r\n

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

      \r\n

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

      \r\n

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

      \r\n

      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:

      \r\n

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

      \r\n

      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}$.

      \r\n

      Next, what if we had an equation as follows?

      \r\n

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

      \r\n

      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.

      \r\n

      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}}$.

      \r\n

      So, I have two questions here:

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

        \r\n 1 Answer\r\n \r\n

        \r\n
        \r\n \r\n
        \r\n
        \r\n\r\n\r\n\r\n\r\n
        \r\n
        \r\n
        \r\n\r\n
        \r\n \r\n \r\n
        \r\n1
        \r\n \r\n \r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n
        \r\n
        \r\n \r\n
        \r\n
        \r\n\r\n\r\n \r\n\r\n
        \r\n\r\n
        \r\n\r\n\r\n\r\n
        \r\n $\\begingroup$\r\n
        \r\n

        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:

        \r\n

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

        \r\n

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

        \r\n

        Edit 1:

        \r\n

        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.

        \r\n

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

        \r\n

        $$\r\n\\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}}\r\n$$

        \r\n

        and multiplying through we have

        \r\n

        $$\r\n\\begin{align}\r\n\\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}}\\\\\r\n\\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}} \\\\\r\n\\begin{bmatrix} y_1 (x_1 + z_1) & \\cdots & y_n(x_n + z_n) \\end{bmatrix} &= \\mathbf{u}D_{\\mathbf{z}} \\\\\r\n\\end{align}\r\n$$

        \r\n

        Therefore, this can be written in matrix form as

        \r\n

        $$\r\n\\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}}\r\n$$

        \r\n

        or more concisely as

        \r\n

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

        \r\n

        which is exactly what is given in your edit:

        \r\n

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

        \r\n

        Edit 2:

        \r\n

        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):

        \r\n

        $$\r\n\\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}}\r\n$$

        \r\n

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

        \r\n
        \r\n
        \r\n
        \r\n \r\n
        \r\n\r\n\r\n\r\n\r\n
        \r\n
        \r\n\r\n
        \r\n\r\n\r\n
        \r\n \r\n\r\n\r\n
        \r\n
        \r\n\r\n\r\n
        \r\n $\\endgroup$\r\n
        \r\n\r\n\r\n\r\n\r\n 4\r\n
        \r\n
        \r\n
          \r\n\r\n
        • \r\n
          \r\n
          \r\n
          \r\n
          \r\n
          \r\n
          \r\n $\\begingroup$\r\n 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}$.\r\n $\\endgroup$\r\n \r\n \r\n Commented\r\n Mar 31, 2021 at 5:45\r\n \r\n \r\n \r\n \r\n
          \r\n
          \r\n
        • \r\n
        • \r\n
          \r\n
          \r\n 1\r\n
          \r\n
          \r\n
          \r\n
          \r\n $\\begingroup$\r\n @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!\r\n $\\endgroup$\r\n
          \r\n– Ralff\r\n
          \r\n \r\n Commented\r\n Mar 31, 2021 at 6:15\r\n \r\n \r\n \r\n \r\n
          \r\n
          \r\n
        • \r\n
        • \r\n
          \r\n
          \r\n
          \r\n
          \r\n
          \r\n
          \r\n $\\begingroup$\r\n 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.\r\n $\\endgroup$\r\n \r\n \r\n Commented\r\n Mar 31, 2021 at 17:38\r\n \r\n
          \r\n
          \r\n
        • \r\n
        • \r\n
          \r\n
          \r\n
          \r\n
          \r\n
          \r\n
          \r\n $\\begingroup$\r\n @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.\r\n $\\endgroup$\r\n
          \r\n– Ralff\r\n
          \r\n \r\n Commented\r\n Mar 31, 2021 at 18:47\r\n \r\n
          \r\n
          \r\n
        • \r\n\r\n
        \r\n\t
        \r\n\r\n \r\n
        \r\n
        \r\n
        \r\n

        \r\n You must log in to answer this question.\r\n

        \r\n\r\n\r\n\r\n

        \r\n
        \r\nNot the answer you're looking for? Browse other questions tagged
          .
          \r\n

          \r\n
          \r\n ", "content_list": [[{"type": "paragraph", "raw_content": "

          Consider the following system of equations:

          ", "content": [{"c": "Consider the following system of equations:", "t": "text"}]}, {"type": "equation-interline", "raw_content": "

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

          ", "content": {"math_content": "\\mathbf{y}D_{\\mathbf{x}}+\\mathbf{z}D_{\\mathbf{y}}=\\mathbf{u}D_{\\mathbf{z}}", "math_type": "latex", "by": "mathjax"}}, {"type": "paragraph", "raw_content": "

          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})).

          ", "content": [{"c": "where", "t": "text"}, {"c": "\\mathbf{x}", "t": "equation-inline"}, {"c": ",", "t": "text"}, {"c": "\\mathbf{y}", "t": "equation-inline"}, {"c": ",", "t": "text"}, {"c": "\\mathbf{z}", "t": "equation-inline"}, {"c": ", and", "t": "text"}, {"c": "\\mathbf{u}", "t": "equation-inline"}, {"c": "are", "t": "text"}, {"c": "1\\times n", "t": "equation-inline"}, {"c": "vectors and", "t": "text"}, {"c": "D_{\\mathbf{x}}", "t": "equation-inline"}, {"c": ",", "t": "text"}, {"c": "D_{\\mathbf{y}}", "t": "equation-inline"}, {"c": ", and", "t": "text"}, {"c": "D_{\\mathbf{z}}", "t": "equation-inline"}, {"c": "are diagonal", "t": "text"}, {"c": "n\\times n", "t": "equation-inline"}, {"c": "matrices with", "t": "text"}, {"c": "\\mathbf{x}", "t": "equation-inline"}, {"c": ",", "t": "text"}, {"c": "\\mathbf{y}", "t": "equation-inline"}, {"c": ", and", "t": "text"}, {"c": "\\mathbf{z}", "t": "equation-inline"}, {"c": ", respectively, along their diagonals (i.e.,", "t": "text"}, {"c": "D_{\\mathbf{x}} = \\mathrm{diag}(\\mathbf{x})", "t": "equation-inline"}, {"c": ").", "t": "text"}]}, {"type": "paragraph", "raw_content": "

          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

          ", "content": [{"c": "My question is whether it is possible to solve for", "t": "text"}, {"c": "\\mathbf{y}", "t": "equation-inline"}, {"c": "here – both the", "t": "text"}, {"c": "\\mathbf{y}", "t": "equation-inline"}, {"c": "as a vector and the", "t": "text"}, {"c": "\\mathbf{y}", "t": "equation-inline"}, {"c": "along the diagonal of", "t": "text"}, {"c": "D_{\\mathbf{y}}", "t": "equation-inline"}, {"c": ". The problem is that I do not know of operations to pull", "t": "text"}, {"c": "\\mathbf{y}", "t": "equation-inline"}, {"c": "out of", "t": "text"}, {"c": "D_{\\mathbf{y}}", "t": "equation-inline"}, {"c": ". 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", "t": "text"}, {"c": "\\mathbf{y}", "t": "equation-inline"}, {"c": "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", "t": "text"}]}, {"type": "equation-interline", "raw_content": "

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

          ", "content": {"math_content": "(\\mathbf{y}e^T) \\odot I_n = D_{\\mathbf{y}}", "math_type": "latex", "by": "mathjax"}}, {"type": "paragraph", "raw_content": "

          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}}:

          ", "content": [{"c": "where", "t": "text"}, {"c": "\\odot", "t": "equation-inline"}, {"c": "is the Hadamard product and", "t": "text"}, {"c": "e^T = (1,1,\\ldots)\\in\\mathbb R^n", "t": "equation-inline"}, {"c": ". So, would it be possible to distribute out", "t": "text"}, {"c": "\\mathbf{y}", "t": "equation-inline"}, {"c": "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", "t": "text"}, {"c": "\\mathbf{y}", "t": "equation-inline"}, {"c": ", not", "t": "text"}, {"c": "D_{\\mathbf{y}}", "t": "equation-inline"}, {"c": ":", "t": "text"}]}, {"type": "equation-interline", "raw_content": "

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

          ", "content": {"math_content": "\\mathbf{y}(e^T \\odot I_n) \\neq D_{\\mathbf{y}}", "math_type": "latex", "by": "mathjax"}}, {"type": "paragraph", "raw_content": "

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

          ", "content": [{"c": "Edit: Oh, it seems that extracting", "t": "text"}, {"c": "\\mathbf{y}", "t": "equation-inline"}, {"c": "in this case would be a simple as rewriting the equation above as", "t": "text"}]}, {"type": "equation-interline", "raw_content": "

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

          ", "content": {"math_content": "\\mathbf{y}D_{\\mathbf{x}}+\\mathbf{y}D_{\\mathbf{z}}=\\mathbf{u}D_{\\mathbf{z}}", "math_type": "latex", "by": "mathjax"}}, {"type": "paragraph", "raw_content": "

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

          ", "content": [{"c": "because rewriting the equation this way would not change the terms along the diagonal of", "t": "text"}, {"c": "\\mathbf{z}D_{\\mathbf{y}}", "t": "equation-inline"}, {"c": ". Then we can write", "t": "text"}]}, {"type": "equation-interline", "raw_content": "

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

          ", "content": {"math_content": "\\mathbf{y}=\\mathbf{u}D_{\\mathbf{z}}D_{\\mathbf{x+z}}^{-1}", "math_type": "latex", "by": "mathjax"}}, {"type": "paragraph", "raw_content": "

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

          ", "content": [{"c": "But then how would solve for", "t": "text"}, {"c": "\\mathbf{y}", "t": "equation-inline"}, {"c": "in the following?", "t": "text"}]}, {"type": "equation-interline", "raw_content": "

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

          ", "content": {"math_content": "\\mathbf{y}D_{\\mathbf{x}}+\\mathbf{y}D_{\\mathbf{y}}=\\mathbf{u}D_{\\mathbf{z}}", "math_type": "latex", "by": "mathjax"}}, {"type": "paragraph", "raw_content": "

          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:

          ", "content": [{"c": "I think that in this case, it would not be possible to solve for a single vector", "t": "text"}, {"c": "\\mathbf{y}", "t": "equation-inline"}, {"c": "as in the previous case. Instead, we would have a system of polynomials:", "t": "text"}]}, {"type": "equation-interline", "raw_content": "

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

          ", "content": {"math_content": "\\mathbf{y^2} + \\mathbf{y}D_{\\mathbf{x}} = \\mathbf{u}D_{\\mathbf{z}}", "math_type": "latex", "by": "mathjax"}}, {"type": "paragraph", "raw_content": "

          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}.

          ", "content": [{"c": "where", "t": "text"}, {"c": "\\mathbf{y^2}", "t": "equation-inline"}, {"c": "is a vector where the elements are the squares of the corresponding elements of", "t": "text"}, {"c": "\\mathbf{y}", "t": "equation-inline"}, {"c": "– that is,", "t": "text"}, {"c": "\\mathbf{y^2} = \\begin{pmatrix} y_{1}^2 & y_{2}^2 & \\cdots & y_{n}^2 \\end{pmatrix}", "t": "equation-inline"}, {"c": ".", "t": "text"}]}, {"type": "paragraph", "raw_content": "

          Next, what if we had an equation as follows?

          ", "content": [{"c": "Next, what if we had an equation as follows?", "t": "text"}]}, {"type": "equation-interline", "raw_content": "

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

          ", "content": {"math_content": "\\mathbf{y}D_{\\mathbf{x}}+\\mathbf{y}D_{\\mathbf{yM}}=\\mathbf{u}D_{\\mathbf{z}}", "math_type": "latex", "by": "mathjax"}}, {"type": "paragraph", "raw_content": "

          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.

          ", "content": [{"c": "where", "t": "text"}, {"c": "\\mathbf{M}", "t": "equation-inline"}, {"c": "is an", "t": "text"}, {"c": "n \\times n", "t": "equation-inline"}, {"c": "matrix. Unlike the other matrices, it is not a diagonal matrix. Thus, in each element along the diagonal of", "t": "text"}, {"c": "D_{\\mathbf{yM}}", "t": "equation-inline"}, {"c": ", we have some linear combination.", "t": "text"}]}, {"type": "paragraph", "raw_content": "

          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}}.

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

          So, I have two questions here:

          ", "content": [{"c": "So, I have two questions here:", "t": "text"}]}, {"type": "list", "raw_content": "
          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?
          ", "content": {"items": [{"c": "Is my general intuition about what this equation would look like correct?"}, {"c": "Are there techniques to solve for the elements of $\\mathbf{y}$ in this system?"}], "list_attribute": "ordered", "list_nest_level": "1"}}, {"type": "title", "raw_content": "

          \n 1 Answer\n \n

          ", "content": {"title_content": "1 Answer", "level": "2"}}, {"type": "paragraph", "raw_content": "
          \n1
          ", "content": [{"c": "1", "t": "text"}]}, {"type": "paragraph", "raw_content": "

          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:

          ", "content": [{"c": "I am not sure what the notation", "t": "text"}, {"c": "D_\\mathbf{x}", "t": "equation-inline"}, {"c": ",", "t": "text"}, {"c": "D_\\mathbf{y}", "t": "equation-inline"}, {"c": ", and", "t": "text"}, {"c": "D_\\mathbf{z}", "t": "equation-inline"}, {"c": "represent and if the importance is significant, but assuming", "t": "text"}, {"c": "D_{\\mathbf{x}}", "t": "equation-inline"}, {"c": "is invertible, you may solve for", "t": "text"}, {"c": "\\mathbf{y}", "t": "equation-inline"}, {"c": "as follows given the original equation:", "t": "text"}]}, {"type": "equation-interline", "raw_content": "

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

          ", "content": {"math_content": "\\mathbf{y}D_{\\mathbf{x}}+\\mathbf{z}D_{\\mathbf{y}}=\\mathbf{u}D_{\\mathbf{z}}", "math_type": "latex", "by": "mathjax"}}, {"type": "equation-interline", "raw_content": "

          \\mathbf{y}D_{\\mathbf{x}}=\\mathbf{u}D_{\\mathbf{z}}-\\mathbf{z}D_{\\mathbf{y}}

          ", "content": {"math_content": "\\mathbf{y}D_{\\mathbf{x}}=\\mathbf{u}D_{\\mathbf{z}}-\\mathbf{z}D_{\\mathbf{y}}", "math_type": "latex", "by": "mathjax"}}, {"type": "equation-interline", "raw_content": "

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

          ", "content": {"math_content": "\\mathbf{y}=\\bigr( \\mathbf{u}D_{\\mathbf{z}}-\\mathbf{z}D_{\\mathbf{y}} \\bigr) D_{\\mathbf{x}}^{-1}", "math_type": "latex", "by": "mathjax"}}, {"type": "paragraph", "raw_content": "

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

          ", "content": [{"c": "Note: I can't verify that your edit is correct because I don't understand what", "t": "text"}, {"c": "D_{\\mathbf{x} + \\mathbf{z}}", "t": "equation-inline"}, {"c": "represents.", "t": "text"}]}, {"type": "paragraph", "raw_content": "

          Edit 1:

          ", "content": [{"c": "Edit 1:", "t": "text"}]}, {"type": "paragraph", "raw_content": "

          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.

          ", "content": [{"c": "Thank you for the response as I didn't realize the meaning of the matrices", "t": "text"}, {"c": "D_{\\mathbf{x}}", "t": "equation-inline"}, {"c": ",", "t": "text"}, {"c": "D_{\\mathbf{y}}", "t": "equation-inline"}, {"c": ", and", "t": "text"}, {"c": "D_{\\mathbf{z}}", "t": "equation-inline"}, {"c": ". Yes, your edit is correct, but perhaps, I can provide how I would work the problem if that is of use to you.", "t": "text"}]}, {"type": "paragraph", "raw_content": "

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

          ", "content": [{"c": "Since", "t": "text"}, {"c": "D_{\\mathbf{x}} = \\text{diag}(\\mathbf{x})", "t": "equation-inline"}, {"c": "and similarly for the other matrices, we have", "t": "text"}]}, {"type": "equation-interline", "raw_content": "

          \\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}}

          ", "content": {"math_content": "\\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}}", "math_type": "latex", "by": "mathjax"}}, {"type": "paragraph", "raw_content": "

          and multiplying through we have

          ", "content": [{"c": "and multiplying through we have", "t": "text"}]}, {"type": "equation-interline", "raw_content": "

          \\begin{align}\n\\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}}\\\\\n\\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}} \\\\\n\\begin{bmatrix} y_1 (x_1 + z_1) & \\cdots & y_n(x_n + z_n) \\end{bmatrix} &= \\mathbf{u}D_{\\mathbf{z}} \\\\\n\\end{align}

          ", "content": {"math_content": "\\begin{align}\n\\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}}\\\\\n\\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}} \\\\\n\\begin{bmatrix} y_1 (x_1 + z_1) & \\cdots & y_n(x_n + z_n) \\end{bmatrix} &= \\mathbf{u}D_{\\mathbf{z}} \\\\\n\\end{align}", "math_type": "latex", "by": "mathjax"}}, {"type": "paragraph", "raw_content": "

          Therefore, this can be written in matrix form as

          ", "content": [{"c": "Therefore, this can be written in matrix form as", "t": "text"}]}, {"type": "equation-interline", "raw_content": "

          \\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}}

          ", "content": {"math_content": "\\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}}", "math_type": "latex", "by": "mathjax"}}, {"type": "paragraph", "raw_content": "

          or more concisely as

          ", "content": [{"c": "or more concisely as", "t": "text"}]}, {"type": "equation-interline", "raw_content": "

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

          ", "content": {"math_content": "\\mathbf{y} (D_{\\mathbf{x}} + D_{\\mathbf{z}} ) = \\mathbf{u} D_{\\mathbf{z}}", "math_type": "latex", "by": "mathjax"}}, {"type": "paragraph", "raw_content": "

          which is exactly what is given in your edit:

          ", "content": [{"c": "which is exactly what is given in your edit:", "t": "text"}]}, {"type": "equation-interline", "raw_content": "

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

          ", "content": {"math_content": "\\mathbf{y} = \\mathbf{u} D_{\\mathbf{z}} (D_{\\mathbf{x}} + D_{\\mathbf{z}} ) ^{-1}", "math_type": "latex", "by": "mathjax"}}, {"type": "paragraph", "raw_content": "

          Edit 2:

          ", "content": [{"c": "Edit 2:", "t": "text"}]}, {"type": "paragraph", "raw_content": "

          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):

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

          \\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}}

          ", "content": {"math_content": "\\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}}", "math_type": "latex", "by": "mathjax"}}, {"type": "paragraph", "raw_content": "

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

          ", "content": [{"c": "where we cannot solve for the matrix containing the", "t": "text"}, {"c": "y", "t": "equation-inline"}, {"c": "variables because we cannot eliminate", "t": "text"}, {"c": "\\mathbf{x}", "t": "equation-inline"}, {"c": "from the left side of the equation.", "t": "text"}]}, {"type": "list", "raw_content": "", "content": {"items": [{"c": "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}$. Commented Mar 31, 2021 at 5:45"}, {"c": "1 @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! – Ralff Commented Mar 31, 2021 at 6:15"}, {"c": "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. Commented Mar 31, 2021 at 17:38"}, {"c": "@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. – Ralff Commented Mar 31, 2021 at 18:47"}], "list_attribute": "unordered", "list_nest_level": "1"}}, {"type": "title", "raw_content": "

          \n You must log in to answer this question.\n

          ", "content": {"title_content": "You must log in to answer this question.", "level": "2"}}, {"type": "title", "raw_content": "

          \nNot the answer you're looking for? Browse other questions tagged

          ", "content": {"title_content": "Not the answer you're looking for? Browse other questions tagged", "level": "2"}}, {"type": "title", "raw_content": "

          .

          ", "content": {"title_content": ".", "level": "2"}}]], "html": "\r\n\r\n\r\n\r\n\r\n \r\n\r\n \r\n\r\n linear algebra - Solving for vector contained in a diagonal matrix - Mathematics Stack Exchange\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n\r\n \r\n \r\n\r\n\r\n\r\n \r\n \r\n\r\n\r\n\r\n\r\n \r\n\r\n\r\n \r\n\r\n\r\n \r\n \r\n\r\n\r\n \r\n \r\n\r\n\r\n\r\n \r\n \r\n \r\n \r\n\r\n\r\n
          \r\n\r\n\r\n\r\n\r\n\r\n
          \r\n
          \r\n
          \r\n\r\n\r\n
          \r\n Skip to main content\r\n\t
          \r\n\t\t\t\r\n\t\t\t
          \r\n\t\t\t\t
          \r\n\t\t\t
          \r\n\t\t\t\r\n\t\t\t
          \r\n\t\t\t\t
          \r\n\t\t\t\t\t

          Stack Exchange Network

          \r\n\t\t\t\t\t

          \r\n\t\t\t\t\t\tStack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.\r\n\t\t\t\t\t

          \r\n\t\t\t\t\tVisit Stack Exchange\r\n\t\t\t\t\t\r\n\t\t\t\t
          \r\n\t\t\t
          \r\n\r\n\r\n\r\n\r\n\r\n\t\t \r\n\r\n\r\n\r\n\r\n\r\n\t
          \r\n
          \r\n\r\n\t\r\n\r\n\r\n\r\n\r\n
          \r\n
          \r\n \r\n \"Mathematics\"\r\n \r\n\r\n
          \r\n
          \r\n\r\n
          \r\n\r\n\r\n\r\n\r\n
          \r\n
          \r\n \r\n
          \r\n\r\n\r\n\r\n
          \r\n
          \r\n\r\n
          \r\n

          Teams

          \r\n

          Q&A for work

          \r\n

          Connect and share knowledge within a single location that is structured and easy to search.

          \r\n \r\n Learn more about Teams\r\n \r\n
          \r\n\r\n
          \r\n \r\n
          \r\n
          \r\n\r\n\r\n\r\n\r\n
          \r\n\r\n\r\n\r\n
          \r\n\r\n\r\n\r\n
          \r\n \r\n\r\n
          \r\n\r\n\r\n \r\n
          \r\n
          \r\n Asked\r\n \r\n
          \r\n
          \r\n Modified\r\n 3 years, 9 months ago\r\n
          \r\n
          \r\n Viewed\r\n 234 times\r\n
          \r\n
          \r\n\r\n\r\n\r\n
          \r\n\r\n
          \r\n \r\n
          \r\n
          \r\n\t\t
          \r\n
          \r\n\r\n
          \r\n
          \r\n\r\n
          \r\n \r\n \r\n
          \r\n2
          \r\n \r\n \r\n \r\n \r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n \r\n\r\n
          \r\n\r\n
          \r\n\r\n\r\n\r\n
          \r\n $\\begingroup$\r\n
          \r\n\r\n

          Consider the following system of equations:

          \r\n

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

          \r\n

          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})$).

          \r\n

          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

          \r\n

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

          \r\n

          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}}$:

          \r\n

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

          \r\n

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

          \r\n

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

          \r\n

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

          \r\n

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

          \r\n

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

          \r\n

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

          \r\n

          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:

          \r\n

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

          \r\n

          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}$.

          \r\n

          Next, what if we had an equation as follows?

          \r\n

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

          \r\n

          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.

          \r\n

          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}}$.

          \r\n

          So, I have two questions here:

          \r\n
            \r\n
          1. Is my general intuition about what this equation would look like correct?
          2. \r\n
          3. Are there techniques to solve for the elements of $\\mathbf{y}$ in this system?
          4. \r\n
          \r\n
          \r\n\r\n
          \r\n
          \r\n
          \r\n\r\n \r\n
          \r\n
          \r\n
          \r\n\r\n
          \r\n
          \r\n
          \r\n\r\n\r\n\r\n
          \r\n\r\n
          \r\n\r\n
          \r\n Share\r\n
          \r\n\r\n
          \r\n \r\n
          \r\n\r\n\r\n
          \r\n \r\n
          \r\n\r\n\r\n\r\n\r\n\r\n\r\n
          \r\n
          \r\n
          \r\n
          \r\n\r\n
          \r\n
          \r\n
          \r\n \r\n\r\n
          \r\n
          \r\n\r\n
          \r\n
          \r\n Ryan da Silva\r\n
          \r\n\r\n
          \r\n
          \r\n
          \r\n
          \r\n
          \r\n
          \r\n
          \r\n
          \r\n asked Mar 29, 2021 at 23:19\r\n
          \r\n\r\n
          \r\n
          \r\n
          \"Ryan
          \r\n
          \r\n
          \r\n Ryan da SilvaRyan da Silva\r\n
          \r\n 6511 silver badge77 bronze badges\r\n
          \r\n
          \r\n
          \r\n\r\n\r\n
          \r\n
          \r\n
          \r\n $\\endgroup$\r\n
          \r\n\r\n\r\n\r\n\r\n \r\n
          \r\n
          \r\n
            \r\n\r\n
          \r\n\t
          \r\n\r\n \r\n
          \r\n
          \r\n\r\n
          \r\n\r\n\r\n\r\n\r\n
          \r\n \r\n
          \r\n
          \r\n
          \r\n

          \r\n 1 Answer\r\n 1\r\n

          \r\n
          \r\n
          \r\n\r\n\r\n
          \r\n
          \r\n \r\n \r\n Reset to default\r\n \r\n
          \r\n
          \r\n \r\n
          \r\n
          \r\n\r\n\r\n
          \r\n
          \r\n
          \r\n\r\n\r\n\r\n\r\n
          \r\n
          \r\n
          \r\n\r\n
          \r\n \r\n \r\n
          \r\n1
          \r\n \r\n \r\n \r\n \r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n
          \r\n
          \r\n \r\n
          \r\n
          \r\n\r\n\r\n \r\n\r\n
          \r\n\r\n
          \r\n\r\n\r\n\r\n
          \r\n $\\begingroup$\r\n
          \r\n

          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:

          \r\n

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

          \r\n

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

          \r\n

          Edit 1:

          \r\n

          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.

          \r\n

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

          \r\n

          $$\r\n\\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}}\r\n$$

          \r\n

          and multiplying through we have

          \r\n

          $$\r\n\\begin{align}\r\n\\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}}\\\\\r\n\\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}} \\\\\r\n\\begin{bmatrix} y_1 (x_1 + z_1) & \\cdots & y_n(x_n + z_n) \\end{bmatrix} &= \\mathbf{u}D_{\\mathbf{z}} \\\\\r\n\\end{align}\r\n$$

          \r\n

          Therefore, this can be written in matrix form as

          \r\n

          $$\r\n\\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}}\r\n$$

          \r\n

          or more concisely as

          \r\n

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

          \r\n

          which is exactly what is given in your edit:

          \r\n

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

          \r\n

          Edit 2:

          \r\n

          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):

          \r\n

          $$\r\n\\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}}\r\n$$

          \r\n

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

          \r\n
          \r\n
          \r\n
          \r\n \r\n
          \r\n\r\n\r\n\r\n
          \r\n\r\n
          \r\n\r\n
          \r\n Share\r\n
          \r\n\r\n
          \r\n \r\n
          \r\n\r\n\r\n
          \r\n \r\n
          \r\n\r\n\r\n\r\n\r\n\r\n\r\n
          \r\n
          \r\n
          \r\n
          \r\n
          \r\n
          \r\n
          \r\n \r\n\r\n
          \r\n
          \r\n\r\n
          \r\n
          \r\n\r\n
          \r\n\r\n
          \r\n
          \r\n
          \r\n
          \r\n\r\n\r\n
          \r\n
          \r\n
          \r\n
          \r\n answered Mar 30, 2021 at 8:19\r\n
          \r\n\r\n
          \r\n
          \r\n
          \"Ralff's
          \r\n
          \r\n
          \r\n RalffRalff\r\n
          \r\n 1,55199 silver badges2424 bronze badges\r\n
          \r\n
          \r\n
          \r\n\r\n\r\n
          \r\n
          \r\n\r\n\r\n
          \r\n $\\endgroup$\r\n
          \r\n\r\n\r\n\r\n\r\n 4\r\n
          \r\n
          \r\n
            \r\n\r\n
          • \r\n
            \r\n
            \r\n
            \r\n
            \r\n
            \r\n
            \r\n $\\begingroup$\r\n 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}$.\r\n $\\endgroup$\r\n
            \r\n– Ryan da Silva\r\n
            \r\n \r\n Commented\r\n Mar 31, 2021 at 5:45\r\n \r\n \r\n \r\n \r\n
            \r\n
            \r\n
          • \r\n
          • \r\n
            \r\n
            \r\n 1\r\n
            \r\n
            \r\n
            \r\n
            \r\n $\\begingroup$\r\n @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!\r\n $\\endgroup$\r\n
            \r\n– Ralff\r\n
            \r\n \r\n Commented\r\n Mar 31, 2021 at 6:15\r\n \r\n \r\n \r\n \r\n
            \r\n
            \r\n
          • \r\n
          • \r\n
            \r\n
            \r\n
            \r\n
            \r\n
            \r\n
            \r\n $\\begingroup$\r\n 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.\r\n $\\endgroup$\r\n
            \r\n– Ryan da Silva\r\n
            \r\n \r\n Commented\r\n Mar 31, 2021 at 17:38\r\n \r\n
            \r\n
            \r\n
          • \r\n
          • \r\n
            \r\n
            \r\n
            \r\n
            \r\n
            \r\n
            \r\n $\\begingroup$\r\n @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.\r\n $\\endgroup$\r\n
            \r\n– Ralff\r\n
            \r\n \r\n Commented\r\n Mar 31, 2021 at 18:47\r\n \r\n
            \r\n
            \r\n
          • \r\n\r\n
          \r\n\t
          \r\n\r\n \r\n
          \r\n
          \r\n
          \r\n

          \r\n You must log in to answer this question.\r\n

          \r\n\r\n\r\n\r\n

          \r\n
          \r\nNot the answer you're looking for? Browse other questions tagged .
          \r\n

          \r\n
          \r\n
          \r\n\r\n\r\n
          \r\n\r\n\r\n\r\n
          \r\n
          \r\n\t\t
          \r\n
          \r\n
          \r\n\t

          Linked

          \r\n\t \r\n
          \r\n\r\n\r\n\r\n\r\n\r\n \r\n \r\n\r\n\r\n\r\n\r\n\r\n
          \r\n

          \r\n \r\n Hot Network Questions\r\n \r\n

          \r\n \r\n\r\n \r\n more hot questions\r\n \r\n
          \r\n\r\n \r\n \r\n\r\n
          \r\n\r\n
          \r\n\r\n
          \r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n
          \r\n
          \r\n\r\n\r\n\r\n\r\n \r\n\r\n\r\n \r\n\r\n\r\n\r\n\r\n \r\n \r\n \r\n \r\n \r\n\r\n \r\n\r\n\r\n\r\n \r\n \r\n", "statics": {"paragraph": 26, "paragraph.text": 85, "equation-interline": 17, "paragraph.equation-inline": 59, "list": 2, "title": 4}} diff --git a/llm_web_kit/extractor/html/recognizer/cc_math/common.py b/llm_web_kit/extractor/html/recognizer/cc_math/common.py index 7e11cbc9..a81a0436 100644 --- a/llm_web_kit/extractor/html/recognizer/cc_math/common.py +++ b/llm_web_kit/extractor/html/recognizer/cc_math/common.py @@ -557,6 +557,8 @@ def process(match_text): return match math_text = self.extract_asciimath(match.strip('`').replace('\\','')) if asciimath_wrap else match wrapped_text = func(math_text) if func else math_text + # html保留原始的,而不是传入修改过的wrapped_text + original_wrapped = wrapped_text wrapped_text = self.wrap_math_md(wrapped_text) if not wrapped_text: return match @@ -566,7 +568,7 @@ def process(match_text): tail='', type=math_type, by=math_render, - html=wrapped_text + html=original_wrapped ) except Exception: return match diff --git a/llm_web_kit/extractor/html/recognizer/cc_math/render/mathjax.py b/llm_web_kit/extractor/html/recognizer/cc_math/render/mathjax.py index 381750cf..f4895a4f 100644 --- a/llm_web_kit/extractor/html/recognizer/cc_math/render/mathjax.py +++ b/llm_web_kit/extractor/html/recognizer/cc_math/render/mathjax.py @@ -269,7 +269,9 @@ def _find_math_in_element(self, element: HtmlElement, inline_pattern: re.Pattern # 跳过ccmath标签 from llm_web_kit.extractor.html.recognizer.recognizer import \ BaseHTMLElementRecognizer - if BaseHTMLElementRecognizer.is_cc_html(element): + + # 新增方法is_cc_tag_node,该方法值判断当前节点是否是cc标签,而不判断子节点 + if BaseHTMLElementRecognizer.is_cc_tag_node(element): return # 检查是否应该忽略该元素 diff --git a/llm_web_kit/extractor/html/recognizer/ccmath.py b/llm_web_kit/extractor/html/recognizer/ccmath.py index 57a98c4b..47896359 100644 --- a/llm_web_kit/extractor/html/recognizer/ccmath.py +++ b/llm_web_kit/extractor/html/recognizer/ccmath.py @@ -139,8 +139,6 @@ def process_ccmath_html(self, cc_html: str, o_html: str, math_render: BaseMathRe if ZHIHU.DOMAIN in self.cm.url and node.tag == 'span' and node.get('class') == ZHIHU.MATH: tag_script.process_zhihu_custom_tag(self.cm, math_render_type, node) - # if 'mathinsight.org' in self.cm.url and node.tag == 'span' and node.get('class') == '': - # tag = span, class 为 math-containerm, 或者 mathjax 或者 wp-katex-eq if node.tag == 'span' and node.get('class') and ( 'math-container' in node.get('class') or @@ -183,14 +181,17 @@ def process_ccmath_html(self, cc_html: str, o_html: str, math_render: BaseMathRe if node.tag == 'p' and len(node.getchildren()) == 0: tag_common_modify.modify_tree(self.cm, math_render_type, original_html, node, parent) - # TODO: 待优化,渲染器通用方案兜底 - try: - if math_render_type == MathRenderType.MATHJAX: - math_render.find_math(node) - except Exception as e: - raise HtmlMathMathjaxRenderRecognizerException(f'处理MathjaxRender数学公式失败: {e}') + # 修改:传入tree节点,mathjax方案作为process2,不参与上面process1节点的遍历 + if math_render_type: + try: + if math_render_type == MathRenderType.MATHJAX: + # 对 tree 节点应用 find_math + math_render.find_math(tree) + except Exception as e: + raise HtmlMathMathjaxRenderRecognizerException(f'处理MathjaxRender数学公式失败: {e}') + # 保存处理后的html - # with open('math_courses_processed.html', 'w', encoding='utf-8') as f: + # with open('test20250702_result.html', 'w', encoding='utf-8') as f: # f.write(self._element_to_html(tree)) except Exception as e: raise HtmlMathRecognizerException(f'处理数学公式失败: {e}') @@ -224,7 +225,10 @@ def process_ccmath_html(self, cc_html: str, o_html: str, math_render: BaseMathRe # ' ' # '

          这是p的text$$a^2 + b^2 = c^2$$这是span的tail这是b的text这是b的tail

          ' # ) - # with open(r'C:\Users\10412\.ssh\llm-webkit-mirror\tests\llm_web_kit\extractor\assets\extractor_chain_input\good_data\html\testmathjax.html', 'r', encoding='utf-8') as f: + # with open(r'C:\Users\10412\.ssh\llm-webkit-mirror\tests\st\test20250702.html', 'r', encoding='utf-8') as f: + # # with open( + # # r'C:\Users\10412\.ssh\llm-webkit-mirror\bench\data\origin\math_mathjax_asciimath_1.html', + # # 'r', encoding='utf-8') as f: # raw_html = f.read() # from llm_web_kit.libs.html_utils import html_to_element # root = html_to_element(raw_html) diff --git a/llm_web_kit/extractor/html/recognizer/recognizer.py b/llm_web_kit/extractor/html/recognizer/recognizer.py index 6ab1a5ef..570bf129 100644 --- a/llm_web_kit/extractor/html/recognizer/recognizer.py +++ b/llm_web_kit/extractor/html/recognizer/recognizer.py @@ -263,3 +263,18 @@ def is_cc_html(el: HtmlElement, tag_name: str | list = None) -> bool: # 构建XPath表达式,检查子元素是否包含目标标签 xpath_expr = ' or '.join([f'self::{tag}' for tag in tags]) return bool(el.xpath(f'.//*[{xpath_expr}]')) + + @staticmethod + def is_cc_tag_node(el: HtmlElement) -> bool: + """判断html片段是否是cc标签. + + 在is_cc_html上做修改,只判断该节点是否为cc标签,而不检查其子节点是否包含cc标签,用在mathjax渲染器方法中. + + Args: + el: str|HtmlElement: html片段或HtmlElement对象 + """ + default_tag_names = [ + CCTag.CC_CODE, CCTag.CC_MATH_INLINE, CCTag.CC_MATH_INTERLINE, CCTag.CC_IMAGE, CCTag.CC_VIDEO, + CCTag.CC_AUDIO, CCTag.CC_TABLE, CCTag.CC_LIST, CCTag.CC_TEXT, CCTag.CC_TITLE + ] + return hasattr(el, 'tag') and isinstance(el.tag, str) and el.tag in default_tag_names diff --git a/requirements/runtime.txt b/requirements/runtime.txt index 54329c4e..10b17d5b 100644 --- a/requirements/runtime.txt +++ b/requirements/runtime.txt @@ -11,7 +11,7 @@ jupyter==1.1.1 langdetect_zh==1.0.4 lightgbm==4.5.0 loguru==0.7.2 -lxml>=5.3.0 +lxml==5.3.0 nbconvert==7.16.6 nltk==3.8.1 notebook==7.4.2 diff --git a/tests/llm_web_kit/extractor/html/recognizer/assets/ccmath/math_physicsforums_2_1.html b/tests/llm_web_kit/extractor/html/recognizer/assets/ccmath/math_physicsforums_2_1.html index 60572add..b124687d 100644 --- a/tests/llm_web_kit/extractor/html/recognizer/assets/ccmath/math_physicsforums_2_1.html +++ b/tests/llm_web_kit/extractor/html/recognizer/assets/ccmath/math_physicsforums_2_1.html @@ -14,7 +14,7 @@ \langle \psi | \phi \rangle \quad \text{versus} \quad \braket{\psi}{\phi} [\hat{A}, \hat{B}] \quad \text{versus} \quad \comm{\hat{A}}{\hat{B}} \{\hat{A}, \hat{B}\} \quad \text{versus} \quad \acomm{\hat{A}}{\hat{B}} -\begin{pmatrix}a & b \\c & d\end{pmatrix} +\begin{pmatrix}a & b \\c & d\end{pmatrix} \quad \text{versus} \quad \mqty(a & b \\ c & d) |\psi\rangle \quad \text{versus} \quad \ket{\psi} \langle\psi| \quad \text{versus} \quad \bra{\psi} \hat{H}|\psi\rangle \quad \text{versus} \quad \op{H}{\psi} diff --git a/tests/llm_web_kit/extractor/html/recognizer/test_math.py b/tests/llm_web_kit/extractor/html/recognizer/test_math.py index bffb7167..98bf7155 100644 --- a/tests/llm_web_kit/extractor/html/recognizer/test_math.py +++ b/tests/llm_web_kit/extractor/html/recognizer/test_math.py @@ -54,10 +54,10 @@ ], 'raw_html': '

          $x = 5$,$$x=6$$

          ', 'expected': [ - ('

          x = 5,

          ', - '

          x = 5,

          '), - ('

          x=6

          ', - '

          x=6

          ') + ('

          x = 5,

          ', + '

          x = 5,

          '), + ('

          x=6

          ', + '

          x=6

          ') ] }, { @@ -67,9 +67,9 @@ ], 'raw_html': '

          $x = 5$,$$x=6$$,$x=4$

          ', 'expected': [ - ('

          x = 5,

          ', '

          x = 5,

          '), + ('

          x = 5,

          ', '

          x = 5,

          '), ('

          x=6

          ', '

          x=6

          '), - ('

          ,x=4

          ', '

          ,x=4

          ') + ('

          ,x=4

          ', '

          ,x=4

          ') ] }, { @@ -81,12 +81,12 @@ 'expected': [ ('

          By substituting

          ', '

          By substituting

          '), - ('

          x

          ', - '

          x

          '), + ('

          x

          ', + '

          x

          '), ('

          with

          ', '

          with

          '), - ('

          t - \\dfrac{b}{3a}

          ', - '

          t - \\dfrac{b}{3a}

          '), + ('

          t - \\dfrac{b}{3a}

          ', + '

          t - \\dfrac{b}{3a}

          '), ('

          , the general

          ', '

          , the general

          ') ] @@ -407,6 +407,19 @@ 'expected_formula': r'\begin{aligned} & p(r|s,a) \\ & \sum_{r\in\mathcal{R}(s,a)}p(r|s,a)=1\text{ for any }(s,a). \end{aligned}' } ] + +TEST_IS_CC_TAG_NODE = [ + { + 'input': r'

          行内公式1:$A+B=C$

          行内公式2:$a+b=c$。

          行间公式1:$$E+F=G$$。<\p>t - \\dfrac{b}{3a}

          行内公式3:$2A+2B=2C$。

          行间公式2:$$2E+2F=2G$$。

          ', + 'cc_tag': '1', + 'not_cc_tag': '6', + }, + { + 'input': r'

          x

          x

          行内公式1:$A+B=C$

          行间公式2$$D+E=F$$

          ', + 'cc_tag': '2', + 'not_cc_tag': '6', + } +] base_dir = Path(__file__).parent @@ -577,6 +590,35 @@ def test_zhihu_ztext_math(self): formula = element.xpath(f'//{expected_tag}/text()')[0] self.assertIn(test_case['expected_formula'], formula) + def test_is_cc_tag_node(self): + from llm_web_kit.extractor.html.recognizer.recognizer import \ + BaseHTMLElementRecognizer + for test_case in TEST_IS_CC_TAG_NODE: + with self.subTest(input=test_case['input']): + root = html_to_element(test_case['input']) + cc_tag_count = 0 + not_cc_tag_count = 0 + + def check_nodes(element): + nonlocal cc_tag_count, not_cc_tag_count + if element is None: + return + if BaseHTMLElementRecognizer.is_cc_tag_node(element): + cc_tag_count += 1 + return + else: + not_cc_tag_count += 1 + for child in element: + check_nodes(child) + # mathjax方案是传入根节点递归调用,与其保持一致 + check_nodes(root) + expected_cc_tag = int(test_case['cc_tag']) + expected_not_cc_tag = int(test_case['not_cc_tag']) + self.assertEqual(cc_tag_count, expected_cc_tag, + f'Expected {expected_cc_tag} cc tags, but found {cc_tag_count}') + self.assertEqual(not_cc_tag_count, expected_not_cc_tag, + f'Expected {expected_not_cc_tag} non-cc tags, but found {not_cc_tag_count}') + if __name__ == '__main__': r = TestMathRecognizer() diff --git a/tests/llm_web_kit/extractor/test_extractor_chain.py b/tests/llm_web_kit/extractor/test_extractor_chain.py index 93d91681..14eb2ec1 100644 --- a/tests/llm_web_kit/extractor/test_extractor_chain.py +++ b/tests/llm_web_kit/extractor/test_extractor_chain.py @@ -193,7 +193,7 @@ def test_html_pipeline_suit_2(self): self.assertEqual(result['track_id'], 'stackoverflow_math') html_content_list = result.get_content_list()[0] - assert len(html_content_list) == 24 + assert len(html_content_list) == 22 def test_mathlab_html_to_md(self): """测试第二个数据:这个数据会丢失一些文本信息.""" diff --git a/tests/st/test_st.py b/tests/st/test_st.py index 625e6b83..87c32e85 100644 --- a/tests/st/test_st.py +++ b/tests/st/test_st.py @@ -78,6 +78,8 @@ def test_st_bench(self): output_path=output_path, ) + failed_cases = [] + with open(self.pipeline_data_path, 'r', encoding='utf-8') as f: for line in f: data_json = json.loads(line.strip()) @@ -105,7 +107,14 @@ def test_st_bench(self): detail.finish() self.assertIsNotNone(summary) self.assertIsNotNone(detail) - self.assertEqual(summary.error_summary['count'], 0, msg=f'测试数据抽取有失败, 抽取失败的数据详情: {detail.to_dict()}') + # 修改,显示所有断言失败的数据,不仅是显示一条 + if failed_cases or summary.error_summary['count'] != 0: + msg = '' + if failed_cases: + msg += '有断言失败:\n' + '\n'.join(failed_cases) + '\n' + if summary.error_summary['count'] != 0: + msg += f'测试数据抽取有失败, 抽取失败的数据详情: {detail.to_dict()}' + self.fail(msg) if __name__ == '__main__':