Determine Fixed-Point Types for Q-less QR Decomposition
This example shows how to use fixed.qlessqrFixedpointTypes
to analytically determine a fixed-point type for the computation of the Q-less QR decomposition.
Define Matrix Dimensions
Specify the number of rows and columns in matrix .
m = 10; % Number of rows in matrix A n = 3; % Number of columns in matrix A
Generate Matrix A
Use the helper function realUniformRandomArray
to generate a random matrix such that the elements of are between and .
rng('default')
A = fixed.example.realUniformRandomArray(-1,1,m,n);
Select Fixed-Point Type
Use the fixed.qlessqrFixedpointTypes
function to select the fixed-point data type for matrix that guarantees no overflow will occur in the transformation of in-place to .
max_abs_A = 1; % Upper bound on max(abs(A(:)) precisionBits = 24; % Number of bits of precision T = fixed.qlessqrFixedpointTypes(m,max_abs_A,precisionBits)
T = struct with fields:
A: [0x0 embedded.fi]
T.A
is the type computed for transforming to in-place so that it does not overflow.
T.A
ans = [] DataTypeMode: Fixed-point: binary point scaling Signedness: Signed WordLength: 29 FractionLength: 24
Use the Specified Type to Compute the Q-less QR Decomposition
Cast the input to the type determined by fixed.qlessqrFixedpointTypes
.
A = cast(A,'like',T.A);
Accelerate fixed.qlessQR
by using fiaccel
to generate a MATLAB® executable (MEX) function.
fiaccel fixed.qlessQR -args {A} -o qlessQR_mex
Compute the QR decomposition.
R = qlessQR_mex(A);
Verify That R Is Upper-Triangular
is an upper-triangular matrix.
R
R = 2.2180 0.8559 -0.5607 0 2.0578 -0.4017 0 0 1.7117 DataTypeMode: Fixed-point: binary point scaling Signedness: Signed WordLength: 29 FractionLength: 24
isequal(R,triu(R))
ans = logical
1
Verify the Accuracy of the Output
To evaluate the accuracy of the fixed.qlessQR
function, compute the relative error.
, and is orthogonal, so , within rounding error.
relative_error = norm(double(R'*R - A'*A))/norm(double(A'*A))
relative_error = 1.0699e-06
Suppress mlint
warnings.
%#ok<*NOPTS>
See Also
Functions
Blocks
- Real Burst Q-less QR Decomposition | Complex Burst QR Decomposition | Real Partial-Systolic Q-less QR Decomposition | Complex Partial-Systolic Q-less QR Decomposition | Real Partial-Systolic Q-less QR Decomposition with Forgetting Factor | Complex Partial-Systolic Q-less QR Decomposition with Forgetting Factor