0% found this document useful (0 votes)
33 views32 pages

Ilovepdf Merged (1) Merged

The document contains instructions for solving differential equations using Mathematica. It provides 5 practice problems: 1) find the solution to y'' - 2y' + y = 0, 2) solve x2y'' + xy' + y = 0, 3) solve the third order equation y''' + 2y'' - y' - 2y = 0, 4) solve dy/dx = (x + y + 3)2, and 5) solve xy'' = y'. The solutions are found and plotted for problems 1-5.

Uploaded by

Keshav Prakash
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views32 pages

Ilovepdf Merged (1) Merged

The document contains instructions for solving differential equations using Mathematica. It provides 5 practice problems: 1) find the solution to y'' - 2y' + y = 0, 2) solve x2y'' + xy' + y = 0, 3) solve the third order equation y''' + 2y'' - y' - 2y = 0, 4) solve dy/dx = (x + y + 3)2, and 5) solve xy'' = y'. The solutions are found and plotted for problems 1-5.

Uploaded by

Keshav Prakash
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

Practice Assignment 1

B.Sc.(Hons) Mathematics I year Sem II

Solving differential equations using Mathematica:


Date: 12/04/2023
Use Wolfram Mathematica to solve the following:
1. 𝒚′′ − 𝟐𝒚′ + 𝒚 = 𝟎, 𝒚(𝟎) = 𝟑, 𝒚′ (𝟎) = 𝟏
2. 𝒙𝟐 𝒚′′ + 𝒙𝒚′ + 𝒚 = 𝟎
3. 𝒚′′′ + 𝟐𝒚′′ − 𝒚′ − 𝟐𝒚 = 𝟎, 𝒚(𝟎) = 𝟏, 𝒚′ (𝟎) = 𝟐, 𝒚′′ (𝟎) = 𝟎
𝒅𝒚
4. = (𝒙 + 𝒚 + 𝟑)𝟐
𝒅𝒙
5. 𝒙𝒚′′ = 𝒚′
Practice Assignment-1
Ques.1

In[4]:= DSolve[{y ''[x] - 2 * y '[x] + y[x] ⩵ 0, y[0] ⩵ 3, y '[0] ⩵ 1}, y[x], x]


Out[4]= y[x] → - ⅇx - 3 + 2 x

Ques.2
In[5]:= DSolve[x * x * y ''[x] + x * y[x] + y[x] ⩵ 0, y[x], x]
1
-(-1)23 + (-1)13 +(-1)23 
Out[5]= y[x] → x 2 BesselJ- - 11/3 - - 12/3 , 2 x  C[2] Gamma1 - ⅈ 3 +
1 1
(-1)13 - (-1)23 1/3 2/3
x2 2 BesselJ- 1 + - 1 ,2 x  C[1] Gamma1 + ⅈ 3 

