Search code examples
matlablinear-algebraequation-solving

Setting up a system of linear equations in matlab


I have the following equation that I want to solve:

H*b0 = M(Q+1)b(Q+1)+l+M'B

The unknowns are b0, b(q+1) and B. The sizes of the known matrices are:

H=(42 x 42)

M(Q+1) = (42 x 21-P)

l = (42 x 1)

M' = (42 x 4)

So I want to figure out how to find the vectors.

Is there a built in command that I could do to do this?

This comes from This paper

EDIT:: Size of unknowns should be (all are column vectors):

b0 = 21
b(q+1) = 21-P (P=4 in this case)
B = P (4 in this case)

Solution

  • First, rearrange your equation:

    H b0 - M(Q+1) B(Q+1) - M' B = l
    

    Now, you can concatenate variables. You will end up with an unknown vector (X) of size 42 + 21 + 4 = 67. And a coefficient matrix (A) of size 42 x 67

    X = [b0;  B(Q+1);  B ];   % <- don't need to execute this; just shows alignment
    A = [ H, -M(Q+1), -M'];
    

    Now you have an equation of the form:

    A X = l
    

    Now you can solve this in a least-squares sense with the \ operator:

    X = A \ l
    

    This X can be turned back into b0, B(Q+1), and B using the identity above in reverse:

    b0 = X(1:42);
    B(Q+1) = X(43:63);
    B = X(64:67);