Practical 1-Merged
Practical 1-Merged
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.
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
d2 y dy
(a) 2 +3 dx
+ y = 0
dx
Out[15]=
d2 y
(b) + 3 y = x.
dx2
2 Practical 1.nb
d2 y dy
(c) 4 2 + 10 dx
+9y = 0
dx
::y@xD ® ã-5 x4 C@2D CosB F + ã-5 x4 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
: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
solA =
Evaluate@y@xD . sol7@@1DD . 8C@1D ® 8-14, 10, -2<, C@2D ® 84, -1, 3<<D
In[22]:=
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.
d3 y
(b) - 27 y = 0 with C1 = 1, 2, 3 and C2 = -4, -19, -2 and C3 = 5, 20, 3.
dx3
::y@xD ® ã3 x C@1D + ã-3 x2 C@2D CosB F + ã-3 x2 C@3D SinB F>>
3 3 x 3 3 x
Out[27]=
2 2
Practical 1.nb 5
ReplaceAll::reps :
8BP1T< is neither a list of replacement rules nor a valid dispatch table, and so cannot be used for replacing.
2.5
2.0
1.5
Out[3]= 1.0
0.5
5 10 15 20
-0.5
Out[5]= :- - 4 + x x, - x -4 + 5 x >
10 20 30 40 50
-200
Out[6]= -400
-600
-800
3) y' - y - 5 = 0
2 PRACTICAL-2 .nb
300
250
200
Out[9]=
150
100
50
1 2 3 4 5
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[14]= ã-3 x + 2 ã2 x
PRACTICAL-2 .nb 3
150
Out[15]= 100
50
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[17]= ã-3 x + 2 ã2 x
In[18]:= Plot@ans6, 8x, - 2, 1<D
200
150
Out[18]= 100
50
20
-5 -4 -3 -2 -1 1
-20
Out[21]=
-40
-60
-80
::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
-5
-10
-15
-20
3) 3d^3y/dx^3 -y = 0
In[25]:= sol9 = DSolve@3 y '''@xD - y@xD == 0, y@xD, xD
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 ã 313 + ã
x
-
x
1 -
x
1
Out[26]= 2 ´ 313 CosB 316 xF + 2 ã 2 ´ 313 SinB 316 xF,
2 2
x
-
x
1 -
x
1
3 ã 313 + 2 ã 2 ´ 313 CosB 316 xF + 5 ã 2 ´ 313 SinB 316 xF,
2 2
x
-
x
1 -
x
1
5 ã 313 + 3 ã 2 ´ 313 CosB 316 xF + 6 ã 2 ´ 313 SinB 316 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
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[7]:= W = Det@AD
Out[7]= x2
In[14]:= a@xD = 1
Out[14]= 1
In[17]:= y2@x_D = 1
Out[17]= 1
In[19]:= W = Det@AD
Out[19]= - ã-x
Tan x2
Out[21]=
2
- Tan H- 1 + xL +
Tan x2
Out[22]=
2
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.
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
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
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
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.
x[t] → ⅇk t 1
3 ⅇ0.02 t
In[22]:= PlotSol1, 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).
P[t] → ⅇk t 1
100 ⅇ0.15 t
4
In[30]:= PlotSol1, 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) = ?
200 ⅇ-0.1 t
5
Decay Model
x(t)
200
150
100
50
t
10 20 30 40 50
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)=?
0.951229 xo
{{xo → 52.5636}}
52.5636
6
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
::y@xD ® cin + ã-
Fx
V C@1D>>
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 x7 I- 3 + c0 + 3 ã12 x7 M==
1 2 3 4 5
2 P5.1 Lake Pollution Model.nb
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 x7 I- 360 + 36 c0 + 360 ã12 x7 + 420 Π - 490 Π2 + 49 c0 Π2 + 490 ã12 x7 Π2 -
1
36 + 49 Π2
420 ã12 x7 Π Cos@2 Π xD + 360 ã12 x7 Sin@2 Π xDM>>
12
10
1 2 3 4 5
P5.1 Lake Pollution Model.nb 3
SystemExceptionBMemoryAllocationFailure,
: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
1.0
0.5
1 2 3 4 5
-0.5
-1.0
DENSITY DEPENDENT
GROWTH MODEL
In[1]:=
In[1]:= r 1;
k 1000;
eqn x 't r xt 1 xt k
sol DSolveeqn, x0 1, xt, t
x t 1
xt
Out[3]= xt
1000
xt
1000 t
Out[4]=
999 t
xt
800
600
Out[5]=
400
200
t
2 4 6 8 10
In[6]:= r 1;
k 10;
h 9 10;
x 't 1 10 9 10 xt xt ^ 2
Eqn x 't r k xt ^ 2 k xt kh r
Sol DSolveEqn, x0 2, xt, t
Plotxt . Sol, t, 0, 8,
PlotStyle Red, Thickness0.01, PlotRange All, AxesLabel t, xt
xt 5 ,
1 25 kh
Out[11]= 25 kh Tan 25 kh t 10 ArcCos
10 16 kh
xt 5 ,
1 25 kh
25 kh Tan 25 kh t 10 ArcCos
10 16 kh
xt 5 ,
1 25 kh
25 kh Tan 25 kh t 10 ArcCos
10 16 kh
xt 5
1 25 kh
25 kh Tan 25 kh t 10 ArcCos
10 16 kh
xt
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 NDSolvey 'x yx zx, z 'x yx zx zx, w 'x zx,
y0 s0, z0 I0, w0 0, yx, zx, wx, x, 0, 25;
PlotEvaluateyx, zx, wx . sol, x, 0, 25, PlotStyle Automatic
700
600
500
400
Out[6]=
300
200
100
5 10 15 20 25
400
300
Out[11]=
200
100
5 10 15 20 25
2 P6.2 influenza model.nb
0.44;
q 0.4;
s0 762;
c0 1;
0.5;
sol NDSolves 'x sx ix sx cx,
i 'x sx ix sx cx ix, c 'x q ix,
r 'x 1 q ix, s0 s0, c0 c0, i0 0, r0 0,
sx, ix, cx, rx, x, 0, 25;
PlotEvaluatesx, ix, cx, rx . 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 NDSolveR 't a1 Bt, B 't a2 Rt, R0 r0, B0 b0,
Rt, Bt, t, 0, 30;
PlotEvaluateRt, Bt . 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
a2 4;
r0 500;
b0 150;
sol NDSolveR 't a2 Bt, B 't a1 Rt Bt, R0 r0, B0 b0,
Rt, Bt, t, 0, 30;
PlotEvaluateRt, Bt . sol, t, 0, 5, PlotStyle Automatic,
RegionFunction Functionx, 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
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]=
with
[x(0), y(0), z(0)] = [200, 180, 100].
SOLUTION --
In[7]:=
Out[7]=
An Epidemic Model Of Influenza
PROBLEM:(page-101)
In[43]:= 2.18 10 ^ 3
0.44
u y 'x yx zx
v z 'x yx zx zx
s NDSolveu, v, y0 762, z0 1, y, z, x, 0, 25
PlotEvaluateyx, zx . s, x, 0, 25
Out[43]= 0.00218
Out[44]= 0.44
700
600
500
400
Out[48]=
300
200
100
5 10 15 20 25
In[49]:= ClearAll,
0.002
0.4
u y 'x yx zx
v z 'x yx zx zx
s NDSolveu, v, y0 500, z0 1, y, z, x, 0, 25
y24, z24 . s
PlotEvaluateyx, zx . s, x, 0, 25
Out[50]= 0.002
Out[51]= 0.4
500
400
300
Out[56]=
200
100
5 10 15 20 25
In[57]:= ClearAll
0.002
u y 'x yx zx
v z 'x yx zx
s NDSolveu, v, y0 500, z0 1, y, z, x, 0, 25
y24, z24 . s
PlotEvaluateyx, zx . s, x, 0, 25
Out[58]= 0.002
500
400
300
Out[63]=
200
100
5 10 15 20 25
In[64]:= ClearAll,
0.002
0.55
u y 'x zx yx zx
v z 'x yx zx zx
s NDSolveu, v, y0 500, z0 1, y, z, x, 0, 50
y24, z24 . s
PlotEvaluateyx, zx . s, x, 0, 50
Out[65]= 0.002
Out[66]= 0.55
400
350
300
Out[71]= 250
200
150
10 20 30 40 50
In[72]:= ClearAll, ,
0.002
0.4
0.2
u y 'x yx zx
v w 'x yx zx wx
p z 'x wx zx
s NDSolveu, v, p, y0 500, w0 10, z0 1, y, w, z, x, 0, 50
y24, z24 . s
PlotEvaluateyx, wx, zx . s, x, 0, 50
Out[73]= 0.002
Out[74]= 0.4
Out[75]= 0.2
500
400
300
Out[81]=
200
100
10 20 30 40 50
In[82]:= 2.18 10 ^ 3
0.44
v4
u y 'x yx zx v yx
v z 'x yx zx zx
s NDSolveu, v, y0 762, z0 1, y, z, x, 0, 25
y1, z4 . s
PlotEvaluateyx, zx . s, x, 0, 10
Out[82]= 0.00218
Out[83]= 0.44
Out[84]= 4
1.5
1.0
Out[89]=
0.5
2 4 6 8 10
ClearAll, , b
2.18 10 ^ 3
In[90]:=
0.44
b 0.5
u y 'x b yx yx zx
v z 'x yx zx zx
s NDSolveu, v, y0 762, z0 1, y, z, x, 0, 25
y14, z14 . s
PlotEvaluateyx, zx . s, x, 0, 15
Out[91]= 0.00218
Out[92]= 0.44
Out[93]= 0.5
2000
1500
Out[98]= 1000
500
2 4 6 8 10 12 14
ClearAll, , b
2.18 10 ^ 3
In[99]:=
0.44
k 1000
pcm 1.62
0.5
A pcm
u y 'x pcm yx zx yx zx k 1 yx zx yx zx;
v z 'x
pcm yx zx yx zx k 1 y x z x yx zx zx;
s NDSolveu, v, y0 762, z0 1, y, z, x, 0, 25;
y14, z14 . s
PlotEvaluateyx, zx . 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
ReplaceAll::reps : NDSolvey x 1.62 yx zx 500. 0.5 Plus2, z x 0.44 zx 1.62 500.
Times2 yx zx, y0 762, z0 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.
y14, z14 . NDSolvey x 1.62 yx zx 500. 0.5 yx zx,
z x 0.44 zx 1.62 500. 0.5 x y x z yx zx,
Out[109]=
ReplaceAll::reps : NDSolvey x 1.62 yx zx 500. 0.5 Plus2, z x 0.44 zx 1.62 500.
Times2 yx zx, y0 762, z0 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.
0.44;
q 0.4;
s0 762;
c0 1;
0.5;
l s 'x sx ix sx cx
m i 'x sx ix sx cx ix
n c 'x q ix
o r 'x 1 q ix
sol NDSolve
l, m, n, o, s0 s0, c0 c0, i0 0, r0 0, s, i, c, r, x, 0, 25;
PlotEvaluatesx, ix, cx, rx . sol, x, 0, 30, PlotStyle Automatic
Out[118]= s x 0.00109 cx sx 0.00218 ix sx
Out[119]= i x 0.44 ix 0.00109 cx sx 0.00218 ix sx
700
600
500
400
Out[123]=
300
200
100
5 10 15 20 25 30