Inverting a Weighted Rectangular Matrix in MATLAB


OBJECTIVE: Learn how to set up and invert an overdetermined system of equations L s = t in MATLAB. Understand difference between consistent and inconsistent equations, and apply weighting to equations to adjust for errors in each equation.

PROCEDURE:
  1. Define the 3x2 matrix L=[1 2; 2 1; 4 1] by typing
    
     L=[1 2; 2 1; 4 1] 
    
    
    
    Define the known RHS data vector by typing
    
    
    t= [3 ; 3 ; 5]
    
    
    
  2. The least squares solution is found by solving the normal equations [LT L] s = L T t , which can be done in MATLAB by typing
    
    
    s = inv(L'*L)*L'*t
    
    
    
  3. Form the squared length of residual vector (i.e., ||predicted t - observed t||2) by typing
    
    
    e = (L*s-t)'*(L*s-t)
    
    
    
    Are the equations consistent or inconsistent? Why?
  4. Repeat above 3 steps except now define t as
     
    
    t= [3 ; 2 ; 8]
     
    
    
    Are the equations consistent or inconsistent?

  5. Plot out each of the equations with the following commands.
    
    s=inv(L'*L)*L'*t;
    x=[-5:5];for i=1:3;plot(x,(t(i)-L(i,1)*x)/L(i,2));hold on;end
    xlabel('x');ylabel('y');plot(s(1),s(2),'*');hold off;axis([-5 5 -5 5]);
    
    Is the least squares solution (labeled as * in MATLAB graph) consistent with the expected "best" solution to all 3 equations?

  6. What if the RHS of the first equation was considered to likely to contain strong errors..with a variance of 22. To accomodate this error we might premultiply the system of equations by a diagonal-like matrix W=[1/22 0 0;0 1 0; 0 0 1], where the 1st equation has been down weighted by the inverse variance. Try down weighting other rows by adjusting values of W and rerun MATLAB script below.
    W=[1/22 0 0;0 1 0; 0 0 1] ;L=W*L;t=W*t;
    s=inv(L'*L)*L'*t;
    x=[-5:5];for i=1:3;plot(x,(t(i)-L(i,1)*x)/L(i,2));hold on;end
    xlabel('x');ylabel('y');plot(s(1),s(2),'*');
    hold off;axis([-5 5 -5 5]);