Ques.3
In[25]:= tde = y '''[x] + 2 * y ''[x] - y '[x] ⩵ 0
DSolve[{tde, y[0] ⩵ 1, y '[0] ⩵ 2, y ''[0] ⩵ 0}, y[x], x]
Out[25]= - y′ [x] + 2 y′′ [x] + y(3) [x] ⩵ 0

1 -1+ 2  x 1+ 2  x
Out[26]= y[x] → - ⅇ -4 + 3 2 - 4 ⅇ2 2 x
-3 2 ⅇ2 2 x
+6ⅇ 
2

Ques.4
In[27]:= DSolvey '[x] ⩵ x + y[x] + 3 ^ 2, y[x], x
1
Out[27]= y[x] → - 3 - ⅈ - x + 

- + ⅇ2 ⅈ x C[1]
2

Ques.5
In[28]:= DSolve[x * y ''[x] ⩵ y '[x], y[x], x]
1
Out[28]= y[x] → x2 C[1] + C[2]
2
Practice Assignment 2

B.Sc.(Hons) Mathematics I year Sem II

Date: 17/05/2023
Plot the solution families of the following differential equations:
1. 𝒚′′ − 𝟐𝒚′ + 𝒚 = 𝟎
2. 𝒙𝟐 𝒚′′ + 𝒙𝒚′ + 𝒚 = 𝟎
3. 𝒚′′′ + 𝟐𝒚′′ − 𝒚′ − 𝟐𝒚 = 𝟎
𝒅𝒚
4. = √𝒙𝒚
𝒅𝒙
5. 𝒙𝒚′′ = 𝒚′
Practice Assignment - 2
Date-17/05/2023

Plot the Solution families of the following differential equations:

1. y''-2y'+y=0

In[7]:= eqn1 = y''[x] - 2 * y'[x] + y[x] ⩵ 0


sol1 = DSolveeqn1, y[x], x
PlotEvaluatey[x] /. sol1 /. C[1] → Range- 5, 5, C[2] → Range- 5, 5, x, - 5, 5

Out[7]= y[x] - 2 y′ [x] + y′′ [x] ⩵ 0

y[x] → ⅇ 1 + ⅇ x 2 
x x
Out[8]=

60

40

20

Out[9]=
-4 -2 2 4

-20

-40

-60

2.x^2y’’+xy’+y = 0
2

In[10]:= eqn2 = (x^2) * y''[x] + x * y'[x] + y[x] ⩵ 0


sol2 = DSolveeqn2, y[x], x
PlotEvaluatey[x] /. sol2 /. C[1] → Range- 6, 6, C[2] → 5 , x, 0, 10
Out[10]=

y[x] + x y′ [x] + x2 y′′ [x] ⩵ 0


Out[11]=

y[x] → 1 Cos[Log[x]] + 2 Sin[Log[x]]

Out[12]=

2 4 6 8 10

-5

3.y’’’+2y’’-y-2y = 0

In[13]:= eqn3 = y'''[x] + 2 * y''[x] - y'[x] - 2 * y[x] ⩵ 0


sol3 = DSolveeqn3, y[x], x
Plot Evaluatey[x] /. sol3 /. C[1] → Range0, 5, C[2] → Range5, 10, C[3] → Range4, 9,
x, - 10, 10
Out[13]=
′ ′′
[x] ⩵
(3 )
- 2 y[x] - y [x] + 2 y [x] + y 0
Out[14]=

y[x] → ⅇ 1 + ⅇ 2 + ⅇ 3 
-2 x -x x

Out[15]=

700 000

600 000

500 000

400 000

300 000

200 000

100 000

-10 -5 5 10
3

4. y’- (xy)^(1/2) =0

In[16]:= eqn4 = y'[x] - x * y[x] ^ 1  2 ⩵ 0


sol4 = DSolveeqn4, y[x], x
PlotEvaluatey[x] /. sol4 /. C[1] → Range- 5, 5, x, - 10, 10
Out[16]=

- x y[x] + y [x] ⩵ 0
Out[17]=
1
y[x] → 4 x + 12 x 1 + 9 1 
3 3 /2 2
36
Out[18]=

150

100

50

-10 -5 5 10

-50

-100

5. xy''=y'
4

In[20]:= eqn5 = x * y''[x] - y'[x] ⩵ 0


sol5 = DSolveeqn5, y[x], x
Plot Evaluatey[x] /. sol5 /. C[1] → Range- 10, 10, C[2] → Range- 10, 10, x, - 10, 20
Out[20]=
′ ′′
- y [x] + x y [x] ⩵ 0
Out[21]=

x2 1
y[x] → + 2 
2
Out[22]=

500

-10 -5 5 10 15 20

-500
Practice Assignment 3

B.Sc. (Hons) Mathematics I year Sem II

