You are on page 1of 5

WS 2018-19

• Course: MAT2002(ADDE) - ELA

• Regd. No.

• Name:

• Slot: L7 + L8

Last Date of submission: 18.03.2019

Experiment 3: Solution of a Linear differential equation by method of variation


of parameters, Solution of Linear differential equations by Laplace
transforms

Guidelines for Submission:

• Download this sheet, and write your answers in detail neatly without any
corrections. In case of graphical answer, create the image ftle of it and paste it in
the answer, where ever needed
• Write your name and do the signature on the top of every page

• Take the snap shot of the title page and the ftlled-in answer sheet carefully which should
be clearly visible, and make a single pdf ftle only
• Then upload it through the lab log-in portal.

• Do not send different image ftles or zipped ftles. Do not send the answer sheet to my
mail
• Follow the guidelines strictly. Any deviation from the above instructions will lead to
the reduction in marks

Submission Format:
(a) Aim of the Experiment

(b) Deftnitions, Mathematical formulas or brief concept related to the

exercise (c)Matlab Code


(d) Input
(e) Output (including the graphical representation)

Uploading of answers in any other format is not


acceptable
Regd. No. Name: Sign.

d y
Exercise 1 (3 marks). Write a Matlab code to ftnd the solution of x2 2 + 4x d y + 2 y = eex by

the method of variation of parameters and graph the solution. dx 2 dx

Answers:
CODE

clc
clear
close all
syms x D T t C1 C2 z s
LHS=input('Enter the LHS in terms of D where D=d/dx: ');
RHS(x)=input('Enter the equation on rhs: ');
s=x;
RHSf(s)=RHS(s);
s=exp(t);
c=coeffs(LHS,D);
for i=1:length(c)
cof(i)=c(length(c)-i+1);
end
if(cof(1)==x^2 & cof(2)/coeffs(cof(2))==x)
coffinal=[coeffs(cof(1))*D*(D-1) coeffs(cof(2))*D cof(3)];
end
eqn(D)=D*0;
for i=1:length(c)
eqn(D)=eqn(D)+coffinal(i);
end
Dval=solve(eqn,D);
if(imag(Dval(1)==0))
if(ne(Dval(1),Dval(2)))
CF(t)=C1*exp(Dval(1)*t)+C2*exp(Dval(2)*t);
y1(t)=exp(Dval(1)*t);
y2(t)=exp(Dval(2)*t);
else
CF(t)=(C1+C2*t)*exp(Dval(1)*t);
y1(t)=exp(Dval(1)*t);
y2(t)=x*exp(Dval(1)*t);
end
else

CF(t)=exp(real(Dval(1))*t)*(C1*cos(imag(Dval(1)))*t+C2*sin(imag
(Dval(1))*t));
y1(t)=exp(real(Dval(1))*t)*cos(imag(Dval(1))*t);
y2(t)=exp(real(Dval(1))*t)*sin(imag(Dval(1))*t);
end

Matlab Experiment 3 2 MAT2002


W=det([y1 y2; diff(y1,t) diff(y2,t)]);
RHSt(t)=RHS(s);
Wd=sym(W);
F1(t)=-y1*int(y2*RHSt(t)/W,t);
F2(t)=y2*int(y1*RHSt(t)/W,t);
t=log(x);
F1f(x)=sym(F1(t));
F2f(x)=sym(F2(t));
PI(x)=F1f+F2f;
CFf(x)=sym(CF(t));
disp('Final Solution is: ');
disp(CFf+PI)
disp('Due to inability of MATLAB to evaluate the integral, I
was not able to graph the solution');

OUTPUT:

Enter the LHS in terms of D where D=d/dx: x^2*D^2+4*x*D+2


Enter the equation on rhs: exp(exp(x))
Final Solution is:
ei(exp(x))/x - int(x*exp(exp(x)), x)/x^2 + C1/x^2 + C2/x
symbolic function inputs: x

Due to inability of MATLAB to evaluate the integral, I was not able to graph the solution
Exercise 2 (3 marks). An electric circuit consists of an inductance 0.1 Heneries, a resistance
of 20 Ohms and a condenser of capacitance 25 micro-Farads. Write a Matlab code to ftnd the
charge q and the current I at any time t given that q(0) = 0.05 and I(0) = 0 (Use Laplace
Transform).

Answers:

CODE:

clc
clear
close all
syms q k s t;
L=input('Enter inductance of circuit: ');
R=input('Enter resistance of circuit: ');
C=input('Enter Capacitance of circuit: ');

qinitial=input('Enter value of Q at t=0: ');


Iinitial=input('Enter the value of I at t=0: ');
a=L*((s^2)*k-s*qinitial-Iinitial);
b=R*(s*k-qinitial);
c=(qinitial*k/C);
f(s)=a+b+c;
Lap=solve(f(s),k);
disp('Q(t): ');
Q(t)=ilaplace(Lap);
disp(simplify(Q(t)));
disp('I(t): ');
I(t)=diff(Q,t);
disp(I(t));

OUTPUT:

Enter inductance of circuit: 0.1


Enter resistance of circuit: 25
Enter Capacitance of circuit: 25*10^-6
Enter value of Q at t=0: 0.05
Enter the value of I at t=0: 0
Q(t):
(exp(-125*t)*(cos(25*7^(1/2)*t) + (5*7^(1/2)*sin(25*7^(1/2)*t))/7))/20

I(t):
(exp(-125*t)*(125*cos(25*7^(1/2)*t)-25*7^(1/2)*sin(25*7^(1/2)*t)))/20-(25*exp(125*t)*(cos(25*7^(1/2)*t)
+ (5*7^(1/2)*sin(25*7^(1/2)*t))/7))/4

You might also like