Experiment 5 AOD.docx - Assessment 5 Course Code u2013...

This preview shows page 1 - 5 out of 9 pages.

Assessment - 5 Course Code – MAT2002 Slot – L33+L34 Registration N0 – 19BCE0861 Name – Raghav Asawa 1. Code: clc clear all syms x a0 a1 a2 a3 y=a0+a1*x+a2*x^2+a3*x^3; dy=diff(y); d2y=diff(dy); eqn=input( 'Enter the coefficients [a,b,c] for a(d2y)+b(dy)+c(y)=0 : ' ); a=eqn(1); b=eqn(2); c=eqn(3); gde=collect(a*d2y+b*dy+c*y,x); cof=coeffs(gde,x); A2=solve(cof(1),a2); A3=solve(cof(2),a3); y=subs(y,{a2,a3},{A2,A3}); y=coeffs(y,[a1 a0]); disp( 'Solution is ' )
disp([ 'y=A(' ,char(y(1)), '+...) +B(' ,char(y(2)), '+...)' ]) Input: Enter the coefficients [a,b,c] for a(d2y)+b(dy) +c(y)=0 : [1 -5 6] Output: Solution is y=A((5*a2*x^3)/3+...)+B(1 - 3*x^2+...)
2. CODE: clc clear all syms n z y(n) Y yn=y(n); yn1=y(n+1); yn2=y(n+2); F=input( 'Enter the coefficients of [a,b,c] : ' ); a=F(1); b=F(2); c=F(3); nh=input( 'Enter the non-homogenous part f(n) : ' ); eqn=a*yn2+b*yn1+c*yn-nh; ZTY=ztrans(eqn); IC=input( 'Enter the initial conditions in the form [y0,y1] : ' ); y0=IC(1); y1=IC(2);
ZTY=subs(ZTY, {str2sym( 'ztrans(y(n),n,z)' ),str2sym( 'y(0)' ),str2sym( 'y (1)' )},{Y,y0,y1}); eq=collect(ZTY,Y); Y=simplify(solve(eq,Y)); yn=simplify(iztrans(Y)) disp( 'The solution of difference equation yn = ' ); disp(yn) m=0:20;

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture