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.
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.