File Exchange

## Updating thin QR factorization

version 1.0.1 (4.55 KB) by
Update existing QR factorization of A when A is modified, such as rank one update, delete or insert a row or a column.

2 Downloads

Updated 21 Apr 2021

View License

Updating the thin QR factorization of A when A is modified. These functions run faster than qr when the dimension of A is large, such as 5000-by-50.

Rank one update: rankoneupdate(Q, R, v, u):
Update the thin QR factorization of A when A = A + vu'.
Example:
A = rand(5,3);
v = rand(5,1);
u = rand(3,1);
[Q, R] = qr(A,0);
[Q_1, R_1] = rankoneupdate(Q, R, v, u);

Deleting a row: deleterow(Q, R, k)
Update the thin QR factorization of A when the kth row of A is deleted.
Example:
A = rand(5,3);
[Q, R] = qr(A, 0);
[Q_1, R_1] = deleterow(Q, R, 3);

Deleting a column: deletecolumn(Q, R, k)
Update the thin QR factorization of A when the kth column of A is deleted.
Example:
A = rand(5,3);
[Q, R] = qr(A, 0);
[Q_1, R_1] = deletecolumn(Q, R, 2);

Inserting a row: insertrow(Q, R, u, k)
Update the thin QR factorization of A when vector u is inserted as the kth row of A.
Example:
A = rand(5, 3);
[Q, R] = qr(A,0);
u = rand(3, 1);
[Q_1, R_1] = insertrow(Q, R, u, 2);

Inserting a row: insertcolumn(Q, R, u, k)
Update the thin QR factorization of A when vector u is inserted as the kth column of A.
Example:
A = rand(5, 3);
[Q, R] = qr(A,0);
u = rand(5, 1);
[Q_1, R_1] = insertcolumn(Q, R, u, 2);

### Cite As

Meimei Chen (2021). Updating thin QR factorization (https://www.mathworks.com/matlabcentral/fileexchange/90835-updating-thin-qr-factorization), MATLAB Central File Exchange. Retrieved .

### Comments and Ratings (2)

Stuart Rogers

This thin QR library does not seem to maintain orthogonality of the columns of the returned matrix Q when the underlying matrix A is complex-valued. For example, for the complex valued matrix A+v*u', the updated 5x3 "orthogonal matrix" Q_1 has columns which are not orthogonal to each other.

>> A = rand(5,3)+1j*rand(5,3);
>> v = rand(5,1);
>> u = rand(3,1);
>> [Q, R] = qr(A,0);
>> [Q_1, R_1] = rankoneupdate(Q, R, v, u);
>> dot(Q_1(:,1),Q_1(:,2))

ans =

-0.0425 - 0.0257i

>> dot(Q_1(:,1),Q_1(:,3))

ans =

0.0565 + 0.0061i

>> dot(Q_1(:,2),Q_1(:,3))

ans =

-0.0479 - 0.0278i

Stuart Rogers

Is this code designed to work for complex matrices? I tried out some example complex matrices, and the upper triangular matrix R that was returned did not have real entries on the diagonal, as is required by definition of the QR factorization.

##### MATLAB Release Compatibility
Created with R2021a
Compatible with any release
##### Platform Compatibility
Windows macOS Linux

### Community Treasure Hunt

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

Start Hunting!