$$\begin{array}{ll} \text{minimize} & \| A - B \|_F^2\\ \text{subject to} & B x = v\end{array}$$
where $B$ is an $m \times n$ matrix and $x$ is an $n$-vector where each element is $1/n$ (an averaging vector). In layman terms, I want to find the 'closest' matrix to $A$ that has a new average along the rows.
Now I might be completely off as this is the first time trying to solve such a problem but I thought I could do something like this. Please take me through the final steps and if my idea is completely wrong let me know why and what I should be doing.
Here is my attempt so far:
$$\text{Trace}\left[(A-B) (A-B)^{\mathsf{T}}\right]$$
I was hoping I could use the Lagrange method.
These are the identities I have found useful:
$$\frac{\partial \text{Trace}[x]}{\partial x}=\text{Trace}\left[\frac{\partial X}{\partial x}\right]$$
$$\text{Trace}[A+B]=\text{Trace}[A]+\text{Trace}[B]$$
$$\frac{\partial X^{\mathsf{T}}}{\partial x}=\left(\frac{\partial X}{\partial x}\right)^{\mathsf{T}}$$
So this is the problem I thought could be the way to solve it:
$$\text{Trace}\left[(A-B) (A-B)^{\mathsf{T}}\right]-\lambda (B x-v)$$
Finding the gradient(please let me know if I am wrong) and setting it to zero and solving for transpose of B I get:
$B^{\mathsf{T}}=A^{\mathsf{T}}+\frac{\lambda x}{2}$
However, I belive that what I have done is wrong or there is something I am missing because now B is a matrix + a vector as far as I can see, so the dimensions does not work.
Unfortunately I am out of my depth and I have started to read about optimization and how to solve similar problems but I need a answer to this quickly.
I am happy for any comments, improvements corrections that would make this useful for other people.
Thank you very much for any feedback!