Search code examples
matlableast-squares

Multiple linear system, same solution


I know how to solve the problem

Ax=B

with matlab, I just use mldivide to obtain x: x=A\B

But what if I have multiple basis A_i and multiple data B_i but the nature of the problem suggests me that the solution x must be the same for every i?


Solution

  • You could try stacking the A matrices and B vectors to obtain a larger least squares system. That is, form

    A = (A_1)
        ...
        (A_n)
    

    and

    B = (B_1)
        ...
        (B_n)
    

    and then solve

    A*x = B 
    

    in the least squares sense

    The solution x to such a system will be the value that minimises

    Sum{ || A_i*x - B_i ||^2 }