0% found this document useful (0 votes)
22 views

Department of Mathematics School of Advanced Sciences Lab Assignment 4

This document contains MATLAB code for solving two differential equations. The first code finds the general solution to a second order linear differential equation of the form d2y/dx2 - dy/dx + xy = 0. It determines the coefficients in terms of the unknowns a1, a0 and represents the solution as y=A(a1x+...) + B(a0+...). The second code solves the same type of equation but with d2y/dx2 - dy/dx + x^2y = 0 and provides the same form for the general solution.
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)
22 views

Department of Mathematics School of Advanced Sciences Lab Assignment 4

This document contains MATLAB code for solving two differential equations. The first code finds the general solution to a second order linear differential equation of the form d2y/dx2 - dy/dx + xy = 0. It determines the coefficients in terms of the unknowns a1, a0 and represents the solution as y=A(a1x+...) + B(a0+...). The second code solves the same type of equation but with d2y/dx2 - dy/dx + x^2y = 0 and provides the same form for the general solution.
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/ 3

DEPARTMENT OF MATHEMATICS

SCHOOL OF ADVANCED SCIENCES

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

You might also like