Department of Mathematics School of Advanced Sciences Lab Assignment 4
Department of Mathematics School of Advanced Sciences Lab Assignment 4
Lab Assignment 4
Name : B.RAVI KIRAN
Reg No : 17BCE0863
Slot : L11+l12
Questions:
Write the MATLAB codes for the following questions:
CODE
clc
clear
syms t C1 C2 A B
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);
disp(X)
OUTPUT
CODE2
a)
clc
clear
syms x a0 a1 a2
a=[a0 a1 a2 ];
y = sum(a.*(x).^[0:2]);
dy =diff(y);
d2y = diff(dy);
gde = collect(d2y-dy+x*y,x);
cof=coeffs(gde,x);
A2=solve(cof(1),a2);
y=subs(y,a2,A2);
y=coeffs(y,[a1 a0]);
disp('Solution is')
disp(['y=A(',char(y(1)),'+....)+B(',char(y(2)),'+ ...... )'])
OUTPUT
b)
clc
clear
syms x a0 a1 a2
a=[a0 a1 a2 ];
y = sum(a.*(x).^[0:2]);
dy =diff(y);
d2y = diff(dy);
gde = collect(d2y-dy+(x^2)*y,x);
cof=coeffs(gde,x);
A2=solve(cof(1),a2);
y=subs(y,a2,A2);
y=coeffs(y,[a1 a0]);
disp('Solution is')
disp(['y=A(',char(y(1)),'+....)+B(',char(y(2)),'+ ...... )'])
OUTPUT