# fixed.qlessqrFixedpointTypes

Determine fixed-point types for transforming A to R in-place, where R is upper-triangular factor of QR decomposition of A, without computing Q

## Syntax

``T = fixed.qlessqrFixedpointTypes(m,max_abs_A,precisionBits)``
``T = fixed.qlessqrFixedpointTypes(m,max_abs_A,precisionBits,regularizationParameter)``

## Description

example

````T = fixed.qlessqrFixedpointTypes(m,max_abs_A,precisionBits)` computes fixed-point types for transforming A to R in-place, where R is the upper-triangular factor of the QR decomposition of A, without computing Q. `T` is returned as a struct with field `T.A` containing a `fi` object that specifies the fixed-point type for A, which guarantees no overflow will occur in the QR algorithm.The QR algorithm transforms A in-place into upper-triangular R, where QR=A is the QR decomposition of A.```
````T = fixed.qlessqrFixedpointTypes(m,max_abs_A,precisionBits,regularizationParameter)` computes fixed-point types for transforming $\left[\begin{array}{c}\lambda {I}_{n}\\ A\end{array}\right]$ in-place to $R=Q\text{'}\left[\begin{array}{c}\lambda {I}_{n}\\ A\end{array}\right]$ where λ is the `regularizationParameter`, QR is the economy size QR decomposition of $\left[\begin{array}{c}\lambda {I}_{n}\\ A\end{array}\right]$, A is an m-by-n matrix, and In = `eye(n)`.```

## Examples

collapse all

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 $A$.

```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 $A$ such that the elements of $A$ are between $-1$ and $+1$.

```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 $A$ that guarantees no overflow will occur in the transformation of $A$ in-place to $R={Q}^{\prime }A$.

```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 $\mathit{A}$ to $\mathit{R}={\mathit{Q}}^{\prime }\mathit{A}$ 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

$R$ 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.

$\mathit{R}={\mathit{Q}}^{\prime }\mathit{A}$, and $Q$ is orthogonal, so ${R}^{\prime }R={A}^{\prime }Q{Q}^{\prime }A={A}^{\prime }A$, within rounding error.

`relative_error = norm(double(R'*R - A'*A))/norm(double(A'*A))`
```relative_error = 9.3865e-07 ```

Suppress `mlint` warnings.

`%#ok<*NOPTS>`

## Input Arguments

collapse all

Number of rows in A, specified as a positive integer-valued scalar.

Data Types: `double`

Maximum of the absolute value of A, specified as a scalar.

Example: `max(abs(A(:)))`

Data Types: `double`

Required number of bits of precision, specified as a positive integer-valued scalar.

Data Types: `double`

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

Fixed-point type for A, returned as a struct. The struct `T` has field `T.A` that contains a `fi` object that specifies a fixed-point type for A that guarantees no overflow will occur in the QR algorithm.

## Tips

Use `fixed.qlessqrFixedpointTypes` to compute fixed-point types for the inputs of these functions and blocks.

## Algorithms

The number of integer bits required to prevent overflow is derived from the following bound on the growth of R [1]. The required number of integer bits is added to the number of bits of precision, `precisionBits`, of the input, plus one for the sign bit, plus one bit for intermediate CORDIC gain of approximately 1.6468 [2].

The elements of R are bounded in magnitude by

`$\mathrm{max}\left(|R\left(:\right)|\right)\le \sqrt{m}\mathrm{max}\left(|A\left(:\right)|\right).$`

## References

[2] Voler, Jack E. "The CORDIC Trigonometric Computing Technique." IRE Transactions on Electronic Computers EC-8 (1959): 330-334.

## Version History

Introduced in R2021b