Date: 05/06/2023
Q1. When sugar is dissolved in water, the amount of sugar A, which remains
𝒅𝑨 𝑨
undissolved after t minutes satisfies the differential equation =− . Find
𝒅𝒕 𝟒
an expression for A in terms of t and depict it graphically. What happens
when 𝒕 → ∞.
Q2. a. Depict logistic growth model taking reproduction rate as 0.5 and
carrying capacity as 500, for 10 different values of the initial population.
Comment on the equilibrium positions and nature of the population curve as
time increases.
b. Change the carrying capacity to 1000 and observe the changes. Write
your observations as a comment under the plot.
Q3. Syntax related question:
a. What happens when an input line is terminated with a semicolon (;) ?
b. What is the difference between = and == in Mathematica?
c. Match (according to usage as Mathematica syntax):
Arguments to functions Parentheses ( )
Lists Square brackets [.]
Grouping in mathematical expressions Percentage sign %
Comments Curly braces { }
Using the last output parentheses and asterisks
(* *)
Practice Assignment-3
Q1. When sugar is dissolved in water, the amount of sugar A, which
remains undissolved after t minutes satisfies the differential equation
dA/dt=-A/4. Find an expression for A in terms of t and depict it
graphically. What happens
when t → ∞.

In[ ]:= DSolveA '[t] ⩵ - A[t]  4, A[t], t


PlotExp- t  4, 2 * Exp- t  4, 5 * Exp- t  4, {t, 0, 50}
Out[ ]= A[t] → ⅇ-t/4 C[1]

0.6

0.5

0.4

Out[ ]= 0.3

0.2

0.1

10 20 30 40 50

Clearly, as time passes the amount of sugar A,


which remains undissolved decreases and as t
approaches infinity then all sugar will be
dissolved in water.
2 Practice Assignment-3 - Copy.nb

Q2. a. Depict logistic growth model taking reproduction rate as 0.5 and
carrying capacity as 500, for 10 different values of the initial population.
Comment on the equilibrium positions and nature of the population
curve as time increases.
In[ ]:= r = 0.5;
k = 500;
eqn = D[z[t], t] ⩵ r * z[t] - r  k * z[t] ^ 2
sol = DSolve[{eqn, z[0] ⩵ z0}, z[t], t]
Plot[Evaluate[z[t] /. sol /. z0 → Range[495, 504]], {t, 4, 25}]
Out[ ]= z′ [t] ⩵ 0.5 z[t] - 0.001 z[t]2

500. × 2.718280.5 t
Out[ ]= z[t] → 
1.
2.718280.5 t + 1.  500.-1. z0 
z0

500.02

500.01

500.00
Out[ ]=

499.99

499.98

5 10 15 20 25
Practice Assignment-3 - Copy.nb 3

Equilibrium position is x := 500 , which is also carrying capacity .


Nature of curve := if the population size is less than carrying capacity ,it
increases towards k .

b. Change the carrying capacity to 1000 and observe the changes. Write
your observations as a comment under the plot.
In[ ]:= r = 0.5;
k = 1000;
eqn1 = D[z[t], t] ⩵ r * z[t] - r  k * z[t] ^ 2
sol1 = DSolve[{eqn1, z[0] ⩵ z0}, z[t], t]
Plot[Evaluate[z[t] /. sol1 /. z0 → Range[995, 1004]], {t, 4, 25}]
Out[ ]= z′ [t] ⩵ 0.5 z[t] - 0.0005 z[t]2

1000. × 2.718280.5 t
Out[ ]= z[t] → 
1.
2.718280.5 t + 1.  1000.-1. z0 
z0

1000.02

1000.01

1000.00
Out[ ]=

999.99

999.98

5 10 15 20 25

Equilibrium position is x = 1000 , which is also carrying capacity .


Nature of curve :- if the population size is less than carrying capacity ,it
increases towards k .
Q3. Syntax related question:
a. What happens when an input line is terminated with a semicolon (;) ?
b. What is the difference between = and == in Mathematica?
c. Match (according to usage as Mathematica syntax):

Solutions:-

a.When we end our input with semicolon , it means that we do not want that particular thing
to be displayed in the output .

b. In Mathematica “=” sign is used to assign a value to any variable . on the other hand,”==” is
4 Practice Assignment-3 - Copy.nb

