QR Factorization for Inconsistent Linear System

2 views (last 30 days)

I am trying to recreate the problem found [here][1] on finding the least squares solution to an inconsistent linear system via QR factorization. Can someone explain the part about adding on vectors so that Q will span $R^5$? When I try to go through this in Matlab using the qr built-in function, my new R matrix is a 5x5 instead of a 5x3. Below is the code that I have thus far. From what I can tell, the only error is that my new R matrix is coming out as the wrong dimension.

    A = [3 -1 2; 4 1 0; -3 2 1; 1 1 5; -2 0 3];
    b = [10; 10; -5; 15; 0];
    [Q,R]=qr(A,0)
    % Add on additional vector to Q in order to span R^4
    Qt = [Q(1,1) Q(1,2) Q(1,3) 1 0; Q(2,1) Q(2,2) Q(2,3) 0 1; Q(3,1) Q(3,2) Q(3,3) 0 0; Q(4,1) Q(4,2) Q(4,3) 0 0; Q(5,1) Q(5,2) Q(5,3) 0 0];
    [Qnew,Rnew]=qr(Qt,0);
    % Multiply Qnew with given b:
    Qnewtran = transpose(Qnew);
    bnew = Qnewtran*b;
    x = Rnew\bnew
[1]: http://homepages.se.edu/kfrinkle/files/2014/06/CS3513Fall2006homework8solutions.pdf

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!