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

Practical 1-Merged

This document solves several first, second and third order differential equations. It provides solutions to sample initial value problems and plots the solutions. Example differential equations include first order equations with solutions involving exponential and trigonometric functions, second order equations with constant coefficients and variable coefficients, and third order equations.

Uploaded by

chaltau088
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)
31 views

Practical 1-Merged

This document solves several first, second and third order differential equations. It provides solutions to sample initial value problems and plots the solutions. Example differential equations include first order equations with solutions involving exponential and trigonometric functions, second order equations with constant coefficients and variable coefficients, and third order equations.

Uploaded by

chaltau088
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/ 41

Practical 1

Solutions of first, second and third order differential


equations
In[11]:= ? DSolve

DSolve@eqn, y, xD solves a differential equation for the function y, with independent variable x.
DSolve@8eqn1 , eqn2 , …<, 8y1 , y2 , …<, xD solves a list of differential equations.
DSolve@eqn, y, 8x1 , x2 , …<D solves a partial differential equation. ‡

Q1. Solve the following first order differential equations :

HaL
dy
+ y = 0
dx
In[12]:= sol1 = DSolve@y'@xD + y@xD Š 0, y@xD, xD
Out[12]= 88y@xD ® ã-x C@1D<<

In[13]:=

HbL
dy
+ 2 y = sinHxL
dx
In[14]:= sol2 = DSolve@y'@xD + 2 y@xD Š Sin@xD, y@xD, xD

::y@xD ® ã-2 x C@1D + H-Cos@xD + 2 Sin@xDL>>


1
Out[14]=
5
Q2. Solve the following second order differential equations:

d2 y dy
(a) 2 +3 dx
+ y = 0
dx

sol3 = DSolve@y''@xD + 3 y'@xD + 2 y@xD Š 0, y@xD, xD


99y@xD ® ã-2 x C@1D + ã-x C@2D==
In[15]:=

Out[15]=

d2 y
(b) + 3 y = x.
dx2
2 Practical 1.nb

In[16]:= sol4 = DSolve@y''@xD + 3 y@xD == x, y@xD, xD

::y@xD ® + C@1D CosA 3 xE + C@2D SinA 3 xE>>


x
Out[16]=
3

d2 y dy
(c) 4 2 + 10 dx
+9y = 0
dx

In[17]:= sol5 = DSolve@4 y''@xD + 10 y'@xD + 9 y@xD Š 0, y@xD, xD

::y@xD ® ã-5 x4 C@2D CosB F + ã-5 x4 C@1D SinB F>>
11 x 11 x
Out[17]=
4 4
Example: Solve the following intial value problems and plot their solutions:

d2 y 1
(a) 2 + y = 0 with C1 = 1, 2
, -1, -1 and C2 = 5, 3, -2, -8.
dx

In[18]:= sol6 = DSolve@y''@xD + y@xD Š 0, y@xD, xD


sol = Evaluate@
y@xD . sol6@@1DD . 8C@1D ® 81, 1  2, -1, -1<, C@2D ® 85, 3, -2, -8<<D
Plot@sol, 8x, -20, 20<, PlotStyle ®
88Red, [email protected]<, 8Green, Thick<, 8Purple, Dashed<, Pink<D
Out[18]= 88y@xD ® C@1D Cos@xD + C@2D Sin@xD<<

:Cos@xD + 5 Sin@xD,
Cos@xD
Out[19]= + 3 Sin@xD, -Cos@xD - 2 Sin@xD, -Cos@xD - 8 Sin@xD>
2

Out[20]=
-20 -10 10 20

-5

d2 y
(b) + y = SecHxL with C1 = -14, 10. - 2 and C2 = 4, -1, 3.
dx2
Practical 1.nb 3

In[21]:= sol7 = DSolve@y''@xD + y@xD == Sec@xD, y@xD, xD


Out[21]= 88y@xD ® C@1D Cos@xD + Cos@xD Log@Cos@xDD + x Sin@xD + C@2D Sin@xD<<

solA =
Evaluate@y@xD . sol7@@1DD . 8C@1D ® 8-14, 10, -2<, C@2D ® 84, -1, 3<<D
In[22]:=

Out[22]= 8-14 Cos@xD + Cos@xD Log@Cos@xDD + 4 Sin@xD + x Sin@xD,


10 Cos@xD + Cos@xD Log@Cos@xDD - Sin@xD + x Sin@xD,
-2 Cos@xD + Cos@xD Log@Cos@xDD + 3 Sin@xD + x Sin@xD<
Plot@solA, 8x, -20, 20<,
PlotStyle ® 88Pink, [email protected]<, 8Blue, Thick<, 8Brown<<,
In[23]:=

PlotLegends ® 8solA@@1DD, solA@@2DD, solA@@3DD<D


Plot::optx : Unknown option PlotLegends in
Plot@solA, 8†1‡<, †1‡, PlotLegends ® 8solAP1T, solAP
2T, solAP3T<D. ‡
Plot@solA, 8x, - 20, 20<, PlotStyle ® 88Pink, [email protected]<, 8Blue, Thick<, 8Brown<<,
PlotLegends ® 8solAP1T, solAP2T, solAP3T<D
Out[23]=

Example: Solve the following third order differential equations:

d3 y d2 y dy
(a) 3 +3 2 +4 dx
- 2 y = CosHxL + ex with C1 = 1, -2, 3 and C2 = 4, -9, 2
dx dx
and C3 = -1, 2, -4.

