Problem with calculating recursive equation I'm facing with this error when I'm trying to solve the equation : 


  Attempted to access x(101); index out of bounds because
  numel(x)=100.


actually the original equation is

so I used "i+1"instead of"i" to avoid following error:


  Attempted to access y(0); index must be a positive
  integer or logical.


n=[1:100];
yy=zeros(1,99);
xx=zeros(1,99);
y=[1 yy];
x=(.5).^n;
for i=n

  y(i)=.5*y(i-1)+2*x(i)+4*x(i-1)
end


error resolved by initializing i by  2

the improved code is : 

yy=zeros(1,99);
xx=zeros(1,99);
y=[1 yy];
x=(.5).^n;
 for n=2:100

 y(n)=.5*y(n-1)+2*x(n)+4*x(n-1);
end


but the results of **y(n)**is different from what I get on paper.
Sorry for answering like this but I cannot comment since my reputation is not sufficient, but yet I want to help.

It is a filter and you can do it way easier, and more quickly than just building an algorithm(in Matlab ofcourse). It will take relatively a long post to cover all the concepts in order to make a sufficient understanding about filter designs. 

However, I can help you about which topics you should cover.

Please take a look at FIR/IIR filters (Your recursive equation is basically an IIR filter) and Z-Transform topics. 

If you need a quicker way to learn about IIR filter this lecture will give you some information.