What is the best way to solve difference equations using matlab without using filter command?

2 views (last 30 days)
We're assigned to solve for a 2nd order difference equations using matlab but without using the built in function filter and filtic. The problem doesn't necessarily stated the inputs rather than it must be a script file.
function lccde
clc
xn= input('Coefficient of y(n): ');
xn1 = input('Coefficient of y(n-1): ');
xn2 = input('Coefficient of y(n-2): ');
yn = input('Coefficient of x(n): ');
yn1 = input('Coefficient of x(n-1): ');
yn2 = input('Coefficient of x(n-2): ');
X = input('Input sequence x(n): ');
xic1 = input('Initial condition at y(-1): ');
xic2 = input('Initial condition at y(-2): ');
nf = input('How many terms?: ');
nc=1/xn;
for n=3:nf
n0=1:3;
if (n-n0==2)
Y(0)=nc*(xn1*xic1+xn2*xic2+yn*X(n-3)+yn1*X(n-2)+yn2*x(n-1))
elseif (n-n0==1)
Y(1)=nc*(xn1*y(0)+xn2*xic1+yn*X(n-3)+yn1*X(n-2)+yn2*X(n-1))
else (n-n0==0)
Y(n)=0;
Y(n)=nc*(xn1*y(n-1)+xn2*y(n-2)+yn*X(n-3)+yn1*X(n-2)+yn2*X(n-1))
end
end

Answers (0)

Community Treasure Hunt

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

Start Hunting!