MATLAB: Optimization Problem: How to minimize a sum of matrices multipled by a vector

matlab functionoptimizationOptimization Toolbox

I have m NxN matrices called A1, A2, …, Am. Their entries are known.
I also have an Nx1 vector called X. Its entries are known.
I have an Nx1 vector called Y. Its entries are known.
I want to solve the following minimization problem for the scalars a1, a2, …, am:
MINIMIZE: (a1.A1 + a2.A2 + a3.A3 + …. + am.Am)X – Y
this equals: minimize (TX-Y) where T is an NxN matrix, X is Nx1, and Y is Nx1
How do I set up this problem to solve it in matlab? I tried looking in the optimization toolbox, but I failed to set up lsqlin in a way that solves this.

Best Answer

So the question is, how to construct T? It should be as simple as,
T=reshape( vertcat(A1,A2,..,Am)*X , N , [] );
Now you can just go and plug into LSQLIN.