FALLSEM2019-20 MAT2002 ELA VL2019201000472 Reference Material I 29-Aug-2019 EXP 3A

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

Department of Mathematics

School of Advanced Sciences


MAT 2002 – Applications of Differential and Difference Equations (MATLAB)
Experiment 3–A
Solution of a Linear differential equation by method of variation of parameters.

Method of variation of parameters:

We consider a second order linear differential equation of the form

d2y dy
F ( D) y  2
 p ( x)  q ( x) y  f ( x) (1)
dx dx

Let the solutions of the homogeneous problem of F ( D) y  0 be y1 ( x) and y 2 ( x ) .

Then the Complementary function (solution of the homogeneous problem) of (1) is

yc ( x)  C1 y1  C2 y2 (2)

Then by the method of variation of parameters the particular integral of (1) is of the form

y p ( x)  uy1  vy2 (3)

where the parameters C1 , C2 of (2) are replaced with functions u (x) , v(x) given by

y2 f ( x) y f ( x)
u ( x)    dx and v( x)   1 dx ,
W ( x) W ( x)

y1 y2
where the wronskian W ( x)   y1 y2 ' y2 y1 '  0 .
y1 ' y2 '

In this experiment we consider the coefficients p, q to be constants.

MATLAB Code:

clear all
close all
clc
syms c1 c2 x m
F=input('Enter the coefficients [a,b,c]: ');
f=input('Enter the RHS function f(x): ');
a=F(1);b=F(2);c=F(3);
AE=a*m^2+b*m+c; % Auxilliary Equation
m=solve(AE);
m1=m(1); m2=m(2);
D=b^2-4*a*c;
if(D>0) % Roots are real and different
y1=exp(m1*x);y2=exp(m2*x);
elseif (D==0)% Roots are real and equal

Department of Mathematics, Vellore Institute of Technology, Vellore. Page 1


