0% found this document useful (0 votes)
43 views10 pages

Da 4 Aod Lab

The document describes solving second order linear differential equations using eigenvalue decomposition. It provides MATLAB code to find the general solution of second order linear differential equations and applies initial conditions to determine the specific solution. The code demonstrates this process for several examples of 2x2 matrices.

Uploaded by

viswa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views10 pages

Da 4 Aod Lab

The document describes solving second order linear differential equations using eigenvalue decomposition. It provides MATLAB code to find the general solution of second order linear differential equations and applies initial conditions to determine the specific solution. The code demonstrates this process for several examples of 2x2 matrices.

Uploaded by

viswa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

AOD LAB DIGITAL ASSIGNMENT 4

K.SAIKUMAR
18BEC0260
SLOT: G2
Exp – 4A

1.(a)
Code:
clc
clear
syms t C1 C2
A=input('Enter A: ');
[P,D]=eig(A);
L1=D(1); L2=D(4);
y1=C1*exp(L1*t); y2=C2*exp(L2*t);
Y=[y1;y2];
X=P*Y;
Cond=input('Enter the initial conditions [t0, x10,x20]: ');
t0=Cond(1); x10=Cond(2); x20=Cond(3);
eq1=subs(X(1)-x10,t0); eq2=subs(X(2)-x20,t0); [C1,
C2] = solve(eq1,eq2);
X=subs(X)

Output:
Enter A: [3 -2;2 -2]
Enter the initial conditions [t0, x10,x20]:

[0 1 -1] X =

2*exp(2*t) - exp(-t)
exp(2*t) - 2*exp(-t)

1.(b)
Code:
clc
clear
syms t C1 C2 C3
A=input('Enter A: ');
[P,D]=eig(A);
n1=P(:,1); n2=P(:,2); n3=P(:,3);
N1=n1/n1(1); N2=n2/n2(1); N3=n3/n3(1);
N1=round(N1); N2=round(N2);
N3=round(N3); L1=D(1); L2=D(5); L3=D(9);
X=C1*exp(L1*t)*N1+C2*exp(L2*t)*N2+C3*exp(L3*t)*N
Output:
Enter A: [0 -1 1;4 -1 -4;-3 -1 4] X =

C2*exp(t) + C1*exp(3*t) + C3*exp(-t)


2*C3*exp(-t) - C1*exp(3*t)
C2*exp(t) + 2*C1*exp(3*t) + C3*exp(-t)

2.(a)
Code:
clc
clear
A=input('Enter A: ');
[P D]=eig(A);
Sol1 = dsolve(['D2y = ',num2str(D(1)),'*y']);
Sol2 = dsolve(['D2y = ',num2str(D(4)),'*y']); X =
P*[Sol1;Sol2];
disp('x1='); disp(X(1))
disp('x2='); disp(X(2))

Output:
Enter A: [-5 2;2 -2]
x1=
- (5^(1/2)*(C8*cos(t) + C9*sin(t)))/5 - (2*5^(1/2)*(C5*cos(6^(1/2)*t) +
C6*sin(6^(1/2)*t)))/5

x2=
(5^(1/2)*(C5*cos(6^(1/2)*t) + C6*sin(6^(1/2)*t)))/5 - (2*5^(1/2)*(C8*cos(t) +
C9*sin(t)))/5

2.(b)
Code:
clc
clear
A=input('Enter A: ');
[P D]=eig(A);
Sol1 = dsolve(['D2y = ',num2str(D(1)),'*y']);
Sol2 = dsolve(['D2y = ',num2str(D(4)),'*y']); X =
P*[Sol1;Sol2];
disp('x1='); disp(X(1))
disp('x2='); disp(X(2))
Output:
Enter A: [-2 1;1 -2]
x1=
(2^(1/2)*(C8*cos(t) + C9*sin(t)))/2 + (2^(1/2)*(C11*cos(3^(1/2)*t) +
C12*sin(3^(1/2)*t)))/2

x2=
(2^(1/2)*(C8*cos(t) + C9*sin(t)))/2 -
(2^(1/2)*(C11*cos(3^(1/2)*t) + C12*sin(3^(1/2)*t)))/2.

3.
Code:
clc
clear
A=input('Enter A: ');
[P D]=eig(A);
Sol1 = dsolve(['D2y = ',num2str(D(1)),'*y']);
Sol2 = dsolve(['D2y = ',num2str(D(4)),'*y']); X =
P*[Sol1;Sol2];
disp('x1=');disp(X(1))
disp('x2=');disp(X(2))

Output:
Enter A: [-4 3; 3 -4]
x1=
(2^(1/2)*(C5*cos(t) - C6*sin(t)))/2 + (2^(1/2)*(C3*cos(7^(1/2)*t) -
C4*sin(7^(1/2)*t)))/2