In[24]:= sol8 = DSolve@y'''@xD - 3 y''@xD + 4 y'@xD - 2 y@xD Š Cos@xD + Exp@xD, y@xD, xD


::y@xD ® ãx C@3D + ãx C@2D Cos@xD + ãx C@1D Sin@xD +
1
Out[24]=
10
H10 ãx x + Cos@xD Cos@2 xD + 5 Sin@xD + 2 Cos@2 xD Sin@xD - 2 Cos@xD Sin@2 xD + Sin@xD Sin@2 xDL>>
4 Practical 1.nb

solB = Evaluate@y@xD . sol8@@1DD .


8C@1D ® 81, -2, 3<, C@2D ® 84, -9, 2<, C@3D ® 8-1, 2, -4<<D
In[25]:=

Out[25]= :-ãx + 4 ãx Cos@xD + ãx Sin@xD +

H10 ãx x + Cos@xD Cos@2 xD + 5 Sin@xD + 2 Cos@2 xD Sin@xD -


1
10
2 Cos@xD Sin@2 xD + Sin@xD Sin@2 xDL,

H10 ãx x + Cos@xD Cos@2 xD +


1
2 ãx - 9 ãx Cos@xD - 2 ãx Sin@xD +
10
5 Sin@xD + 2 Cos@2 xD Sin@xD - 2 Cos@xD Sin@2 xD + Sin@xD Sin@2 xDL,

H10 ãx x + Cos@xD Cos@2 xD +


1
-4 ãx + 2 ãx Cos@xD + 3 ãx Sin@xD +
10
5 Sin@xD + 2 Cos@2 xD Sin@xD - 2 Cos@xD Sin@2 xD + Sin@xD Sin@2 xDL>

Plot@solB, 8x, -2, 2<,


PlotStyle ® 88Pink<, 8Blue, Thick<, 8Green<<,
In[26]:=

PlotLegends ® 8"Sol 1", "Sol 2", "Sol 3"<D


Plot::optx : Unknown option PlotLegends in
Plot@solB, †1‡, †1‡, PlotLegends ® 8Sol 1,
Sol 2, Sol 3<D. ‡
Plot@solB, 8x, - 2, 2<, PlotStyle ® 88Pink<, 8Blue, Thick<, 8Green<<,
PlotLegends ® 8Sol 1, Sol 2, Sol 3<D
Out[26]=

d3 y
(b) - 27 y = 0 with C1 = 1, 2, 3 and C2 = -4, -19, -2 and C3 = 5, 20, 3.
dx3

In[27]:= sol9 = DSolve@y'''@xD - 27 y@xD Š 0, y@xD, xD

::y@xD ® ã3 x C@1D + ã-3 x2 C@2D CosB F + ã-3 x2 C@3D SinB F>>
3 3 x 3 3 x
Out[27]=
2 2
Practical 1.nb 5

solC = Evaluate@y@xD . B@@1DD .


8C@1D ® 81, 2, 3<, C@2D ® 8-4, -19, -2<, C@3D ® 85, 20, 3<<D
In[28]:=

Part::partd : Part specification BP1T is longer than depth of object. ‡

ReplaceAll::reps :
8BP1T< is neither a list of replacement rules nor a valid dispatch table, and so cannot be used for replacing. ‡

Out[28]= y@xD . BP1T


Plot@solC, 8x, -2, 1<,
PlotStyle ® 88Pink<, 8Blue, Thick<, 8Green<<,
In[29]:=

PlotLegends ® 8"Sol 1", "Sol 2", "Sol 3"<D


Plot::optx : Unknown option PlotLegends in
Plot@solC, †1‡, †1‡, PlotLegends ® 8Sol 1,
Sol 2, Sol 3<D. ‡
Plot@solC, 8x, - 2, 1<, PlotStyle ® 88Pink<, 8Blue, Thick<, 8Green<<,
PlotLegends ® 8Sol 1, Sol 2, Sol 3<D
Out[29]=
PRACTICAL -2
PLOTTTING OF SOLUTIONS OF FIRST , SECOND AND THIRD ORDER DIFFERENTIAL EQUA-
TION :-
1) FIRST ORDER DIFFERENTIAL EQUATION -

PLOTTING OF SOLUTIONS OF FIRST ORDER DIFFERENTIAL EQUATIONS :-

QUES 1- dy/dx + y = sinx


In[1]:= sol1 = DSolve@y '@xD + y@xD == Sin@xD, y@xD, xD

::y@xD ® ã-x C@1D + H- Cos@xD + Sin@xDL>>


1
Out[1]=
2
In[2]:= ans1 = Evaluate@y@xD . sol1@@1DD . 8C@1D ® 81, 5<<D

:ã-x + H- Cos@xD + Sin@xDL, 5 ã-x + H- Cos@xD + Sin@xDL>


1 1
Out[2]=
2 2
In[3]:= Plot@ans1, 8x, 0, 20<D

2.5

2.0

1.5

Out[3]= 1.0

0.5

5 10 15 20

-0.5

QUES 2- 2 x y dy/dx - 4x^2 - 3y^2 = 0


In[4]:= sol2 = DSolve@2 x y@xD y '@xD - 4 x ^ 2 - 3 Hy@xDL ^ 2 == 0, y@xD, xD

Out[4]= ::y@xD ® - x - 4 + x C@1D >, :y@xD ® x - 4 + x C@1D >>

In[5]:= ans2 = Evaluate@y@xD . sol2@@1DD . 8C@1D ® 81, 5<<D

Out[5]= :- - 4 + x x, - x -4 + 5 x >

In[6]:= Plot@ans2, 8x, - 5, 50<D

10 20 30 40 50

-200

Out[6]= -400

-600

-800

3) y' - y - 5 = 0
2 PRACTICAL-2 .nb

In[7]:= sol3 = DSolve@y '@xD - y@xD - 5 == 0, y@xD, xD


Out[7]= 88y@xD ® - 5 + ãx C@1D<<

In[8]:= ans3 = Evaluate@y@xD . sol3@@1DD . 8C@1D ® 81, 5<<D


Out[8]= 8- 5 + ãx , - 5 + 5 ãx <

In[9]:= Plot@ans3, 8x, 0, 5<D

300

250

200

Out[9]=
150

100

50

1 2 3 4 5

PLOTTING SOLUTIONS OF SECOND ORDER DIFFERENTIAL EQUATIONS :-


1) d^2y/dx^2 + y = 0
In[10]:= sol4 = DSolve@y ''@xD + y@xD == 0, y@xD, xD
Out[10]= 88y@xD ® C@1D Cos@xD + C@2D Sin@xD<<

In[11]:= ans4 = Evaluate@y@xD . sol4@@1DD . 8C@1D ® 1, C@2D ® 2<D


Out[11]= Cos@xD + 2 Sin@xD

In[12]:= Plot@ans4, 8x, - 2, 1<D

Out[12]=
-2.0 -1.5 -1.0 -0.5 0.5 1.0

-1

-2

2) d^2y/dx^2 + dy/dx - 6y = 0
In[13]:= sol5 = DSolve@y ''@xD + y '@xD - 6 y@xD == 0, y@xD, xD