used to compare the equality of objects on both sides of it .

c.
Arguments to functions
1.Square brackets [.]
Lists
2.Curly braces { }
Grouping in mathematical expressions
3.Parentheses ( )
Comments
4.parentheses and asterisks (* *)
Using the last output
5.Percentage sign %
Practice Assignment 4

B.Sc. (Hons) Mathematics I year Sem II

Date: 07/06/2023
Q1. A. Depict lake pollution model in the constant flowrate setting;
taking cin = 4, V = 30, F = 52 for ten different values of the initial
concentration. What happens to the concentration as t increases?
B. Modify the syntax to account for a seasonal flowrate given by 𝑭(𝒕) =
𝟖 + 𝟒 𝒄𝒐𝒔(𝟐𝝅𝒕), retaining the other values as they are in Part A. What
changes do you observe in the two plots? Write as a comment under
the plot.
Q2. A. Plot standard Lotka Volterra system of One Predator-One Prey
interaction, taking appropriate values of the constants of your choice
for the plot. Comment on the behaviour of the two populations as t
increases.
B. Modify the syntax to include one more prey in the model, assuming
that the two prey species do not interact with each other. What
happens as time progresses? Comment on the basis of the plot
obtained.
Q3. Syntax related question:
A. What is the difference between DSolve and NDSolve commands?
B. What is the use of PlotLegends command?
C. How does PlotStyle command help in getting advanced plots?
Practical Assignment 4
Q1. A. Depict lake pollution model in the constant flowrate setting; taking cin = 4, V = 30, F = 52 for
ten different values of the initial concentration. What happens to the concentration as t
increases?
In[35]:= cin = 4;
V = 30;
F = 52;
de = D[C[t], t] ⩵ (F / V) * (cin - C[t])
sol = DSolve[{de, C[0] ⩵ C0}, C[t], t]
Plot[Evaluate[C[t] /. sol /. C0 → Range[1, 10]], {t, 0, 10}]
Out[38]=

26 (4 - t)
C′ [t] ⩵
15
Out[39]=

-26 t15 26 t15


t → ⅇ - 4 + C0 + 4 ⅇ 

Out[40]=

4.04

4.02

4.00

3.98

2 4 6 8 10

As the 't' increases the value of concentration approaches to initial concentration , cin(4).

B. Modify the syntax to account for a seasonal flowrate given by F(t) = 8 + 4cos(2πt), retaining the
other values as they are in Part A. What changes do you observe in the two plots? Write as a
comment under the plot.
2

In[41]:= V = 30;
de1 = D[C[t], t] ⩵ 8 + 4 Cos[2 * Pi * t] * (4 - C[t])  V
sol1 = DSolve[{de1, C[0] ⩵ C0}, C[t], t]
Plot[Evaluate[C[t] /. sol1 /. C0 → Range[1, 10]], {t, 0, 10}]
Out[42]=
1
C′ [t] ⩵ (4 - t) 8 + 4 Cos2 π t
30
Out[43]=
4t Sin2 π t 4t Sin2 π t
- - +
t → ⅇ - 4 + C0 + 4 ⅇ 
15 15 π 15 15 π

Out[44]=

10

2 4 6 8 10

As time t increases, concentration approaches to a constant value , but graph is oscillating due to
the diverse seasons, which result into a non-stable flowrate .

Q2. A. Plot standard Lotka Volterra system of One Predator-One Prey interaction, taking appropri-
ate values of the constants of your choice for the plot. Comment on the behaviour of the two
populations as t increases.
3

In[13]:= b1 = 1; a2 = 0.5; c1 = 0.01; c2 = 0.005;


de2 = x '[t] ⩵ b1 * x[t] - c1 * x[t] * y[t]
de3 = y '[t] ⩵ c2 * x[t] * y[t] - a2 * y[t]
sol3 = NDSolve[{de2, de3, x[0] ⩵ 200, y[0] ⩵ 80}, {x[t], y[t]}, {t, 0, 50}];
PlotEvaluate[{x[t], y[t]} /. sol3], {t, 0, 50},
PlotRange → All, PlotLegends → {"Prey", "Predator"},
PlotStyle → Green, Thick, Dashed, Brown, Thick, Dashed
Out[14]=

