Digital Assignment-5: Name: Havila Reddy Register No: 19BCT0211

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

DIGITAL ASSIGNMENT-5

Name: Havila Reddy


Register No: 19BCT0211

Question 1:
Write MATLAB code to solve the system 1 1 2 x ' = 3x − 2x , 2 1 2 x ' = 2x − 2x ; (0) 1 x1
= , x2 (0) = −1
1. Aim of the experiment:

Aim of this experiment is to solve the system of differential equations by matrix


method using matlab.

2. Mathematical Procedure:

3. Matlab Code:
clc
clear
syms t A C1 C2
A=input('Enter A: ');
[P,D]=eig(A);
Phi(t)=[P(1,1)*exp(D(1,1)*t) P(1,2)*exp(D(2,2)*t);...
P(2,1)*exp(D(1,1)*t) P(2,2)*exp(D(2,2)*t)];
Xc=Phi(t)*[C1;C2];
disp(Xc)

4. Input:

Enter A: [3 -2; 2 -2]

Output:

(2*5^(1/2)*C1*exp(2*t))/5 + (5^(1/2)*C2*exp(-t))/5
(5^(1/2)*C1*exp(2*t))/5 + (2*5^(1/2)*C2*exp(-t))/5
5. Conclusion:

Therefore, the equations are solved using matrix method in matlab.

Question 2:
Write MATLAB code to solve the following difference equation by Z transforms. Solve
y +2 − 5y +1 + 6y = 5 ,n  0 n n n n , 1 y0 = and 1 y1 = .
1. Aim of the experiment:

Aim of the experiment is to solve differential equation by Z transform method using


matlab.

2. Mathematical Procedure:
3. Matlab Code:

clear all
clc
syms n z
CF=input('Enter the coefficients of Difference equation [a b c]: ');
a=CF(1);b=CF(2);c=CF(3);
f=input('Enter the RHS function in terms of n : ');
Cond=input('Enter the initial conditions [y0 y1]');
y0=Cond(1);y1=Cond(2);
F=ztrans(f);
num=F+(a*z^2+b*z)*y0+a*z*y1;
den=a*z^2+b*z+c;
Y=num/den;
y=iztrans(Y)
m=0:20;
yn=subs(y,n,m);
stem(yn)
title('Difference equation');
xlabel('n'); ylabel('y(n)');

4. Input:

Enter the coefficients of Difference equation [a b c]: [1 -5 6]


Enter the RHS function in terms of n : 5^n
Enter the initial conditions [y0 y1][1 1]

Output:
den =
z^2 - 5*z + 6
y=
(7*2^n)/3 - (3*3^n)/2 + 5^n/6

5. Graph:
6. Conclusion:

Therefore the differential equation is solved using Z transform in matlab.

You might also like