y1=exp(m1*x);y2=x*exp(m1*x);
else % Roots are complex
alfa=real(m1);beta=imag(m1);
y1=exp(alfa*x)*cos(beta*x);
y2=exp(alfa*x)*sin(beta*x);
end
yc=c1*y1+c2*y2; % Complimentary Solution
%%% Particular Integral by Method of variation of parameters.
fx=f/a;
W=y1*diff(y2,x)-y2*diff(y1,x); %%% Wronskian%%%
u=int(-y2*fx/W,x);
v=int(y1*fx/W,x);
yp=y1*u+y2*v; %%%Particular Integral%%%
y_gen=yc+yp; %%%General Solution%%%
check=input('If the problem has initial conditions then enter
1 else enter 2: ');
if(check==1)
cn=input('Enter the initial conditions [x0, y(x0), Dy(x0)]:');
dy_gen=diff(y_gen);
eq1=(subs(y_gen,x,cn(1))-cn(2));
eq2=(subs(dy_gen,x,cn(1))-cn(3));
[c1 c2]=solve(eq1,eq2);
y=simplify(subs(y_gen));
disp('The complete solution is');
disp(y);
ezplot(y, [cn(1),cn(1)+2]);
else
y=simplify(y_gen);
disp('The General Solution is ');
disp(y);
end

Example 1. Find the general solution of the differential equation y  4 y  e2 x .

Enter the coefficients [a,b,c]: [1 0 -4]


Enter the RHS function f(x): exp(2*x)
If the problem has initial conditions then enter 1 else enter 2: 2
The General Solution is
(exp(-2*x)*(16*c1 - exp(4*x) + 4*x*exp(4*x) + 16*c2*exp(4*x)))/16

Example 2. Find the general solution of the differential equation y  y  sec x tan x .

Enter the coefficients [a,b,c]: [1 0 1]


Enter the RHS function f(x): sec(x)*tan(x)
If the problem has initial conditions then enter 1 else enter 2: 2
The General Solution is
(log(tan(x)^2 + 1)*sin(x))/2 - sin(x) + c1*cos(x) - c2*sin(x) + x*cos(x)

Department of Mathematics, Vellore Institute of Technology, Vellore. Page 2


Example 3: Suppose that a spring with a mass of 2 kg. has natural length 0.5 m. A force of
25.6 N is required to maintain it stretched to a length of 0.2 m. The spring is immersed in a
fluid with damping constant c=40. Find the position of the mass at any time t if it starts from
the equilibrium position and is given a push to start with an initial velocity of 0.6 m/s.

Solution: The differential equation pertaining the motion of the spring described by the
d 2x dx
differential equation m 2
 c  ky  0 .
dt dt

25.6
Given mass m  2 , spring constant k   128 , damping constant c  40 .
0 .2

d 2x dx
Therefore, the differential equation is 2
 20  64 x  0 with x(0)  0 ; x(0)  0.6 .
dt dt

Input/Output:
Enter the coefficients [a,b,c]: [1 20 64]
Enter the RHS function f(x): 0
If the problem has initial conditions then enter 1 else enter 2: 1
Enter the initial conditions [x0, y(x0), Dy(x0)]:[0 0 0.6]
The complete solution is
(exp(-16*x)*(exp(12*x) - 1))/20

Inference: Here c 2  4mk  0 . Hence it is a case of over damping, therefore no


oscillations occur.

Example 4: Consider the above problem with the spring constant c  14 , other parameters
being the same.

The spring constant here is k  128 . Damping constant c  14 , the mass m  2 .

Department of Mathematics, Vellore Institute of Technology, Vellore. Page 3


d 2x dx
So the differential equation becomes 2
 7  64 x  0 , with x(0)  0 ; x(0)  0.6 .
dt dt

Input/Output:
Enter the coefficients [a,b,c]: [1 7 64]
Enter the RHS function f(x): 0
If the problem has initial conditions then enter 1 else enter 2: 1
Enter the initial conditions [x0, y(x0), Dy(x0)]:[0 0 0.6]
The complete solution is
(2*23^(1/2)*exp(-(7*x)/2)*sin((3*23^(1/2)*x)/2))/115

Inference: Here c 2  4mk  0 . It is a case of under damping. Some oscillations occur.

Example 5: Find the charge in the RLC circuit at time t in the circuit when a resistance of
40 , inductance of 1H and a capacitance of 16  10 4 F are connected in series with a
source of voltage E (t )  100 cos10t , given that initially the charge and current are both 0.

The differential equation for the RLC circuit is

1
LQ  RQ  Q  E (t )
C

Here R  40 , L  1 , C  16  10 4 , E (t )  100 cos10t .

Therefore, the differential equation is

Q  40Q  625Q  100cos10t with Q(0)  0 ; Q(0)  0 .

Input/Output
Enter the coefficients [a,b,c]: [1,40,625]
Enter the RHS function f(x): 100*cos(10*x)
If the problem has initial conditions then enter 1 else enter 2: 1
Enter the initial conditions [x0, y(x0), Dy(x0)]:[0,0,0]

Department of Mathematics, Vellore Institute of Technology, Vellore. Page 4


The complete solution is
(84*cos(10*x))/697 + (64*sin(10*x))/697 - (84*cos(15*x)*exp(-20*x))/697 -
(464*sin(15*x)*exp(-20*x))/2091

Exercise:

1. Find the general solution of the differential equation y  2 y  e x sin x .

2. Solve the initial value problem

y  4 y  20 y  23 sin x  15 cos x , y(0)  0 , y' (0)  1 .

3. Find the current I(t) in an RLC circuit with R=11Ω, L=0.1 H, C=10-2 F , which is
connected to a source of voltage E(t) = 100 sin400t. Assume that the current and the
charge are zero when t=0.

4. A spring with mass of 2kg has damping constant 14, and a force of 6N is required to
keep the spring stretched 0.5 m beyond its natural length. The spring is stretched 1m
beyond its natural length and then released with zero velocity. Find the position of
the mass at any time t.

Department of Mathematics, Vellore Institute of Technology, Vellore. Page 5

You might also like