I try to vectorize this simple recursive relation (all quantities are scalars)
x_{0} = 0;x_{n} = x_{n-1}*a_{n} + b_{n} for n=1,2,...,N
In MATLAB code it can be carried out by for loop
% test inputs
b=rand(1,10);a=0.9+zeros(size(b));xk=0;x=zeros(size(b));for k=1:length(x) xk = a(k)*xk+b(k); x(k) = xk;end
For a(:) constant this can be vectorized by IIR filter
ac = unique(a);if length(ac)==1 x = filter(1, [1 -ac], b);end
I would though it could have some time-varying IIR filter that I can use to vectorize the case where a is time-dependent.
But I couldn't find anywhere such stock function. anyone have an idea?
Best Answer