So is this the problem?
Minimize
with respect to

and

(

is the dimension of the vectors

and

)
I'd think you could put that problem directly into an nonlinear optimization program in Matlab.
Or following the usual minimization technique for solving the problem, set all the partial derivatives
This yields the equations
Then perhaps those equations could be put into a nonlinear equation solver.
Note: It seems to me there is a bit of freedom in the problem in that the vector

can be scaled arbitrarily and the

adjusted accordingly. So you may want to add a constraint like