x′ [t] ⩵ x[t] - 0.01 x[t] × y[t]


Out[15]=

y′ [t] ⩵ - 0.5 y[t] + 0.005 x[t] × y[t]


Out[17]=

200

150

Prey
Predator
100

50

10 20 30 40 50

As 't' increases the prey and predator population varies sinusoidally . As prey population increases
the predator has surplus prey and their population flourishes and at a certain limit due to increase
in predator population the population of prey started declining and this process continues.

B. Modify the syntax to include one more prey in the model, assuming that the two prey species
do not interact with each other. What happens as time progresses? Comment on the basis of the
plot obtained.
4

In[7]:= b1 = 1; b2 = 0.5; b3 = 0.5; c1 = 0.1; c2 = 0.01; c3 = 0.01; c4 = 0.01;


de4 = x '[t] ⩵ b1 * x[t] - c1 * x[t] * z[t]
de5 = y '[t] ⩵ b2 * y[t] - c2 * y[t] * z[t]
de6 = z '[t] ⩵ - b3 * z[t] + c3 * x[t] * z[t] + c4 * y[t] * z[t]
sol4 = NDSolve

de4, de5, de6, x[0] ⩵ 100, y[0] ⩵ 180, z[0] ⩵ 100, x[t], y[t], z[t], t, 0, 50;

PlotEvaluate[{x[t], y[t], z[t]} /. sol4], {t, 0, 50},

PlotRange → All, PlotLegends → "Prey 1", "Prey 2", "Predator"

Out[8]= x′ [t] ⩵ x[t] - 0.1 x[t] × z[t]

Out[9]= y′ [t] ⩵ 0.5 y[t] - 0.01 y[t] × z[t]


Out[10]=

z′ [t] ⩵ - 0.5 z[t] + 0.01 x[t] × z[t] + 0.01 y[t] × z[t]


Out[12]=

200

150
Prey 1

100 Prey 2
Predator
50

10 20 30 40 50

All three species can’t exist together as seen in the plot, as as result, only one prey will survive and
prey 1 will suffer the consequences and start declining. After some time, when predator’s popula-
tion exceeds prey 2, predators will start to decline too but after equilibrium point prey 2 will
increase in size, as time t passes, same periodic cycle can be seen.
5

Q3. Syntax related question:


A. What is the difference between DSolve and NDSolve commands?
Ans: DSolve is used to solve only one ordinary differential equation that is equation involving only
one dependent variable whereas NDSolve is used to solve multiple ordinary differential equations
that is equations involving multiple dependent variables.
B. What is the use of PlotLegends command?
Ans: It is used to label the graph of different dependent variables or that specifies what legend to use
providing a visual guide to the meaning of different plotted functions.
C. How does PlotStyle command help in getting advanced plots?
Ans:It is an option for in plotting that specifies styles in which objects are to be drawn.Using it we
can do different styling in graph like changing colour,thickness,and much more.
Practice Assignment 5

B.Sc. (Hons) Mathematics I year Sem II

