A = [3 -6; 4 -8; 0 1]; b = [-1 7 2]'; [Q1,R] = qr(A,0) d = Q1'*b; bksolve(R, d) % remember back-subsitution method % equivalent (linear regression!) regress(b, A)