I'd like to write the Matlab code for the following equation:
z(k)=lamda*x(k)+(1-lamda)*z(k-1)
lamda
can be of any value. x
is a 1000x22
matrix. Z(0)=0
.
Can anyone help me please?
I'd like to write the Matlab code for the following equation:
z(k)=lamda*x(k)+(1-lamda)*z(k-1)
lamda
can be of any value. x
is a 1000x22
matrix. Z(0)=0
.
Can anyone help me please?
You can use iteration function
.same thing like this
function z = itrationFunctio(k,x,lambda)
if(k == 0)
z = 0;
else
z = lambda*x+(1-lambda)*itrationFunctio((k-1),x,lambda);
end
and in your code just call itrationFunctio(k,x,lambda)
.
Does that vectorized solution work for you?
% parameters
x = rand(10,1);
lambda = 2;
% init z, normalize with (1-lambda)
z(2:numel(x)) = lambda/(1-lambda)*x(2:end);
% cumsum, denormalize with (1-lambda)
z = cumsum(z)*(1-lambda)
However I don't get why your x
is a matrix and not a vector. What is z
supposed to be, in what dimension works k
? So in case x
represents a couple of vectors you want to calculate in parallel, that could work:
% parameters
x = rand(1000,22);
lambda = 2;
% init z, normalize with (1-lambda)
z(2:size(x,1),:) = lambda/(1-lambda)*x(2:end,:);
% cumsum, denormalize with (1-lambda)
z = cumsum(z,1)*(1-lambda)