You are on page 1of 8

DIGITAL ASSIGNMENT

AOD LAB DA : 5

NAME: SHAARMILA B
REG NO: 19MIS0236
SLOT: L19+L20
FACULTY: DEBAROTI DAS

CODE:
syms n z u(n) U
F = input('Input the coefficients [a,b,c]: ');
a=F(1);b=F(2);c=F(3);
nh = input('Enter the non-homogenous part f(n): ');
Zf=ztrans(nh);
IC=input('Enter the initial conditions in the form [u0,u1]:');
u0=IC(1);u1=IC(2);
ZTU1=z*U-z*u0;
ZTU2=z^2*U-z^2*u0-z*u1;
eqn= a* ZTU2+b* ZTU1+c*U-Zf;
Uf=simplify(solve(eqn,U));
un=simplify(iztrans(Uf));
disp('The solution of the difference equation yn=')
disp(un);
m=0:20;
u=subs(un,n,m);
stem(u)
title('Difference equation');
xlabel('n'); ylabel('u(n)');

SCREANSHOTS:
CODE:
syms n z u(n) U
F = input('Input the coefficients [a,b,c]: ');
a=F(1);b=F(2);c=F(3);
nh = input('Enter the non-homogenous part f(n): ');
Zf=ztrans(nh);
IC=input('Enter the initial conditions in the form [u0,u1]:');
u0=IC(1);u1=IC(2);
ZTU1=z*U-z*u0;
ZTU2=z^2*U-z^2*u0-z*u1;
eqn= a* ZTU2+b* ZTU1+c*U-Zf;
Uf=simplify(solve(eqn,U));
un=simplify(iztrans(Uf));
disp('The solution of the difference equation yn=')
disp(un);
m=0:20;
u=subs(un,n,m);
stem(u)
title('Difference equation');
xlabel('n'); ylabel('u(n)');
SCREANSHOT:
3. Solve y(n + 2) + 2y(n +1) + y(n) = n,n  0 , y0 = 0 and y1 = 0 .
CODE:
syms n z u(n) U
F = input('Input the coefficients [a,b,c]: ');
a=F(1);b=F(2);c=F(3);
nh = input('Enter the non-homogenous part f(n): ');
Zf=ztrans(nh);
IC=input('Enter the initial conditions in the form [u0,u1]:');
u0=IC(1);u1=IC(2);
ZTU1=z*U-z*u0;
ZTU2=z^2*U-z^2*u0-z*u1;
eqn= a* ZTU2+b* ZTU1+c*U-Zf;
Uf=simplify(solve(eqn,U));
un=simplify(iztrans(Uf));
disp('The solution of the difference equation yn=')
disp(un);
m=0:20;
u=subs(un,n,m);
stem(u)
title('Difference equation');
xlabel('n'); ylabel('u(n)');
SCREANSHOT:

4. Solve y(n + 2) − 4y(n +1) + 3y(n) = n.2 ,n  0 n , y0 = 0 and y1 = 0 .


CODE:
syms n z u(n) U
F = input('Input the coefficients [a,b,c]: ');
a=F(1);b=F(2);c=F(3);
nh = input('Enter the non-homogenous part f(n): ');
Zf=ztrans(nh);
IC=input('Enter the initial conditions in the form [u0,u1]:');
u0=IC(1);u1=IC(2);
ZTU1=z*U-z*u0;
ZTU2=z^2*U-z^2*u0-z*u1;
eqn= a* ZTU2+b* ZTU1+c*U-Zf;
Uf=simplify(solve(eqn,U));
un=simplify(iztrans(Uf));
disp('The solution of the difference equation yn=')
disp(un);
m=0:20;
u=subs(un,n,m);
stem(u)
title('Difference equation');
xlabel('n'); ylabel('u(n)');
SCREANSHOT:

You might also like