Date: 16/06/2023
Q1. Plot the basic epidemic model governed by the differential
𝒅𝑺 𝒅𝑰
equations = −𝒃𝑺𝑰 , 𝒅𝒕 = 𝒃𝑺𝑰 − 𝒂𝑰; where b is the transmission
𝒅𝒕
coefficient and a is the recovery rate. Take 𝒃 = 𝟐. 𝟏𝟖 × 𝟏𝟎−𝟑 𝒂𝒏𝒅 𝒂 =
𝟎. 𝟒𝟒 and examine the behavior of the model for any set of initial values
of your choice. Comment on how the two populations: susceptible and
infective behave with passing time in this model.
Q2. Modify the above model assuming that the disease is such that
those infected remain contagious for life. How does this change the
model and the subsequent results. Plot the same and write the
comparative analysis of the two settings (i.e. Q1 and Q2).
Q3. Consider a disease where all infectives recover from the disease and
become susceptible again. A model that captures this setting is given
𝒅𝑺 𝒅𝑰
by: = −𝒃𝑺𝑰 + 𝒂𝑰 , 𝒅𝒕 = 𝒃𝑺𝑰 − 𝒂𝑰; where b is the transmission
𝒅𝒕
coefficient and a is the recovery rate. Plot this model for the same set
of values of a and b as in Q1 and analyze the difference in the plot
obtained in this setting as compared to Q1.
Practice Assignment 5
Q1. Plot the basic epidemic model governed by the differential equations dS/dt=-bSI , dI/dt=bSI-aI;
where b is the transmission coefficient and a is the recovery rate. Take b =2.18 × 10^-3 and a=0.44.
and examine the behavior of the model for any set of initial values of your choice. Comment on how
the two populations: susceptible and infective behave with passing time in this model.
b = 0.00218;
a = 0.44;
de1 = s '[t]  - b * s[t] * i[t]
de2 = i '[t]  b * s[t] * i[t] - a * i[t]
de3 = r '[t]  a * i[t]
sol =
NDSolve[{de1, de2, de3, s[0]  500, i[0]  1, r[0]  0}, {s[t], i[t], r[t]}, {t, 0, 50}]
Plot[Evaluate[{s[t], i[t], r[t]} /. sol], {t, 0, 50}, PlotRange  All,
PlotLegends  {"susceptibles", "infectives", "recovered"}]

O u t [ ] =

s′ [t]  - 0.00218 i[t] × s[t]


O u t [ ] =

i′ [t]  - 0.44 i[t] + 0.00218 i[t] × s[t]


O u t [ ] =

r′ [t]  0.44 i[t]


O u t [ ] =

Domain: 0., 50.


s[t]  InterpolatingFunction [t],
Output: scalar

Domain: 0., 50.


i[t]  InterpolatingFunction [t],
Output: scalar

Domain: 0., 50.


r[t]  InterpolatingFunction [t]
Output: scalar

O u t [ ] =

500

400

300 susceptibles
infectives
200
recovered

100

10 20 30 40 50
2 Ayush 8775 assignment 5 (4).nb

As the time increases , the number of susceptibles decreases and number of infectives increases
due to spread of disease. It can be seen that around 50 susceptibles never get infected with this
set of choices for the interacation,recovery parameters and initial conditions.

Q2. Modify the above model assuming that the disease is such that those infected remain conta-
gious for life. How does this change the model and the subsequent results. Plot the same and write
the comparative analysis of the two settings (i.e. Q1 and Q2).
b = 0.00218;
a = 0.44;
de1 = s '[t]  - b * s[t] * i[t]
de2 = i '[t]  b * s[t] * i[t]
sol = NDSolve[{de1, de2, s[0]  500, i[0]  1}, {s[t], i[t]}, {t, 0, 50}]
Plot[Evaluate[{s[t], i[t]} /. sol], {t, 0, 50},
PlotRange  All, PlotLegends  {"susceptibles", "infectives"}]

O u t [ ] =

s′ [t]  - 0.00218 i[t] × s[t]


O u t [ ] =

i′ [t]  0.00218 i[t] × s[t]


O u t [ ] =

Domain: 0., 50.


s[t]  InterpolatingFunction [t],
Output: scalar

Domain: 0., 50.


i[t]  InterpolatingFunction [t]
Output: scalar

O u t [ ] =

500

400

300
susceptibles
infectives
200

100

10 20 30 40 50

As the recovery factor is missing , the infectives increases with time and susceptibles decreases
due to their interaction with infected individuals. after some time the infectives become 500 =
total population and susceptables decreases to zero.