x2=
(2^(1/2)*(C5*cos(t) - C6*sin(t)))/2 - (2^(1/2)*(C3*cos(7^(1/2)*t) -
C4*sin(7^(1/2)*t)))/2
5.
Code
clc clear
syms t C1 C2
A=input('Enter A: ');
[P,D]=eig(A);
L1=D(1); L2=D(4);
y1=C1*exp(L1*t); y2=C2*exp(L2*t);
Y=[y1;y2];
X=P*Y;
Cond=input('Enter the initial conditions [t0, x10,x20]: ');
t0=Cond(1); x10=Cond(2); x20=Cond(3);
eq1=subs(X(1)-x10,t0); eq2=subs(X(2)-x20,t0); [C1,
C2] = solve(eq1,eq2);
X=subs(X)

Output:
Enter A: [-0.02 0.02; 0.02 -0.02]
Enter the initial conditions [t0, x10,x20]: [0

0 150] X =

75 - 75*exp(-t/25)
75*exp(-t/25) + 75

EX-4(B)
1.(a)
Code:
clc clear
all
syms x a0 a1 a2 a3 y
coef=input('Enter the coefficient of D2y(x),Dy(x) and y(x):'); a = [a0
a1 a2 a3];
y = sum(a.*(x).^[0:3]);
disp(y)
ps=collect(coef(1)*diff(y,2)+coef(2)*diff(y)+coef(3)*y,x);
psc=coeffs(ps,x);
[a2,a3]=solve(psc(1),psc(2),a2,a3);
y=subs(y);
y=coeffs(y,[a1 a0]);
disp('Solution is')
disp(['y=A(',char(y(1)),'+ ...)+B(',char(y(2)),'+ ...)'])

Output:
Enter the coefficient of D2y(x),Dy(x) and y(x):
[1,0,x] a3*x^3 + a2*x^2 + a1*x + a0

Solution is
y=A(1 - x^3/6+ ...)+B(x+ ...)

1.(b)
Code:
clc clear
all
syms x a0 a1 a2 a3 y
coef=input('Enter the coefficient of D2y(x),Dy(x) and y(x):'); a = [a0
a1 a2 a3];
y = sum(a.*(x).^[0:3]);
disp(y)
ps=collect(coef(1)*diff(y,2)+coef(2)*diff(y)+coef(3)*y,x);
psc=coeffs(ps,x);
[a2,a3]=solve(psc(1),psc(2),a2,a3);
y=subs(y);
y=coeffs(y,[a1 a0]);
disp('Solution is')
disp(['y=A(',char(y(1)),'+ ...)+B(',char(y(2)),'+ ...)'])
Output:
Enter the coefficient of D2y(x),Dy(x) and y(x):
[1,0,x^2] a3*x^3 + a2*x^2 + a1*x + a0
Solution is
y=A(1+ ...)+B(x+ ...)

1.(c)
Code:
clc
clear all
syms x a0 a1 a2 a3 y
coef=input('Enter the coefficient of D2y(x),Dy(x) and y(x):'); a = [a0
a1 a2 a3];
y = sum(a.*(x).^[0:3]);
disp(y)
ps=collect(coef(1)*diff(y,2)+coef(2)*diff(y)+coef(3)*y,x);
psc=coeffs(ps,x);
[a2,a3]=solve(psc(1),psc(2),a2,a3);
y=subs(y);
y=coeffs(y,[a1 a0]);
disp('Solution is')
disp(['y=A(',char(y(1)),'+ ...)+B(',char(y(2)),'+ ...)'])

Output:
Enter the coefficient of D2y(x),Dy(x) and y(x):
[1,x,1] a3*x^3 + a2*x^2 + a1*x + a0

Solution is
y=A(1 - x^2/2+ ...)+B(x - x^3/3+ ...)

1.(d)
Code:
clc clear
all close
all
syms x a0 a1 a2 a3 a4 a5 C1 C2 t;
a=[a0 a1 a2 a3 a4 a5];
aa=input('Enter the coefficient of D2y: ');
bb=input('Enter the coefficient of Dy: '); cc=input('Enter
the coefficient of y: '); Ics=input('Enter the values for [a
y(a) Dy(a)] : '); y=sum(a.*(x).^[0:5]);
dy=diff(y); d2y=diff(dy);
f=aa*d2y+x*dy+cc*y-(bb-x)*dy;
de=collect(f,x); de=subs(f,x,t);
coe=coeffs(de,t);
A2=solve(coe(1),a2);
A3=subs(solve(coe(2),a3),a2,A2);
A4=subs(solve(coe(3),a4),a2,A2);
A5=subs(solve(coe(4),a5),a3,A3); y=subs(y,{a2,a3,a4,a5},
{A2,A3,A4,A5});
soln=coeffs(y,[a1,a0])
gs=a1*soln(1)+a0*soln(2);
eq1=subs(gs,x,Ics(1))-Ics(2);
eq2=subs(diff(gs),x,Ics(1))-Ics(3); [a0
a1]=solve(eq1,eq2);
gs=subs(gs)

Output:
Enter the coefficient of D2y: (1-
x^2) Enter the coefficient of
Dy: 0
Enter the coefficient of y: 2
Enter the values for [a y(a) Dy(a)]

: [0 4 5] gs =

x^5/3 + (4*x^4)/3 - (10*x^3)/3 - 4*x^2 + 5*x + 4

You might also like