MATLAB: Matrix solving via least-squares: Y = A*B where Y, A and B are all matrices

fitfittinglsqcurvefitmatrices

I've been trying to get the lsqcurvefit function to find B such that A*B = Y where B and Y are mxn matrices and A is a mxm matrix of constants. The closest advice I could find is HERE but it doesn't seem to want to work when the "function" is a matrix.
Any advice or direction is greatly appreciated. Is there a better function out there to use? I wrote up a convergence algorithm to solve this but I want to check the results against something that already exists and is proven. Plus, if lsqcurvefit is anything like fit, it'd have the added bonus of returning errors for each value.

Best Answer

Since your model is linear and you have linear constraints on B (its row sums), then LSQLIN is the better tool to use
b=lsqlin(C,d,[],[],Aeq,beq);
B=reshape(b,m,n);
where
C=kron(speye(n),A);
d=Y(:);
Aeq=kron(ones(1,n),speye(m));
beq=rowsums;