Q3. Consider a disease where all infectives recover from the disease and become susceptible again.
A model that captures this setting is given by:dS/dt=-bSI+aI , dI/dt=bSI-aI ; where b is the transmis-
Ayush 8775 assignment 5 (4).nb 3

sion coefficient and a is the recovery rate. Plot this model for the same set of values of a and b as in
Q1 and analyze the difference in the plot obtained in this setting as compared to Q1.

b = 0.00218;
a = 0.44;
de1 = s '[t]  - b * s[t] * i[t] + a * i[t]
de2 = i '[t]  b * s[t] * i[t] - a * i[t]
sol = NDSolve[{de1, de2, s[0]  500, i[0]  1}, {s[t], i[t]}, {t, 0, 50}]
Plot[Evaluate[{s[t], i[t]} /. sol], {t, 0, 50},
PlotRange  All, PlotLegends  {"susceptibles", "infectives"}]

O u t [ ] =

s′ [t]  0.44 i[t] - 0.00218 i[t] × s[t]


O u t [ ] =

i′ [t]  - 0.44 i[t] + 0.00218 i[t] × s[t]


O u t [ ] =

Domain: 0., 50.


s[t]  InterpolatingFunction [t],
Output: scalar

Domain: 0., 50.


i[t]  InterpolatingFunction [t]
Output: scalar

O u t [ ] =

500

400

300
susceptibles
infectives
200

100

10 20 30 40 50

In comparison with question 1 where infectives were getting converted into recovered so they
first increases and then decreases, so we have a extra recovered population whereas in question
3 the infectives are getting converted into susceptibles so recovered population is missing . In
question 3, susceptibles first decreases and infectives first increases and at some time they both
become constant and around 200 people never become infected .
Practice Assignment 6

B.Sc. (Hons) Mathematics I year Sem II

Date: 03/07/2023

Use the method of Variation of Parameters to solve the following using


