Main Content

fixed.qrAB

Compute C = Q'B and upper-triangular factor R

Since R2020b

Description

[C,R] = fixed.qrAB(A,B) computes C = Q'B and upper-triangular factor R. The function simultaneously performs Givens rotations to A and B to transform A into R and B into C.

This syntax is equivalent to

[C,R] = qr(A,B)

example

[C,R] = fixed.qrAB(A,B,regularizationParameter) computes C and R using a regularization parameter value specified by regularizationParameter. When a regularization parameter is specified, the function simultaneously performs Givens rotations to transform

[λInA]R

and

[0n,pB]C

where A is an m-by-n matrix, B is a m-by-p matrix, and λ is the regularization parameter.

This syntax is equivalent to

[Q,R] = qr([regularizationParameter*eye(n); A], 0);
C = Q'[zeros(n,p);B];

example

Examples

collapse all

This example shows how to compute the upper-triangular factor R, and C=Qb.

Define the input matrices, A, and b.

rng('default');
m = 6;
n = 3;
p = 1;
A = randn(m,n)
A = 6×3

    0.5377   -0.4336    0.7254
    1.8339    0.3426   -0.0631
   -2.2588    3.5784    0.7147
    0.8622    2.7694   -0.2050
    0.3188   -1.3499   -0.1241
   -1.3077    3.0349    1.4897

b = randn(m,p)
b = 6×1

    1.4090
    1.4172
    0.6715
   -1.2075
    0.7172
    1.6302

The fixed.qrAB function returns the upper-triangular factor, R, and C=Qb.

[C, R] = fixed.qrAB(A,b)
C = 3×1

   -0.3284
    0.4055
    2.5481

R = 3×3

    3.3630   -2.8841   -1.0421
         0    4.8472    0.6885
         0         0    1.3258

This example shows how to solve a system of linear equations, Ax=b, by computing the upper-triangular factor R, and C=Qb. A regularization parameter can improve the conditioning of least squares problems, and reduce the variance of the estimates when solving linear systems of equations.

Define input matrices, A, and b.

rng('default');
m = 50;
n = 5;
p = 1;
A = randn(m,n);
b = randn(m,p);

Use the fixed.qrAB function to compute the upper-triangular factor, R, and C=Qb.

[C, R] = fixed.qrAB(A, b, 0.01)
C = 5×1

   -0.6361
    1.7663
    1.5892
   -2.0638
   -0.1327

R = 5×5

    9.0631    0.7471    0.4126   -0.3606    0.1883
         0    7.2515   -1.1145    0.6011   -0.7544
         0         0    7.6132   -0.9460   -0.7062
         0         0         0    6.3065   -2.3238
         0         0         0         0    5.9297

Use this result to solve Ax=b using x = R\C. Compute x = R\C using the fixed.qrMatrixSolve function.

x = fixed.qrMatrixSolve(R,C)
x = 5×1

   -0.1148
    0.2944
    0.1650
   -0.3355
   -0.0224

Compare the result to computing x = A\b directly.

x = A\b
x = 5×1

   -0.1148
    0.2944
    0.1650
   -0.3355
   -0.0224

Input Arguments

collapse all

Input coefficient matrix, specified as a matrix.

Data Types: single | double | fi
Complex Number Support: Yes

Right-hand side matrix, specified as a matrix.

Data Types: single | double | fi
Complex Number Support: Yes

Regularization parameter, specified as a nonnegative scalar. Small, positive values of the regularization parameter can improve the conditioning of the problem and reduce the variance of the estimates. While biased, the reduced variance of the estimate often results in a smaller mean squared error when compared to least-squares estimates.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fi

Output Arguments

collapse all

Linear system factor, returned as a matrix that satisfies C = Q'B.

Upper-triangular factor, returned as a matrix that satisfies A = QR.

Extended Capabilities

Version History

Introduced in R2020b