# Compute Forgetting Factor Required for Streaming Input Data

This example shows how to use the fixed.forgettingFactor and fixed.forgettingFactorInverse functions.

The growth in the QR decomposition can be seen by looking at the magnitude of the first element $R\left(1,1\right)$of the upper-triangular factor $R$, which is equal to the Euclidean norm of the first column of matrix $A$,

$|R\left(1,1\right)|=||A\left(:,1\right)|{|}_{2}$.

To see this, create matrix $A$ as a column of ones of length $n$ and compute $R$ of the economy-size QR decomposition.

n = 1e4;
A = ones(n,1);

Then $|R\left(1,1\right)|=||A\left(:,1\right)|{|}_{2}=\sqrt{\sum _{i=1}^{n}{1}^{2}}=\sqrt{n}$.

R = fixed.qlessQR(A)
R = 100.0000
norm(A)
ans = 100
sqrt(n)
ans = 100

The diagonal elements of the upper-triangular factor $R$ of the QR decomposition may be positive, negative, or zero, but fixed.qlessQR and fixed.qrAB always return the diagonal elements of $R$ as non-negative.

In a real-time application, such as when data is streaming continuously from a radar array, you can update the QR decomposition with an exponential forgetting factor $\alpha$ where $0<\alpha <1$. Use the fixed.forgettingFactor function to compute a forgetting factor $\alpha$ that acts as if the matrix were being integrated over $m$ rows to maintain a gain of about $\sqrt{m}$. The relationship between $\alpha$ and $m$ is $\alpha ={e}^{-1/\left(2m\right)}$.

m = 16;
alpha = fixed.forgettingFactor(m);
R_alpha = fixed.qlessQR(A,alpha)
R_alpha = 3.9377
sqrt(m)
ans = 4

If you are working with a system and have been given a forgetting factor $\alpha$, and want to know the effective number of rows $m$ that you are integrating over, then you can use the fixed.forgettingFactorInverse function. The relationship between $m$ and $\alpha$ is $m=\frac{-1}{2\mathrm{log}\left(\alpha \right)}$.

fixed.forgettingFactorInverse(alpha)
ans = 16