Out[13]= 99y@xD ® ã-3 x C@1D + ã2 x C@2D==


In[14]:= ans5 = Evaluate@y@xD . sol5@@1DD . 8C@1D ® 1, C@2D ® 2<D

Out[14]= ã-3 x + 2 ã2 x
PRACTICAL-2 .nb 3

In[15]:= Plot@ans5, 8x, - 2, 1<D


200

150

Out[15]= 100

50

-2.0 -1.5 -1.0 -0.5 0.5 1.0

3) d^2y/dx^2 + dy/dx - 6y = 0
In[16]:= sol6 = DSolve@y ''@xD + y '@xD - 6 y@xD == 0, y@xD, xD

Out[16]= 99y@xD ® ã-3 x C@1D + ã2 x C@2D==


In[17]:= ans6 = Evaluate@y@xD . sol6@@1DD . 8C@1D ® 1, C@2D ® 2<D

Out[17]= ã-3 x + 2 ã2 x
In[18]:= Plot@ans6, 8x, - 2, 1<D
200

150

Out[18]= 100

50

-2.0 -1.5 -1.0 -0.5 0.5 1.0

PLOTTING SOLUTIONS OF THIRD ORDER DIFFERENTIAL EQUATIONS :-


1) d^3y/dx^3 + d^2y/dx^2 - x - Exp[-x] = 0
In[19]:= sol7 = DSolve@y '''@xD + y ''@xD - x - Exp@- xD == 0, y@xD, xD

::y@xD ® - - ã-x H- 2 - x - C@1DL + C@2D + x C@3D>>


x2 x3
Out[19]= +
2 6
In[20]:= ans7 = Evaluate@y@xD . sol7@@1DD . 8C@1D ® 81, 2, 3<, C@2D ® 82, 5, 6<, C@3D ® 88, 3, 5<<D

:2 - ã-x H- 3 - xL + 8 x - , 5 - ã-x H- 4 - xL + 3 x - , 6 - ã-x H- 5 - xL + 5 x - >


x2 x3 x2 x3 x2 x3
Out[20]= + + +
2 6 2 6 2 6
4 PRACTICAL-2 .nb

In[21]:= Plot@ans7, 8x, - 5, 1<, PlotStyle ® 8Thick, Thin, Dashed<D

20

-5 -4 -3 -2 -1 1

-20

Out[21]=
-40

-60

-80

2) d^3y/dx^3 - 5dy/dx-3x +x1 = 0


In[22]:= sol8 = DSolve@y '''@xD - 5 y '@xD - 3 x + 1 == 0, y@xD, xD

::y@xD ®
x 3 x2 ã 5 x C@1D ã- 5 x C@2D
Out[22]= - + - + C@3D>>
5 10 5 5
In[23]:= ans8 = Evaluate@y@xD . sol8@@1DD . 8C@1D ® 81, 2, 3<, C@2D ® 82, 5, 6<, C@3D ® 88, 3, 5<<D

:8 -
2 ã- 5 x ã 5 x x 3 x2
Out[23]= + + - ,
5 5 5 10

>
2ã 5 x x 3 x2 6 ã- 5 x 3ã 5 x x 3 x2
3- 5 ã- 5 x
+ + - , 5- + + -
5 5 10 5 5 5 10
In[24]:= Plot@ans8, 8x, - 1, 1<D

15

10

Out[24]= -1.0 -0.5 0.5 1.0

-5

-10

-15

-20

