Method of Variation of Parameters Experiment-6
Method of Variation of Parameters Experiment-6
Experiment-6
Title: Solution of differential Equations by the
method of variation of parameters
d2y dy
p qy f ( x) , where p, q are constants.
dx 2 dx
Let the complimentary function be of the form yc C1 y1 ( x) C2 y 2 ( x) , where C1 , C2
d2y dy
p qy 0 .
dx 2 dx
In the method of variation of parameters, the arbitrary constants C1 , C2 are replaced with two unknown
functions u (x) and v (x ) .
Let us assume that the particular integral is of the form y p u ( x) y1 ( x) v( x) y 2 ( x)
y 2 ( x) f ( x) y1 ( x) f ( x)
where u ( x) dx and v( x) dx .
y1 y 2' y1' y 2 y1 y 2' y1' y 2
On putting the values of u (x) and v (x ) in (14), we get the particular integral y p .
Hence the required solution y ( x) y c y p .
MATLAB CODE
% Prog ra m for solvin g d iffe re n tia l e q ua tion of the form
% a y"+ by'+ cy= f(x), for a , b a n d c a s con sta n ts.
cle a r a ll
close a ll
clc
sym s A B x m
p = in p u t('E nte r th e coe fficie nts a , b, c');
f= in p u t('E n te r th e R H S fu nction f(x)');
a = p (1 ); b = p (2); c= p (3 );
d isc= b ^ 2 -4*a *c;
m = su b s(solve ('a *m ^ 2 + b *m + c') );
if(d isc> 0 )
C F = A*exp (m (1 )*x)+ B*e xp (m (2 )*x);
u = exp (m (1)*x); v= e xp (m (2 )*x);
e lse if (disc= = 0 )
C F = (A+ B*x)*exp(m (1 )*x);
u = e xp (m (1 )*x); v= x*exp (m (1)*x);
e lse
a lfa = re a l(m (1 ));
be ta = im a g (m (1));
C F = e xp (a lfa *x)*(A*cos(be ta *x)+ B*sin (b e ta *x));
u = e xp (a lfa *x)*cos(b e ta *x); v= exp (a lfa *x)*sin (b eta *x);
end
% Method of variation of parameters.
f1=f/a;
jac=u*diff(v,x)-diff(u,x)*v; % Jacobian of u and v
P=int(-v*f1/jac,x);
Q=int(u*f1/jac,x);
PI=P*u+Q*v;
y_ gen=CF+PI;
dy_ gen=diff(y_ gen);
cond=input('Enter the initial conditions x0, y(x0) and Dy(x0)');
eq1=(subs(y_ gen,x,cond(1))-cond(2));
eq2=(subs(dy_ gen,x,cond(1))-cond(3));
[A B]=solve(eq1,eq2);
y=subs(CF+PI)
d2y dy
Example 1: Solve the equation 5 6 y sin 3x , y (0) 0 , y (0) 1 .
dx 2 dx
MATLAB input
Enter the coefficients a,b,c [1 -5 6]
Enter the RHS function f(x) sin(3*x)
Enter the initial conditions x0, y(x0) and Dy(x0) [0 0 1]
MATLAB output
y=
(5*cos(3*x))/78 - (16*exp(2*x))/13 + (7*exp(3*x))/6 - sin(3*x)/78
d2y w( x )
Example 2: Consider the problem of suspension cable
dx 2 TH
dy
with the conditions y (0) 0 , 0.
dx x 0
MATLAB code
MATLAB output
y=
x^2/2
-------------------------------------------------------------------------------------------------------------
MATLAB input
Enter the external load: x
Enter the horizontal tension: 1
MATLAB output
y=
x^3/6
Exercise problems:
d2y dy 1
1. Solve the equation 2
4 4 y sin 2 x , y ( 0 ) , y (0) 4 .
dx dx 8
d 2 y dy
2. Solve the equation 2
6 y x , y (0) 0 , y (0) 1 .
dx dx