Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Compute the full QR decomposition of a matrix
ResourceFunction["FullQRDecomposition"][m] yields the full QR decomposition for a numerical matrix m. The result is a list {q,r}, where q is a unitary matrix and r is an upper‐trapezoidal matrix. |
Compute the full QR decomposition for a 3×2 matrix with exact values:
In[1]:= |
|
Out[1]= |
|
In[2]:= |
|
Out[2]= |
|
Compute the full QR decomposition for a 2×3 matrix with approximate numerical values:
In[3]:= |
|
Out[3]= |
|
In[4]:= |
|
Out[4]= |
|
Use a 3×4 matrix:
In[5]:= |
|
Full QR decomposition computed with exact arithmetic:
In[6]:= |
|
Out[6]= |
|
Full QR decomposition computed with machine arithmetic:
In[7]:= |
|
Out[7]= |
|
In[8]:= |
|
Out[8]= |
|
Full QR decomposition computed with 24-digit arithmetic:
In[9]:= |
|
Out[9]= |
|
Full QR decomposition for a 3×3 matrix with random complex entries:
In[10]:= |
|
Out[10]= |
|
In[11]:= |
|
Out[11]= |
|
Use a 3×4 matrix:
In[12]:= |
|
Compute the full QR decomposition using machine arithmetic with pivoting:
In[13]:= |
|
Out[13]= |
|
The elements along the diagonal of r are in order of decreasing magnitude:
In[14]:= |
|
Out[14]= |
|
The matrix p is a permutation matrix:
In[15]:= |
|
Out[15]= |
|
FullQRDecomposition satisfies m.p==ConjugateTranspose[q].r:
In[16]:= |
|
Out[16]= |
|
Here is some data:
In[17]:= |
|
In[18]:= |
|
Out[18]= |
|
Set up a design matrix for fitting with basis functions 1, t, t2:
In[19]:= |
|
Out[19]= |
|
Find the full QR decomposition of m:
In[20]:= |
|
Out[20]= |
|
This finds a vector x such that is a minimum:
In[21]:= |
|
Out[21]= |
|
These are the coefficients for the least-squares fit:
In[22]:= |
|
Out[22]= |
|
In[23]:= |
|
Out[23]= |
|
Use a 3×4 matrix:
In[24]:= |
|
Compute the full QR decomposition:
In[25]:= |
|
The rows and columns of q are orthonormal:
In[26]:= |
|
Out[26]= |
|
In[27]:= |
|
Out[27]= |
|
Check that r is upper trapezoidal:
In[28]:= |
|
Out[28]= |
|
In[29]:= |
|
Out[29]= |
|
In[30]:= |
|
Out[30]= |
|
Check that m is equal to ConjugateTranspose[q].r:
In[31]:= |
|
Out[31]= |
|
This work is licensed under a Creative Commons Attribution 4.0 International License