fixed.qlessQRMatrixSolve

Solve system of linear equations (A'A)x = B for x using Q-less QR decomposition

Description

example

x = fixed.qlessQRMatrixSolve(A, B) solves the system of linear equations (A'A)x = B using QR decomposition, without computing the Q value.

The result of this code is equivalent to computing

[~,R] = qr(A,0);
x = R\(R'\B)
or
x = (A'*A)\B

example

x = fixed.qlessQRMatrixSolve(A, B, outputType) returns the solution to the system of linear equations (A'A)x = B as a variable with the output type specified by outputType.

x = fixed.qlessQRMatrixSolve(A, B, outputType, forgettingFactor) returns the solution to the system of linear equations, with the forgettingFactor multiplied by R after each row of A is processed.

Examples

collapse all

This example shows how to solve the system of linear equations $\left({\mathit{A}}^{\prime }\mathit{A}\right)\mathit{x}=\mathit{b}$ using QR decomposition, without explicitly calculating the Q factor of the QR decomposition.

rng('default');
m = 6;
n = 3;
p = 1;
A = randn(m,n);
b = randn(n,p);
x = fixed.qlessQRMatrixSolve(A,b)
x = 3×1

0.2991
0.0523
0.4182

The fixed.qlessQRMatrixSolve function is equivalent to the following code, however the fixed.qlessQRMatrixSolve function is more efficient and supports fixed-point data types.

x = (A'*A)\b
x = 3×1

0.2991
0.0523
0.4182

This example shows how to specify an output data type to solve a system of equations with fixed-point data.

Define the data representing the system of equations. Define the matrix A as a zero-mean, normally distributed random matrix with a standard deviation of 1.

rng('default');
m = 6;
n = 3;
p = 1;
A0 = randn(m,n);
b0 = randn(n,p);

Specify fixed-point data types for A and b as to avoid overflow during the computation of QR.

T.A = fi([],1,22,16);
T.b = fi([],1,22,16);
A = cast(A0, 'like', T.A)
A =
0.5377   -0.4336    0.7254
1.8339    0.3426   -0.0630
-2.2589    3.5784    0.7147
0.8622    2.7694   -0.2050
0.3188   -1.3499   -0.1241
-1.3077    3.0349    1.4897

DataTypeMode: Fixed-point: binary point scaling
Signedness: Signed
WordLength: 22
FractionLength: 16
b = cast(b0, 'like', T.b)
b =
1.4090
1.4172
0.6715

DataTypeMode: Fixed-point: binary point scaling
Signedness: Signed
WordLength: 22
FractionLength: 16

Specify an output data type to avoid overflow in the back-substitution.

T.x = fi([],1,29,12);

Use the fixed.qlessQRMatrixSolve function to compute the solution, x.

x = fixed.qlessQRMatrixSolve(A,b,T.x)
x =
0.2988
0.0522
0.4180

DataTypeMode: Fixed-point: binary point scaling
Signedness: Signed
WordLength: 29
FractionLength: 12

Compare this result to the result of the built-in MATLAB® operations in double-precision floating-point.

x0 = (A0'*A0)\b0
x0 = 3×1

0.2991
0.0523
0.4182

Input Arguments

collapse all

Coefficient matrix in the linear system of equations (A'A)x = B.

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

Input vector or matrix representing B in the linear system of equations (A'A)x = B.

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

Output data type, specified as a numerictype object or a numeric variable. If outputType is specified as a numerictype object, the output, x, will have the specified data type. If outputType is specified as a numeric variable, x will have the same data type as the numeric variable.

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

Forgetting factor, specified as a nonnegative scalar between 0 and 1. The forgetting factor determines how much weight past data is given. The forgettingFactor value is multiplied by the output of the QR decomposition, R after each row of A is processed.

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

Output Arguments

collapse all

Solution, returned as a vector or matrix. If A is an m-by-n matrix and B is an m-by-p matrix, then x is an n-by-p matrix.

Extended Capabilities

Introduced in R2020b

Fixed-Point Designer Documentation Get trial now