Mathematica:
1. 𝑦 ′′ + 3𝑦 ′ + 2𝑦 = 4𝑒 𝑥
2. 𝑦 ′′ + 9𝑦 = 2 𝑠𝑒𝑐3𝑥
3. 𝑦 ′′ − 4𝑦 = 𝑠𝑖𝑛2 𝑥
4. 𝑦 ′′ − 4𝑦 = 𝑠𝑖𝑛ℎ2𝑥
Practice Assignment-6
Use the method of Variation of Parameters to solve the following using
Mathematica:
1.y’’+3y’+2y=4e^x
In[1]:= eqn = y ''[x] + 3 * y '[x] + 2 * y[x] ⩵ 4 * Exp[x]
CF = DSolve[y ''[x] + 3 * y '[x] + 2 * y[x] ⩵ 0, y[x], x]
Out[1]= 2 y[x] + 3 y′ [x] + y′′ [x] ⩵ 4 ⅇx

Out[2]= y[x] → ⅇ-2 x C[1] + ⅇ-x C[2]

In[3]:= u[x_] := Exp[- 2 * x]


v[x_] := Exp[- x]
W = Simplify[Det[{{u[x], v[x]}, {u '[x], v '[x]}}]]
Out[5]= ⅇ-3 x

In[6]:= f1 = Integrate[- (v[x] * 4 * Exp[x]), x]


g1 = Integrate[u[x] * 4 * Exp[x], x]
Out[6]= -4 x

Out[7]= - 4 ⅇ-x

In[8]:= PI = f1 * u[x] + g1 * v[x]


Out[8]= - 4 ⅇ-2 x - 4 ⅇ-2 x x

In[9]:= CF + PI
Out[9]= - 4 ⅇ-2 x - 4 ⅇ-2 x x + y[x] → ⅇ-2 x C[1] + ⅇ-x C[2]

2. y’’+9y=2Sec(3x)
In[10]:= eqn1 = y ''[x] + 9 * y[x] ⩵ 2 * Sec[3 * x]
CF = DSolve[y ''[x] + 9 * y[x] ⩵ 0, y[x], x]
Out[10]= 9 y[x] + y′′ [x] ⩵ 2 Sec[3 x]

Out[11]= {{y[x] → C[1] Cos[3 x] + C[2] Sin[3 x]}}

In[12]:= u[x_] := Cos[3 * x]


v[x_] := Sin[3 * x]
W = Simplify[Det[{{u[x], v[x]}, {u '[x], v '[x]}}]]
Out[14]= 3

In[15]:= f1 = Integrate- v[x] * 2 * Sec[3 * x], x


g1 = Integrate[u[x] * 2 * Sec[3 * x], x]
2
Out[15]= Log[Cos[3 x]]
3
Out[16]= 2x
2 Practical Assignment-6.nb

In[17]:= PI = f1 * u[x] + g1 * v[x]


2
Out[17]= Cos[3 x] Log[Cos[3 x]] + 2 x Sin[3 x]
3

In[18]:= CF + PI
2
Out[18]=  Cos[3 x] Log[Cos[3 x]] + y[x] → C[1] Cos[3 x] + C[2] Sin[3 x] + 2 x Sin[3 x]
3

3. y’’-4y=(sinx)^2
In[19]:= eqn2 = y ''[x] - 4 * y[x] ⩵ Sin[x] ^ 2
CF = DSolve[y ''[x] - 4 * y[x] ⩵ 0, y[x], x]
Out[19]= - 4 y[x] + y′′ [x] ⩵ Sin[x]2

Out[20]= y[x] → ⅇ2 x C[1] + ⅇ-2 x C[2]

In[21]:= u[x_] := Exp[2 * x]


v[x_] := Exp[- 2 * x]
W = Simplify[Det[{{u[x], v[x]}, {u '[x], v '[x]}}]]
Out[23]= -4

In[24]:= f1 = Integrate- v[x] * Sin[x] ^ 2, x


g1 = Integrate[u[x] * Sin[x] ^ 2, x]
1
Out[24]= - ⅇ-2 x - 2 + Cos[2 x] - Sin[2 x]
8
1
Out[25]= - ⅇ2 x - 2 + Cos[2 x] + Sin[2 x]
8

In[26]:= PI = f1 * u[x] + g1 * v[x]


1 1
Out[26]= 2 - Cos[2 x] - Sin[2 x] + 2 - Cos[2 x] + Sin[2 x]
8 8

In[27]:= CF + PI
1 1
Out[27]= y[x] → ⅇ2 x C[1] + ⅇ-2 x C[2] + 2 - Cos[2 x] - Sin[2 x] + 2 - Cos[2 x] + Sin[2 x]
8 8

4. y’’-4y=sinh2x
In[28]:= eqn3 = y ''[x] - 4 * y[x] ⩵ Sinh[2 * x]
CF = DSolve[y ''[x] - 4 * y[x] ⩵ 0, y[x], x]
Out[28]= - 4 y[x] + y′′ [x] ⩵ Sinh[2 x]

Out[29]= y[x] → ⅇ2 x C[1] + ⅇ-2 x C[2]

In[30]:= u[x_] := Exp[2 * x]


v[x_] := Exp[- 2 * x]
W = Simplify[Det[{{u[x], v[x]}, {u '[x], v '[x]}}]]
Out[32]= -4
Practical Assignment-6.nb 3

In[33]:= f1 = Integrate- v[x] * Sinh[2 * x], x


g1 = Integrate[u[x] * Sinh[2 * x], x]
ⅇ-4 x x
Out[33]= -2 +
16 4

ⅇ4 x x
Out[34]= -
8 2

In[35]:= PI = f1 * u[x] + g1 * v[x]


ⅇ4 x x ⅇ-4 x x
Out[35]= ⅇ-2 x - - 2 ⅇ2 x +
8 2 16 4

In[36]:= CF + PI
ⅇ4 x x ⅇ-4 x x
Out[36]= ⅇ-2 x - - 2 ⅇ2 x + + y[x] → ⅇ2 x C[1] + ⅇ-2 x C[2]
8 2 16 4

You might also like