3) 3d^3y/dx^3 -y = 0
In[25]:= sol9 = DSolve@3 y '''@xD - y@xD == 0, y@xD, xD

::y@xD ® ã 31‘3 C@3D + ã


x
-
x
1 -
x
1
Out[25]= 2 ´ 31‘3 C@1D CosB 316 xF + ã 2 ´ 31‘3 C@2D SinB 316 xF>>
2 2
PRACTICAL-2 .nb 5

In[26]:= ans9 = Evaluate@y@xD . sol9@@1DD . 8C@1D ® 81, 2, 3<, C@2D ® 82, 5, 6<, C@3D ® 88, 3, 5<<D

:8 ã 31‘3 + ã
x
-
x
1 -
x
1
Out[26]= 2 ´ 31‘3 CosB 316 xF + 2 ã 2 ´ 31‘3 SinB 316 xF,
2 2
x
-
x
1 -
x
1
3 ã 31‘3 + 2 ã 2 ´ 31‘3 CosB 316 xF + 5 ã 2 ´ 31‘3 SinB 316 xF,
2 2
x
-
x
1 -
x
1
5 ã 31‘3 + 3 ã 2 ´ 31‘3 CosB 316 xF + 6 ã 2 ´ 31‘3 SinB 316 xF>
2 2
In[27]:= Plot@ans9, 8x, 1, 5<D

250

200

150

Out[27]=

100

50

2 3 4 5
PRACTICAL - 3
SOLUTION OF DIFFERENTIAL EQUATION USING
VARIATION OF PARAMETERS METHHOD

QUES 1 - SOLVE THE DIFFERENTIAL EQUATION


x^2y'' - 2xy' + 2y = x^3
BY VARIATION OF PARAMETER.
SOLUTION --
In[1]:= yc = DSolve@Hx ^ 2L * y ''@xD - 2 x * y '@xD + 2 y@xD == 0, y@xD, xD
Out[1]= 99y@xD ® x C@1D + x2 C@2D==

In[2]:= a@xD = x ^ 2
r@xD = x ^ 3
Out[2]= x2

Out[3]= x3

In[4]:= y1@x_D = x
Out[4]= x

In[5]:= y2@x_D = x ^ 2
Out[5]= x2

In[6]:= A = 88y1@xD, y2@xD<, 8y1 '@xD, y2 '@xD<<


Out[6]= 99x, x2 =, 81, 2 x<=

In[7]:= W = Det@AD
Out[7]= x2

In[8]:= w = Wronskian@8y1@xD, y2@xD<, xD


Out[8]= x2

In[9]:= u@xD = Integrate@- Hy2@xD * r@xDL  Ha@xD * wL, xD


v@xD = Integrate@Hy1@xD * r@xDL  Ha@xD * wL, xD
x2
Out[9]= -
2
Out[10]= x

In[11]:= sol2 = u@xD * y1@xD + v@xD * y2@xD


x3
Out[11]=
2
2 PRACTICAL-3.nb

In[12]:= ans = yc + sol2

:: + Iy@xD ® x C@1D + x2 C@2DM>>


x3
Out[12]=
2

QUES 2- SOLVE THE DIFFERENTIL EQUATION BY VARIATION OF


PARAMETER
y'' + y = Tan x
SOLUTION--
In[13]:= cf = DSolve@y ''@xD + y '@xD == 0, y@xD, xD
Out[13]= 88y@xD ® - ã-x C@1D + C@2D<<

In[14]:= a@xD = 1
Out[14]= 1

In[15]:= r@xD = Tan x


Out[15]= Tan x

In[16]:= y1@x_D = - Exp@- xD


Out[16]= - ã-x

In[17]:= y2@x_D = 1
Out[17]= 1

In[18]:= A = 88y1@xD, y2@xD<, 8y1 '@xD, y2 '@xD<<


Out[18]= 88- ã-x , 1<, 8ã-x , 0<<

In[19]:= W = Det@AD
Out[19]= - ã-x

In[20]:= u@xD = Integrate@- Hy2@xD * r@xDL  Ha@xD * WL, xD


v@xD = Integrate@Hy1@xD * r@xDL  Ha@xD * WL, xD
Out[20]= ãx Tan H- 1 + xL

Tan x2
Out[21]=
2

In[22]:= sol2 = u@xD * y1@xD + v@xD * y2@xD

- Tan H- 1 + xL +
Tan x2
Out[22]=
2

In[23]:= ans = cf + sol2

::- Tan H- 1 + xL + + Hy@xD ® - ã-x C@1D + C@2DL>>


Tan x2
Out[23]=
2
GROWTH AND DECAY MODEL
(EXPONENTIAL CASE ONLY )...
 Growth Model :-
It is based on the concept that as the size of population increases, growth rate also
increases. It is not affected by environmental limitations. In mathematical term,
growth model can be formulated as
x(t) = Population at any time t.
dx/dt = rate of change with respect to t.
dx/dt = kx, where k is positive constant.
x = xo Exp[kt]

Q 1 :- Suppose that the population of a certain country growth at an annual rate is given below if the
current population is 3 million ,what will be the population in 10 yrs ? Also plot the graph of the solu-
tion .
(a)2% annual rate
(b)5% annual rate
(c)100% annual rate
(a)2% annual rate.

In[1]:= Sol = DSolvex '[t] ⩵ k x[t], x[t], t

Out[1]= x[t] → ⅇk t 1

In[2]:= Sol1 = Evaluate[x[t] /. Sol〚1〛 /. {k → 0.02, C[1] → 3}]

Out[2]= 3 ⅇ0.02 t

In[5]:= Plot[Sol1, {t, 0, 100}, PlotStyle → {Green, Thick}, AxesLabel → {t, x[t]}]
x(t)

20

15
Out[5]=

10

t
20 40 60 80 100
2

In[4]:= x[10] = Evaluate[Sol1 /. {t → 10}]


Out[4]= 3.66421

(b) 5% annual rate.


In[6]:= Sol2 = Evaluate[x[t] /. Sol〚1〛 /. {k → 0.05, C[1] → 3}]

Out[6]= 3 ⅇ0.05 t

In[7]:= Plot[Sol2, {t, 0, 100}, PlotStyle → {Orange, Thick}, AxesLabel → {t, x[t]}]
x(t)

400

300

Out[7]=

200

100

t
20 40 60 80 100

In[8]:= x[10] = Evaluate[Sol2 /. {t → 10}]


Out[8]= 4.94616

(c) 100% annual rate.


In[10]:= Sol3 = Evaluate[x[t] /. Sol〚1〛 /. {k → 1, C[1] → 3}]
Out[10]=

3 ⅇt

In[12]:= Plot[Sol3, {t, 0, 10}, PlotStyle → {Blue, Thick}, AxesLabel → {t, x[t]}]
Out[12]=
x(t)

25 000

20 000

15 000

10 000

5000

t
2 4 6 8 10
3

In[13]:= x[10] = Evaluate[Sol3 /. {t → 10}]


Out[13]=

3 ⅇ10

Q 2 :- In the same country as in Ques 1, how long will it take the population to reach 5 million.
Solution :- Here xo=3=C[1], k=2%, x(t) =5 for same time t.

In[15]:= Sol = DSolvex 't ⩵ k xt, xt, t


Out[15]=

x[t] → ⅇk t 1

In[20]:= Sol1 = Evaluate[x[t] /. Sol[[1]] /. {k → 0.02, C[1] → 3}]


Out[20]=

3 ⅇ0.02 t

In[22]:= PlotSol1, t, 0, 50, PlotStyle → Red, Thick, AxesLabel → t, x[t]
Out[22]=
x(t)

t
10 20 30 40 50

Q 3 :- Suppose that the size of a bacteria culture is given by the function P(t) =100 e^(0.15)t, where the
size P(t) is measured in grams and time t is measured in hours. How long will it take for the culture to
double in size?
Solution :- Here Po=100, k-15% and t=?
We can use the differential equation P'(t)=k P(t).

In[24]:= Sol = DSolveP '[t] ⩵ k P[t], P[t], t


Out[24]=

P[t] → ⅇk t 1

In[26]:= Sol1 = Evaluate[P[t] /. Sol〚1〛 /. {k → 0.15, C[1] → 100}]


Out[26]=

100 ⅇ0.15 t
4

In[30]:= PlotSol1, t, - 50, 50, PlotStyle → Peach, Thick, AxesLabel → t, x[t]
Out[30]=
x(t)

30 000

25 000

20 000

15 000

10 000

5000

t
-40 -20 20 40

 Decay Model:-
The disintegration of radioactive material into small particle is a continuous process.
The model based on this process is known as Decay model. This process continues
without any fluctuations in time and mass of the element. In Decay model, rate of
change of radioactive material at time t is proportional to the rate of amount of
radioactive material decayed.
x(t) = Number of radioactive particles at any time t.
dx/dt = rate of change with respect to t.

Q 1 :- Suppose that a certain radioactive element has an annual decay rate of 10%. Starting with a 200
gram sample of the element, how many grams will be left in 3 years?
Solution:- Here k = 10% , x(0) = 200 , t = 3, x(t) = ?

In[31]:= Sol = DSolve x 't ⩵ - k xt, xt, t


Out[31]=

x[t] → ⅇ-k t 1

In[32]:= Sol1 = Evaluatex[t] /. Sol〚1〛 /. k → 0.1 , C[1] → 200 


Out[32]=

200 ⅇ-0.1 t
5

In[41]:= PlotSol1, t, 0, 50, PlotStyle → Pink, Thick,

PlotLabel → "Decay Model" , AxesLabel → t, x[t]


Out[41]=

Decay Model
x(t)

200

150

100

50

t
10 20 30 40 50

In[46]:= x[3] = Evaluate[Sol1 /. {t → 3}]


Out[46]=

148.164

Observation :- Hence, 148.164 grams of radioactive element will be left after 3 years.
Q 2 :- Using the same element as in Ques 1, if a particular sample of the element decays to 50 grams
after 5 years, how big was the original sample?
Solution :- Here k = 10%, x(t) =50, t=5,x(0)=?

In[47]:= Sol = DSolvex 't ⩵ - k xt, xt, t


Out[47]=

x[t] → ⅇ-k t 1

Here, value of constant C[1] = xo at time t = 0, which gives x(t) = xo e^(-kt)

In[51]:= Sol1 = Evaluatex[t] /. Sol〚1〛 /. {k → 0.01, C[1] → xo, t → 5}


Out[51]=

0.951229 xo

Att=5,x(t)=50, therefore, x(t) =50 e^(0.5)

In[52]:= Sol2 = Solve[Sol1 ⩵ 50, xo]


Out[52]=

{{xo → 52.5636}}

In[53]:= Sol3 = xo /. Sol2〚1〛


Out[53]=

52.5636
6

In[56]:= Sol4 = x[t] /. Sol〚1〛 /. C[1] → Sol3, k → 0.1


Out[56]=

52.5636 ⅇ-0.1 t

In[58]:= Plot Sol4, t, 0, 50, PlotStyle → Red, Thickness[0.0], PlotLabel → "Decay Model"
Out[58]=

Decay Model

50

40

30

20

10

10 20 30 40 50

Observation:- The original sample was 82.4361 grams.


Practical 5.1: Lake Pollution Model
DSolve@y '@xD == F  V * cin - F  V * y@xD, y@xD, xD

::y@xD ® cin + ã-
Fx
V C@1D>>

sol = DSolve@8y '@xD == F  V * cin - F  V * y@xD, y@0D Š c0<, y@xD, xD

::y@xD ® ã- Jc0 - cin + cin ã N>>


Fx Fx
V V

Limit@sol@@1, 1, 2DD, x ® InfinityD

Jc0 - cin + cin ã N, x ® ¥F


Fx Fx
LimitBã- V V

Jc0 - cin + cin ã N, x ® ¥FF


Fx Fx
FullSimplifyBLimitBã- V V

LimitBcin + Hc0 - cinL ã-


Fx
V , x ® ¥F

ClearAll@cin, V, F, c0D;
cin = 3; V = 28;
F = 4 * 12;
sol = DSolve@8y '@xD == F  V * cin - F  V * y@xD, y@0D Š c0<, y@xD, xD
Plot@Evaluate@y@xD . sol . c0 ® Range@1, 5DD, 8x, 0, 5<, PlotRange ® FullD
99y@xD ® ã-12 x7 I- 3 + c0 + 3 ã12 x7 M==

1 2 3 4 5
2 P5.1 Lake Pollution Model.nb

ClearAll@cin, V, F, c0, F0D;


cin = 3; V = 28; F0 = 4 * 12; Ε = 0.5;
F@xD = F0 * H1 + Ε Sin@2 Π xDL;
sol = DSolve@8y '@xD == F@xD  V * cin - F@xD  V * y@xD, y@0D Š c0<, y@xD, xD
Plot@Evaluate@y@xD . sol . c0 ® Range@1, 5DD, 8x, 0, 5<, PlotRange ® FullD
99y@xD ® 0.872477 ã-1.71429 x
I3.43848 ã1.71429 x - 3. ã0.136419 [email protected] xD + 1. c0 ã0.136419 [email protected] xD M==

1 2 3 4 5

ClearAll@cin, V, F, c0D;
V = 28; F = 4 * 12;
cin@x_D = H10 + 10 Sin@2 Π xDL;
sol = DSolve@8y '@xD == F  V * cin@xD - F  V * y@xD, y@0D Š c0<, y@xD, xD
Plot@Evaluate@y@xD . sol . c0 ® Range@1, 5DD, 8x, 0, 5<, PlotRange ® FullD

::y@xD ®

ã-12 x7 I- 360 + 36 c0 + 360 ã12 x7 + 420 Π - 490 Π2 + 49 c0 Π2 + 490 ã12 x7 Π2 -
1
36 + 49 Π2
420 ã12 x7 Π Cos@2 Π xD + 360 ã12 x7 Sin@2 Π xDM>>

12

10

1 2 3 4 5
P5.1 Lake Pollution Model.nb 3

ClearAll@cin, V, F, c0, F0D;


V = 28; F0 = 4 * 12; Ε = 0.5;
cin@x_D = H10 + 10 Sin@2 Π xDL;
F@x_D = F0 * H1 + Ε Sin@2 Π xDL;
sol = DSolve@8y '@xD == F@xD  V * cin@xD - F@xD  V * y@xD, y@0D Š c0<, y@xD, xD
Plot@Evaluate@y@xD . sol . c0 ® Range@1, 5DD, 8x, 0, 5<, PlotRange ® FullD

SystemExceptionBMemoryAllocationFailure,

:sol = DSolveB:y¢ @xD Š


F@xD cin@xD F@xD y@xD
V
- V
, y@0D Š c0>, y@xD, xF, DSolveB

:y¢ @xD Š H1 + 0.5 Sin@2 Π xDL H10 + 10 Sin@2 Π xDL - H1 + 0.5 Sin@2 Π xDL y@xD,
12 12
7 7

y@0D Š c0>, y@xD, xF, †133‡, 983 403 688 !>F

1.0

0.5

1 2 3 4 5

-0.5

-1.0
DENSITY DEPENDENT
GROWTH MODEL
In[1]:=

LIMITED GROWTH OF POPULATION (WITHOUT HARVESTING) :-

In[1]:= r  1;
k  1000;
eqn  x 't  r xt 1  xt  k
sol  DSolveeqn, x0  1, xt, t

x t  1 
xt
Out[3]= xt
1000

Solve::ifun : Inverse functions are being used by Solve, so


some solutions may not be found; use Reduce for complete solution information. 

xt  
1000 t
Out[4]=
999  t

Plotxt . sol, t, 0, 10,


PlotStyle  Red, Thickness0.01, PlotRange  All, AxesLabel  t, xt
In[5]:=

xt

800

600
Out[5]=

400

200

t
2 4 6 8 10

LIMITED GROWTH OF POPULATION (WITH HARVESTING) :-


2 PRACTICAL-6 DENSITY-DEPENDENT GROWTH.nb

In[6]:= r  1;
k  10;
h  9  10;
x 't  1  10  9  10 xt  xt ^ 2
Eqn  x 't   r  k  xt ^ 2  k xt  kh  r
Sol  DSolveEqn, x0  2, xt, t
Plotxt . Sol, t, 0, 8,
PlotStyle  Red, Thickness0.01, PlotRange  All, AxesLabel  t, xt

x t   9  10 xt  xt2 


1
Out[9]=
10

x t   kh  10 xt  xt2 


1
Out[10]=
10

Solve::ifun : Inverse functions are being used by Solve, so


some solutions may not be found; use Reduce for complete solution information. 

xt  5   ,
1  25  kh
Out[11]=  25  kh Tan   25  kh t  10 ArcCos
10  16  kh

xt  5   ,
1  25  kh
 25  kh Tan   25  kh t  10 ArcCos
10  16  kh

xt  5   ,
1  25  kh
 25  kh Tan   25  kh t  10 ArcCos
10  16  kh

xt  5   
1  25  kh
 25  kh Tan   25  kh t  10 ArcCos
10  16  kh
xt
1.0

0.5

Out[12]=
t
1.0 0.5 0.5 1.0

0.5

1.0
Practical 6.b Epidemic model of influenza -- Basic epidemic model
In[1]:=   2.18  10 ^  3;
  0.44;
s0  762;
I0  1;
sol  NDSolvey 'x    yx zx, z 'x   yx zx   zx, w 'x   zx,
y0  s0, z0  I0, w0  0, yx, zx, wx, x, 0, 25;
PlotEvaluateyx, zx, wx . sol, x, 0, 25, PlotStyle  Automatic

700

600

500

400
Out[6]=

300

200

100

5 10 15 20 25

Practical 6.b Epidemic model of influenza -- Contagious for life


In[7]:=   0.002;
s0  500;
I0  1;
sol  NDSolvey 'x    yx zx, z 'x   yx zx, y0  s0, z0  I0,
yx, zx, x, 0, 25;
PlotEvaluateyx, zx . sol, x, 0, 25, PlotStyle  Automatic
500

400

300

Out[11]=

200

100

5 10 15 20 25
2 P6.2 influenza model.nb

Practical 6.b Epidemic model of influenza -- Disease with Carriers


ClearAll, , , s, s0, c0, c, i, r, x;
  2.18  10 ^  3;
In[12]:=

  0.44;
q  0.4;
s0  762;
c0  1;
  0.5;
sol  NDSolves 'x    sx ix    sx cx,
i 'x   sx ix    sx cx   ix, c 'x  q  ix,
r 'x  1  q  ix, s0  s0, c0  c0, i0  0, r0  0,
sx, ix, cx, rx, x, 0, 25;
PlotEvaluatesx, ix, cx, rx . sol, x, 0, 30, PlotStyle  Automatic

700

600

500

400
Out[20]=

300

200

100

5 10 15 20 25 30

In[21]:=
Practical 6.3: Basic Battle Model
In[22]:= a1  0.0544;
a2  0.0106;
r0  66 454;
b0  18 274;
sol  NDSolveR 't   a1 Bt, B 't   a2 Rt, R0  r0, B0  b0,
Rt, Bt, t, 0, 30;
PlotEvaluateRt, Bt . sol, t, 0, 30, PlotStyle  Automatic

60 000

50 000

40 000

Out[27]=
30 000

20 000

10 000

5 10 15 20 25 30

Practical 6.3: Jungle Warfare


ClearAlla1, a2, r0, b0, sol, R, B, t;
a1  4  10 ^  4;
In[28]:=

a2  4;
r0  500;
b0  150;
sol  NDSolveR 't   a2 Bt, B 't   a1 Rt Bt, R0  r0, B0  b0,
Rt, Bt, t, 0, 30;
PlotEvaluateRt, Bt . sol, t, 0, 5, PlotStyle  Automatic,
RegionFunction  Functionx, y, y  0

NDSolve::ndsz : At t  5.619082778061862`, step size is effectively zero; singularity or stiff system suspected. 

1000

800

600

400
Out[34]=

200

1 2 3 4 5

200

400

In[35]:=
2 P6.3 battle model.nb

Practical 6.3: Long Range Weapons


In[36]:= ClearAlla1, a2, r0, b0, sol, R, B, t;
a1  0.004;
a2  0.05;
r0  100;
b0  50;
sol  NDSolveR 't   a2 Bt Rt,
B 't   a1 Rt Bt, R0  r0, B0  b0, Rt, Bt, t, 0, 30;
PlotEvaluateRt, Bt . sol, t, 0, 1, PlotStyle  Automatic,
RegionFunction  Functionx, y, y  0,
AxesLabel  t, Army, PlotLegends  "Red Army", "Blue Army"
Army
100

80

60
Red Army
Out[42]=
Blue Army

40

20

t
0.2 0.4 0.6 0.8 1.0
QUESTION 1 -- Plot the solution of the predator-prey model with b1=1, a2=
0.5, c1= 0.01, c2= 0.005, x(0) = 200 and y(0) = 80.
SOLUTION --
2 PRACTICAL-7.nb

In[1]:=

Out[1]=

In[2]:=

QUESTION 2 -: Plot the solution of the predator-prey model with b1=1, a2=
0.5, c1= 0.01, c2= 0.005, p1 = 0.1, p2 = 0.1, x(0) = 200 and y(0) = 80.
SOLUTION --
In[3]:= ClearAll[]
PRACTICAL-7.nb 3

In[4]:=

Out[4]=

QUESTION 3--Plot the solution of the predator-prey model with b1=1, a2=
0.5, c1= 0.01, c2= 0.005, k = 1000, x(0) = 80 and y(0) = 100.
SOLUTION --
In[5]:=
4 PRACTICAL-7.nb

In[6]:=

Out[6]=

QUESTION 4- Generate time dependent graph of the population over time


with b1 =
1.0, b2= 1.0, b3= 0.5, c1 = 0.01, c2 = 0.005, d1= 0.01 and d2= 0.001. Initialize
with
[x(0), y(0), z(0)] = [200, 180, 100].
PRACTICAL-7.nb 5

with
[x(0), y(0), z(0)] = [200, 180, 100].
SOLUTION --

In[7]:=

Out[7]=
An Epidemic Model Of Influenza

AN EPIDEMIC MODEL FOR INFLUENZA


y(x)=number of susceptible at time x,
z(x)=number of infectives at time x,
=trasmission coefficient or infection rate,
=recovery rate(per capita)

PROBLEM:(page-101)
In[43]:=   2.18  10 ^  3
  0.44
u  y 'x   yx zx
v  z 'x   yx zx   zx
s  NDSolveu, v, y0  762, z0  1, y, z, x, 0, 25
PlotEvaluateyx, zx . s, x, 0, 25
Out[43]= 0.00218

Out[44]= 0.44

Out[45]= y x   0.00218 yx zx

Out[46]= z x   0.44 zx  0.00218 yx zx

Out[47]= y  InterpolatingFunction0., 25., ,


z  InterpolatingFunction0., 25., 

700

600

500

400
Out[48]=

300

200

100

5 10 15 20 25

PROBLEM:BASIC SIR EPIDEMIC MODEL


[5.1(a),page-128][use b=0.002,r=0.4,z(0)=1,y(0)=500]
[5.1(c),page-128][use s(0)=100]
[5.1(d),page-128][use b=0.004]
2 epidemic model of influenza.nb

In[49]:= ClearAll, 
  0.002
  0.4
u  y 'x   yx zx
v  z 'x   yx zx   zx
s  NDSolveu, v, y0  500, z0  1, y, z, x, 0, 25
y24, z24 . s
PlotEvaluateyx, zx . s, x, 0, 25
Out[50]= 0.002

Out[51]= 0.4

Out[52]= y x   0.002 yx zx

Out[53]= z x   0.4 zx  0.002 yx zx

Out[54]= y  InterpolatingFunction0., 25., ,


z  InterpolatingFunction0., 25., 

Out[55]= 55.6182, 6.16239

500

400

300

Out[56]=

200

100

5 10 15 20 25

PROBLEM: SI MODEL CONTAGIOUS FOR LIFE


(A DISEASE WHERE ALL THOSE INFECTED REMAIN CONTAGIOUS FOR LIFE)
We ignore births and deaths.
[5.2(b),page-128][use =0.002,S(0)=500,I(0)=1]
epidemic model of influenza.nb 3

In[57]:= ClearAll
  0.002
u  y 'x   yx zx
v  z 'x   yx zx
s  NDSolveu, v, y0  500, z0  1, y, z, x, 0, 25
y24, z24 . s
PlotEvaluateyx, zx . s, x, 0, 25
Out[58]= 0.002

Out[59]= y x   0.002 yx zx

Out[60]= z x  0.002 yx zx

Out[61]= y  InterpolatingFunction0., 25., ,


z  InterpolatingFunction0., 25., 

Out[62]= 9.01355  106 , 501.

500

400

300

Out[63]=

200

100

5 10 15 20 25

PROBLEM: SI MODEL (DISEASE WITH NO IMMUNITY)


(A DISEASE WHERE ALL THOSE INFECTED BECOME SUCEPTIBLE AGAIN UPON RECOVER-
ING FROM THE DISEASE)
We ignore births and deaths.
[5.3,page-128][use =0.002,y(0)=500,z(0)=1]
4 epidemic model of influenza.nb

In[64]:= ClearAll, 
  0.002
  0.55
u  y 'x   zx   yx zx
v  z 'x   yx zx   zx
s  NDSolveu, v, y0  500, z0  1, y, z, x, 0, 50
y24, z24 . s
PlotEvaluateyx, zx . s, x, 0, 50
Out[65]= 0.002

Out[66]= 0.55

Out[67]= y x  0.55 zx  0.002 yx zx

Out[68]= z x   0.55 zx  0.002 yx zx

Out[69]= y  InterpolatingFunction0., 50., ,


z  InterpolatingFunction0., 50., 

Out[70]= 275.984, 225.016

400

350

300

Out[71]= 250

200

150

10 20 30 40 50

PROBLEM: SEIR MODEL (DISEASE WITH A LATENT PERIOD)


(Many diseases have a latent period,which is a period of time between infection and when an
infected individual become infactious.)
We extend the basic epidemic model to one with an additional population class
E(t),corresponding to individual who have been exposed to the disease,so they
are no longer susceptibles,but are not infectious.)
We ignore births and deaths.
[5.5,page-129][use =0.002,S(0)=500,I(0)=1,E(0)=10]
epidemic model of influenza.nb 5

In[72]:= ClearAll, , 
  0.002
  0.4
  0.2
u  y 'x   yx zx
v  w 'x   yx zx   wx
p  z 'x   wx   zx
s  NDSolveu, v, p, y0  500, w0  10, z0  1, y, w, z, x, 0, 50
y24, z24 . s
PlotEvaluateyx, wx, zx . s, x, 0, 50
Out[73]= 0.002

Out[74]= 0.4

Out[75]= 0.2

Out[76]= y x   0.002 yx zx

Out[77]= w x   0.2 wx  0.002 yx zx

Out[78]= z x  0.2 wx  0.4 zx

Out[79]= y  InterpolatingFunction0., 50., ,


w  InterpolatingFunction0., 50., ,
z  InterpolatingFunction0., 50., 

Out[80]= 210.063, 40.8862

500

400

300

Out[81]=

200

100

10 20 30 40 50

PROBLEM: Continuous Vaccination


The susceptibles are continuously vaccinated againt the disease at a rate proportional to their
number.
v = vaccination rate
Problem :(5.4)(page - 129)
6 epidemic model of influenza.nb

In[82]:=   2.18  10 ^  3
  0.44
v4
u  y 'x   yx zx  v yx
v  z 'x   yx zx   zx
s  NDSolveu, v, y0  762, z0  1, y, z, x, 0, 25
y1, z4 . s
PlotEvaluateyx, zx . s, x, 0, 10
Out[82]= 0.00218

Out[83]= 0.44

Out[84]= 4

Out[85]= y x   4 yx  0.00218 yx zx

Out[86]= z x   0.44 zx  0.00218 yx zx

Out[87]= y  InterpolatingFunction0., 25., ,


z  InterpolatingFunction0., 25., 

Out[88]= 13.9231, 0.26055

1.5

1.0

Out[89]=

0.5

2 4 6 8 10

PROBLEM: Cycles of measles epidemic


For the spread of measles it is thought that the effect of births, continuously refreshing the number
of susceptibls, is an important contrbuting factor towards the periodic outbreak of the disease.
Assuming a constant per capita birth rate for susceptibles, and also that all those infected become
immune.
b = per capita birth rate
Problem(5.15)(page - 131)
epidemic model of influenza.nb 7

ClearAll, , b
  2.18  10 ^  3
In[90]:=

  0.44
b  0.5
u  y 'x  b yx   yx zx
v  z 'x   yx zx   zx
s  NDSolveu, v, y0  762, z0  1, y, z, x, 0, 25
y14, z14 . s
PlotEvaluateyx, zx . s, x, 0, 15
Out[91]= 0.00218

Out[92]= 0.44

Out[93]= 0.5

Out[94]= y x  0.5 yx  0.00218 yx zx

Out[95]= z x   0.44 zx  0.00218 yx zx

Out[96]= y  InterpolatingFunction0., 25., ,


z  InterpolatingFunction0., 25., 

Out[97]= 0.633732, 20.1889

2000

1500

Out[98]= 1000

500

2 4 6 8 10 12 14

PROBLEM:Density dependent contact rate


In case of fatal disease,we need to modify the basic epidemic model to include density dependent
disease transmission.
Problem:(5.16)(page - 131)

ClearAll, , b
  2.18  10 ^  3
In[99]:=

  0.44
k  1000
pcm  1.62
  0.5
A  pcm
u  y 'x   pcm yx  zx  yx  zx k 1     yx  zx yx zx;
v  z 'x 
pcm yx  zx  yx  zx k 1     y x  z x  yx zx   zx;
s  NDSolveu, v, y0  762, z0  1, y, z, x, 0, 25;
y14, z14 . s
PlotEvaluateyx, zx . s, x, 0, 15;
8 epidemic model of influenza.nb

Out[100]= 0.00218

Out[101]= 0.44

Out[102]= 1000

Out[103]= 1.62

Out[104]= 0.5

Out[105]= 1.62

NDSolve::dvnoarg : The function y appears with no arguments. 

ReplaceAll::reps : NDSolvey x  1.62 yx zx 500.  0.5 Plus2, z x  0.44 zx  1.62 500.
 Times2 yx zx, y0  762, z0  1, y, z, x, 0, 25 is
neither a list of replacement rules nor a valid dispatch table, and so cannot be used for replacing. 

y14, z14 . NDSolvey x   1.62 yx zx 500.  0.5 yx  zx,
z x   0.44 zx  1.62 500.  0.5 x y  x z yx zx,
Out[109]=

y0  762, z0  1, y, z, x, 0, 25

ReplaceAll::reps : NDSolvey x  1.62 yx zx 500.  0.5 Plus2, z x  0.44 zx  1.62 500.
 Times2 yx zx, y0  762, z0  1, y, z, x, 0, 25 is
neither a list of replacement rules nor a valid dispatch table, and so cannot be used for replacing. 

NDSolve::dsvar : 0.0003064285714285714` cannot be used as a variable. 

ReplaceAll::reps : NDSolvey 0.000306429  1.62 y0.000306429 z0.000306429 500.


 0.5 Plus2, z 0.000306429  0.44 z0.000306429  1.62 500.
 Times2 y0.000306429 z0.000306429, y0  762, z0  1, y, z, 22, 0, 25
is neither a list of replacement rules nor a valid dispatch
table,
and
so
cannot
be
used
for
replacing.

NDSolve::dsvar : 0.0003064285714285714` cannot be used as a variable. 

ReplaceAll::reps : NDSolvey 0.000306429  1.62 y0.000306429 z0.000306429 500.


 0.5 Plus2, z 0.000306429  0.44 z0.000306429  1.62 500.
 Times2 y0.000306429 z0.000306429, y0.  762., z0.  1., 1, 1
is neither a list of replacement rules nor a valid dispatch
table,
and
so
cannot
be
used
for
replacing.

General::stop : Further output of ReplaceAll::reps will be suppressed during this calculation. 


epidemic model of influenza.nb 9

NDSolve::dsvar : 0.30642887755102044` cannot be used as a variable. 

General::stop : Further output of NDSolve::dsvar will be suppressed during this calculation. 

PROBLEM :Disease with Carriers


Develop a model for an infectious disease where there is immunity for only some of those who
recover
,others recover to become permanent carriers,who can still cause infection.A carrier can infect
others at a reduced rate compared to infectious individuals but shows no symptoms.
Problem (5.24)(page - 133)

ClearAll, , , s, s0, c0, c, i, r, x;


  2.18  10 ^  3;
In[111]:=

  0.44;
q  0.4;
s0  762;
c0  1;
  0.5;
l  s 'x    sx ix    sx cx
m  i 'x   sx ix    sx cx   ix
n  c 'x  q  ix
o  r 'x  1  q  ix
sol  NDSolve
l, m, n, o, s0  s0, c0  c0, i0  0, r0  0, s, i, c, r, x, 0, 25;
PlotEvaluatesx, ix, cx, rx . sol, x, 0, 30, PlotStyle  Automatic
Out[118]= s x   0.00109 cx sx  0.00218 ix sx

Out[119]= i x   0.44 ix  0.00109 cx sx  0.00218 ix sx

Out[120]= c x  0.176 ix

Out[121]= r x  0.264 ix

700

600

500

400
Out[123]=

300

200

100

5 10 15 20 25 30

You might also like