Finding $x$ from $Ax = b$ with $QR$ factorization

119 Views Asked by At

I'm currently trying to find $x$ such as $A x = b$ where $A \in \mathbb{R}^{5\times 5}$, $x \in \mathbb{R}^{5}$ and $b \in \mathbb{R}^{5}$. I used for that the $QR$ factorisation. I know I have the good $Q$ and $R$ (verified with Octave). I had no right to reverse matrices in my exercice unless they are triangular like $R$. However, I can't find the right $x$. Here are my calculations:

$$Ax = b$$ $$\Longleftrightarrow QRx = b$$ $$\Longleftrightarrow Qy = b \ | \ y := Rx$$ $$\Longleftrightarrow y = Q^{-1} b$$ and: $$y = Rx$$ $$\Longleftrightarrow x = R^{-1}y$$ This result is wrong. Indeed, the Octave code:

clear all; close all; clc;

A = [2 6 5 1 7; ...
     6 9 2 2 3; ...
     7 9 0 6 5; ...
     1 1 6 6 7; ...
     2 7 7 3 9];
     
b = [1;2;3;4;5];
     
[Q, R] = qr(A);
norm(A - Q*R) 

y = Q*b; % inv(Q) = Q
x = inv(R) * y 

% Verifcation:

x_verif = inv(A) * b

gives me the wrong result for the value of $x$. Could you please tell me where my calculations are wrong ?

1

There are 1 best solutions below

5
On

To solve $Ax=b$ uniquely, one needs $A$ invertible. If it is, then the solution is $x=A^{-1}b.$ This fact has no need for $QR$ factorization, however if it happens that in $A=QR$ both $Q$ and $R$ are invertible, then the above solution becomes $x=(QR)^{-1}b=R^{-1}Q^{-1}b.$