# Matrix equation optimization

Let s be a positive real number, let M be a matrix, and let $v_1, v_2$ be vectors. $v_2$ will only have 1's or 0's as entries.

Given M, $v_1$ and $v_2$, find an s such that $(sMv_1) \cdot v_2$ = 0.5. I don't need an exact solution, just some way to get pretty close. If it makes any difference, I'm trying to do this through MATLAB.

For example, I have M = $\begin{bmatrix}1 & 1/3 & 0 & 1/5 & 0 & 1/4 & 0 \\ 0 & 0 & 1/2 & 1/5 & 0 & 0 & 0 \\ 0 & 1/3 & 0 & 1/5 & 0 & 0 & 0 \\ 0 & 1/3 & 1/2 & 0 & 1/2 & 1/4 & 0\\ 0 & 0 & 0 & 1/5 & 0 & 1/4 & 0\\ 0 & 0 & 0 & 1/5 & 1/2 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 1/4 & 1\end{bmatrix}$, $v_1$ = $\begin{bmatrix} 0.15 \\ 0.15 \\ 0.10 \\ 0.25 \\ 0.10 \\ 0.20 \\ 0.50 \end{bmatrix}$ and $v_2$ = $\begin{bmatrix} 1 \\ 0 \\ 0 \\ 0 \\ 0 \\ 0 \\ 0 \end{bmatrix}$.

My code can already find the closest integers for s (in this case, s is between 2 and 3) but how can I find a better approximation of s?

$(sMv_1) \cdot v_2 = s (Mv_1) \cdot v_2 = s (Mv_1)^T v_2 = s v_1^T M^T v_2 = 0.5$
So $s = \frac{0.5}{v_1^T M^T v_2}$.
• This is the only possible solution for $s$ (depending on $M,v_1,v_2$, the resultant $s$ may be negative from this equation, in which case there doesn't exist a solution). Jun 15, 2017 at 2:19