Main Content

fixed.qrAB

ComputeC=Q'Band upper-triangular factorR

Description

example

[C,R] = fixed.qrAB(A,B)computesC=Q'Band upper-triangular factorR. The function simultaneously performs Givens rotations toAandBto transformAintoRandBintoC.

This syntax is equivalent to

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

example

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

[ λ I n A ] R

and

[ 0 n , p B ] C

whereAis anm-by-nmatrix,Bis am-by-pmatrix, and λ is the regularization parameter.

This syntax is equivalent to

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

Examples

collapse all

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

Define the input matrices,A, andb.

rng('default'); m = 6; n = 3; p = 1; A = randn(m,n)
A =6×30.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×11.4090 1.4172 0.6715 -1.2075 0.7172 1.6302

Thefixed.qrABfunction returns the upper-triangular factor, R , and C = Q b .

[C, R] = fixed.qrAB(A,b)
C =3×1-0.3284 0.4055 2.5481
R =3×33.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 通过计算upper-triangular factor R , and C = Q b . 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, andb.

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

Use thefixed.qrABfunction to compute the upper-triangular factor, R , and C = Q b .

[C, R] = fixed.qrAB(A, b, 0.01)
C =5×1-0.6361 1.7663 1.5892 -2.0638 -0.1327
R =5×59.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 usingx = R\C. Computex = R\Cusing thefixed.qrMatrixSolvefunction.

x = fixed.qrMatrixSolve(R,C)
x =5×1-0.1148 0.2944 0.1650 -0.3355 -0.0224

Compare the result to computingx = A\bdirectly.

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 satisfiesC=Q'B.

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

Extended Capabilities

Version History

Introduced in R2020b