Solving LTID system recursively

I want to solve this system recursively
y[n]0.7y[n1]+0.12y[n2]=2x[n]x[n1]
with
x[n]=(2)nu[n]; y[1]=3 and y[2]=2
what i have tried is this but i keep getting Array indices must be positive integers or logical values.
any suuggestions?
n=-2:15;
% y=[2;3;zeros(length(n)-2,1)]; %I.C
y(-2)=2;
y(-1)=3;
x=inline('2.^(-n).*(n>=0)'); % input system
for k = 1: length(n)-2
y(k) = 0.7*y(k-1)-0.12*y(k-2)+2*x(k)-x(k-1);
end
clf;
stem(n,y);
disp('n y'); disp([num2str([n,y])]);

Réponses (1)

Alan Stevens
Alan Stevens le 5 Sep 2020

0 votes

Matlab indexing begins at 1, so you can't have y(-2), y(-1), y(0) etc. Shift your indexing.
y(1) = 2;
y(2) = 3;
for k = 3: length(n)
y(k) = ...etc

Catégories

En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by