MATLAB: Sum of a series

finite sumMATLABseriessimulation

Hi,
Can someone please help me to write the following code using a summation
for i = 1:1000
v(i) =y(i) - a0- a1*y(i-1)-a2*y(i-2);
end
Thanks.

Best Answer

a0=1;
a1=2;
a2=1;
y=rand(1,1000) % your data
coeff=[-a2 -a1 1];
for ii = 3:1000
v(ii) =sum(y(ii-2:ii).* coeff)-a0;
end