Janmjay Kumar (6037)

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

PRACTICAL

Name – Janmjay Kumar

Roll No. – 6037

Examination Roll No. - 23062563021

Course - B.Sc. (Hons) Mathematics

Sem - 2nd

Subject – Ordinary Differential Equation

Date of Submission - 10/05/2024

Teacher’s Name – Prof. Bhawna Singh &


Prof. Tarun Garg
PRACTICAL 1
PLOTTING FIRST ORDER SOLUTION
FAMILY OF DIFFERENTIAL EQUATIONS

Solving Linear Ordinary Differential Euations


Q .1 Solve dy  dx + y = asin (x)

DSolve[y '[x] + y[x] ⩵ a * Sin[x], y[x], x]

y[x] → ⅇ-x C[1] + 1 a - Cos[x] + Sin[x]


2

Q .2 Solve dy  dx - 3 1 - 4 x ^ 2 = 0

DSolvey '[x] - 3 1 - 4 * x ^ 2 ⩵ 0, y[x], x


y[x] → 3 x - 4 x3 + C[1]

Q .3 Solve dy  dx + y = 0

DSolve[y '[x] + y[x] ⩵ 0, y[x], x]


y[x] → ⅇ-x C[1]

Q .4 Solve dy  dx + 7 y = 0

DSolve[y '[x] + 7 * y[x] ⩵ 0, y[x], x]


y[x] → ⅇ-7 x C[1]

Q .5 Solve 3 dy  dx + 2 y = sinx

DSolve[3 * y '[x] + 2 * y[x] ⩵ Sin[x], y[x], x]

y[x] → ⅇ-2 x/3 C[1] + 1 - 3 Cos[x] + 2 Sin[x]


13

PRACTICAL 2
PLOTTING OF FAMILY OF SOLUTIONS OF DIFFERENCTIAL
EQUATIONS FIRST SECOND AND THIRD ORDER

a) Plotting Solutions Of First Order Differential Equations


Q .1 Solve dy  dx + xy = Cosx ^ 2.
2 Untitled-2.nb

In[6]:= sol = DSolve[y '[x] + x * y[x] ⩵ Cos[x ^ 2], y, x]


Plot[Evaluate[y[x] /. sol /. {C[1] → {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}}],
{x, - 2.5, 2.5}, PlotRange → All]
Out[6]= y → Function{x},

ⅇ- 2 C[1] + 1 ⅇ- 2 1 - ⅈ x + 1 + ⅈ x 
2 2
x x π 1 + 2 ⅈ Erfi 1 - 2 ⅈ Erfi
2 10 2 2

10

Out[7]=

-2 -1 1 2

b) Plotting Solutions Of Second Order Differential Equations


Q .1 Solve d ^ 2 y  dx ^ 2 + (4 x)  x ^ 2 + 1 y = 0

In[8]:= soll = DSolvey ''[x] + (4 * x)  x ^ 2 + 1 * y[x] ⩵ 0, y, x


Out[8]= y → DifferentialRoot
. . .. . .2 .′′ . . .′
Function{y., x
.}, 4 x
.y .] + 1 + x
.[x . y
. [x.] ⩵ 0, y
.[0] ⩵ C[1], y
. [0] ⩵ C[2]

In[12]:= Plot[Evaluate[y[x] /. soll /. {C[1] → {3, 19}, C[2] → {2, 0}}], {x, - 10, 2}, PlotRange → All]
140 000

120 000

100 000

80 000
Out[12]=
60 000

40 000

20 000

-10 -8 -6 -4 -2 2

c) Plotting Solutions Of Third Order Differential Equations


Untitled-2.nb 3

In[19]:= Q .4 Solve d ^ 3 y  dx ^ 3 + 3 d ^ 2 y  dx ^ 2 - 4 y = 0
sol = DSolve[y '''[x] + 3 y ''[x] - 4 y[x] ⩵ 0, y[x], x]
Out[19]= 0

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

3 d2 y 0.4 d3 Q Solve y
Set: Tag Plus in -4 y + + is Protected.
dx2 dx3
3 d2 y 0.4 d3 Q Solve y
Set: Tag Plus in -4 y + + is Protected.
dx2 dx3
Out[13]= 0

In[35]:= y[x] → ⅇ-2 x C[1] + ⅇ-2 x x C[2] + ⅇx C[3]


sol1 = Evaluate[y[x] /. sol[[1]] /. {C[1] → 1, C[2] → 2, C[3] → 3}]
sol2 = Evaluatey[x] /. sol[[1]] /. C[1] → - 1  2, C[2] → 2, C[3] → 5
sol3 = Evaluate[y[x] /. sol[[1]] /. {C[1] → - 1, C[2] → - 4, C[3] → 2}]

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

Out[36]= ⅇ-2 x + 3 ⅇx + 2 ⅇ-2 x x

Out[37]= - 1 ⅇ-2 x + 5 ⅇx + 2 ⅇ-2 x x


2
Out[38]= - ⅇ-2 x + 2 ⅇx - 4 ⅇ-2 x x

In[39]:= Plot[{sol1, sol2, sol3}, {x, - 5, 3}, PlotRange → {- 30, 30},


PlotStyle → {{Pink, Thickness[0.01]}, {Blue, Thick}, {Green, Thickness[0.02]}}]
30

20

10

Out[39]=
-4 -2 2

-10

-20

-30
PRACTICAL 3
VARIATIONS OF PARAMETERS
In[30]:= x2 y ' - 2 xy ' + 2 y = x3 using method of variation of parameters
eqn = x2 * y ''[x] - 2 * x * y '[x];
a[x] = x2 ;
r[x] = x3 ;
sol = DSolve[eqn ⩵ 0, y[x], x];
sol1 = y[x] /. sol[[1]]
Print["The general solution of corresponding homogenous equation is y[x]=", sol1,
"where c1 and c2 are arbitrary constants"]
y1[x] = x;
y2[x] = x2 ;
w = Wronskian[{y1[x], y2[x]}, x];
u[x] = Integrate- y2[x] * r[x]  (a[x] * w), x;
v[x] = Integratey1[x] * r[x]  (a[x] * w), x;
sol2 = u[x] y1[x] + v[x] * y2[x];
Print["The particular integral of non homogenous equation is:", sol2]
Print["The general solution of non homogenous equation is y[x]=", sol1 + sol2]

Out[30]= method of2 parameters using variation x3

Out[35]=
1 x3 C[1] + C[2]
3
The general solution of corresponding homogenous equation is y[x]=
1 3
x C[1] + C[2]where c1 and c2 are arbitrary constants
3
x3
The particular integral of non homogenous equation is:
2
x3 1 3
The general solution of non homogenous equation is y[x]= + x C[1] + C[2]
2 3

PRACTICAL 4
GROWTH DECAY MODEL

a) (growth model exponetial case only)


2

In[75]:= r = Input["Enter the growth parameter"];


x0 = Input["Enter the initial value"];
sol = DSolve[{y '[x] ⩵ r y[x], y[0] ⩵ x0 }, y[x], x];
sol[[1, 1, 2]]
Plot[%, {x, 40, 50}]
Out[78]= 5 ⅇ4 x

8 × 1084

6 × 1084

Out[79]= 4 × 1084

2 × 1084

42 44 46 48 50

b) (Decay model exponetial case only)


In[80]:= r = Input["Enter the growth parameter"];
x0 = Input["Enter the initial value"];
sol = DSolve[{y '[x] ⩵ - r y[x], y[0] ⩵ x0 }, y[x], x];
sol[[1, 1, 2]]
Plot[%, {x, 0, 50}]
Out[83]= 5 ⅇ-4 x

7. × 10-15

6. × 10-15

5. × 10-15

4. × 10-15
Out[84]=

3. × 10-15

2. × 10-15

1. × 10-15

10 20 30 40 50

PRACTICAL 5
LAKE POLLUTION MODEL

a) Constant Flow
3

In[85]:= ClearAll[Cin, V, F, t, C]
Cin = 3
V = 58
F=8
de = c '[t] ⩵ (F / V) * Cin - c[t]
sol = DSolve[{de, c[0] ⩵ c0}, c[t], t]
Plot[Evaluate[c[t] /. sol /. c0 → Range[1, 20]], {t, 0, 30}]

Out[86]= 3

Out[87]= 58

Out[88]= 8

Out[89]= c′ [t] ⩵ 4 3 - c[t]


29
Out[90]= c[t] → ⅇ-4 t/29 - 3 + c0 + 3 ⅇ4 t/29 

10

Out[91]=
6

5 10 15 20 25 30

(b) Seasonal Flow


Cin = 1 + 6 Sin[2. pi.t]
4

In[92]:= ClearAll[Cin, V, F, t, C]
Cin = 1 + 6 * Sin[2 * Pi * t];
V = 28;
de1 = C '[t] ⩵ Cin * 10 - C[t]  V
sol1 = DSolve[{de1, C[0] ⩵ C0}, C[t], t]
Plot[Evaluate[C[t] /. sol1 /. C0 → Range[1, 20]], {t, 0, 10}]

Out[95]= C′ [t] ⩵ 1 10 - C[t] 1 + 6 Sin[2 π t]


28
3 t 3 t 3 Cos2 π t 3 Cos2 π t
Out[96]= C[t] → ⅇ- 28 π - 28 10 ⅇ 28 π + 28 - 10 ⅇ 28 π + C0 ⅇ 28 π 

20

15

Out[97]= 10

2 4 6 8 10

5 C Cin = 10 + 5 Cos[2. pi.t]

ClearAll[Cin, V, F, t, C]
Cin = 10 + 5 * Cos[2 * Pi * t];
V = 28;
de2 = C '[t] ⩵ Cin * 10 - C[t]  V
sol2 = DSolve[{de2, C[0] ⩵ C0}, C[t], t]
Plot[Evaluate[C[t] /. sol2 /. C0 → Range[1, 20]], {t, 0, 10}]
Out[98]= 10 + 5 Cos[2. pi.t]

Out[102]= C′ [t] ⩵ 1 10 - C[t] 10 + 5 Cos[2 π t]


28
5t 5 Sin2 π t 5t 5 Sin2 π t
Out[103]= C[t] → ⅇ- 14 - 56 π - 10 + C0 + 10 ⅇ 14 + 56 π 
5

14

12

10

2 4 6 8 10

PRACTICAL 6
DENSITY DEPENDENT GROWTH
6

In[105]:= Needs["PlotLegends`"]
b1 = 1
a2 = 0.5
c1 = 0.01
c2 = 0.005
k = 1000
equa1 = x '[t] ⩵ b1 x[t] 1 - x[t]  k - c1 x[t] y[t]
equa2 = y '[t] ⩵ c2 x[t] y[t] - a2 y[t]
s = NDSolve[{equa1, equa2, x[0] ⩵ 200, y[0] ⩵ 80}, {x, y}, {t, 0, 20}]
Plot[Evaluate[{x[t], y[t]} /. s], {t, 0, 20}, PlotRange → All,
PlotStyle → {{Red, Thickness[0.02]}, {Blue, Thickness[0.03]}},
AxesLabel → {"t Years", "Population Density"},
PlotLegends → {"x[t] Pray", "y[t] Predators"}]
Out[106]= 1

Out[107]= 0.5

Out[108]= 0.01

Out[109]= 0.005

Out[110]= 1000

Out[111]= x′ [t] ⩵ 1 - x[t]  x[t] - 0.01 x[t] y[t]


1000
Out[112]= y′ [t] ⩵ - 0.5 y[t] + 0.005 x[t] y[t]

Domain: {{0., 20.}}


Out[113]= x → InterpolatingFunction ,
Output: scalar

Domain: {{0., 20.}}


y → InterpolatingFunction 
Output: scalar

Population Density

200

150
x[t] Pray
Out[114]=
y[t] Predators
100

t Years
5 10 15 20

PRACTICAL 7
PREDITOR PREY MODEL
7

(a) Basic Volterra Model


In[115]:= Needs["PlotLegends`"]
b1 = 1
a2 = 0.5
c1 = 0.01
c2 = 0.005
equa1 = x '[t] ⩵ b1 x[t] - c1 x[t] y[t]
equa2 = y '[t] ⩵ c2 x[t] y[t] - a2 y[t]
s = NDSolve[{equa1, equa2, x[0] ⩵ 200, y[0] ⩵ 80}, {x, y}, {t, 0, 20}]
Plot[Evaluate[{x[t], y[t]} /. s], {t, 0, 20}, PlotRange → All,
PlotStyle → {{Red, Thickness[0.02]}, {Blue, Thickness[0.03]}},
AxesLabel → {"t Years", "Population Density"},
PlotLegends → {"x[t] Pray", "y[t] Predators"}]
Out[116]= 1

Out[117]= 0.5

Out[118]= 0.01

Out[119]= 0.005

Out[120]= x′ [t] ⩵ x[t] - 0.01 x[t] y[t]

Out[121]= y′ [t] ⩵ - 0.5 y[t] + 0.005 x[t] y[t]

Domain: {{0., 20.}}


Out[122]= x → InterpolatingFunction ,
Output: scalar

Domain: {{0., 20.}}


y → InterpolatingFunction 
Output: scalar

Population Density

200

150
x[t] Pray
Out[123]=
y[t] Predators
100

50
t Years
5 10 15 20

b) Effect of DDT
8

In[124]:= Needs["PlotLegends`"]
b1 = 1
a2 = 0.5
c1 = 0.01
c2 = 0.005
p1 = 0.1
p2 = 0.1
equa1 = x '[t] ⩵ b1 x[t] - c1 x[t] y[t] - p1 x[t]
equa2 = y '[t] ⩵ c2 x[t] y[t] - a2 y[t] - p2 y[t]
s = NDSolve[{equa1, equa2, x[0] ⩵ 200, y[0] ⩵ 80}, {x, y}, {t, 0, 20}]
Plot[Evaluate[{x[t], y[t]} /. s], {t, 0, 20}, PlotRange → All,
PlotStyle → {{Red, Thickness[0.02]}, {Blue, Thickness[0.03]}},
AxesLabel → {"t Years", "Population Density"},
PlotLegends → {"x[t] Pray", "y[t] Predators"}]
Out[125]= 1

Out[126]= 0.5

Out[127]= 0.01

Out[128]= 0.005

Out[129]= 0.1

Out[130]= 0.1

Out[131]= x′ [t] ⩵ 0.9 x[t] - 0.01 x[t] y[t]

Out[132]= y′ [t] ⩵ - 0.6 y[t] + 0.005 x[t] y[t]

Domain: {{0., 20.}}


Out[133]= x → InterpolatingFunction ,
Output: scalar

Domain: {{0., 20.}}


y → InterpolatingFunction 
Output: scalar

Population Density

200

150
x[t] Pray
Out[134]=
y[t] Predators

100

t Years
5 10 15 20

c) Two Prey One Predator


9

In[135]:= Needs["PlotLegends`"]
b1 = 1
b2 = 1
a3 = 0.5
c1 = 0.01
c2 = 0.005
d1 = 0.002
d2 = 0.003
equa1 = x '[t] ⩵ b1 x[t] - c1 x[t] z[t]
equa2 = y '[t] ⩵ b2 y[t] - c2 y[t] z[t]
equa3 = z '[t] ⩵ d1 x[t] z[t] + d2 y[t] z[t] - a3 z[t]
s = NDSolve[{equa1, equa2, equa3, x[0] ⩵ 200, y[0] ⩵ 80, z[0] ⩵ 50}, {x, y, z}, {t, 0, 20}]
Plot[Evaluate[{x[t], y[t], z[t]} /. s], {t, 0, 20}, PlotRange → All,
PlotStyle → {{Red, Thickness[0.02]}, {Blue, Thickness[0.03]}, {Green, Thickness[0.04]}},
AxesLabel → {"t Years", "Population Density"},
PlotLegends → {"x[t] Pray", "y[t] Predators", "z[t] Predators"}]
Out[136]= 1

Out[137]= 1

Out[138]= 0.5

Out[139]= 0.01

Out[140]= 0.005

Out[141]= 0.002

Out[142]= 0.003

Out[143]= x′ [t] ⩵ x[t] - 0.01 x[t] z[t]

Out[144]= y′ [t] ⩵ y[t] - 0.005 y[t] z[t]

Out[145]= z′ [t] ⩵ - 0.5 z[t] + 0.002 x[t] z[t] + 0.003 y[t] z[t]

Domain: {{0., 20.}}


Out[146]= x → InterpolatingFunction ,
Output: scalar

Domain: {{0., 20.}}


y → InterpolatingFunction ,
Output: scalar

Domain: {{0., 20.}}


z → InterpolatingFunction 
Output: scalar
10

Population Density
350

300

250
x[t] Pray
200
Out[147]= y[t] Predators
150
z[t] Predators
100

50

t Years
5 10 15 20

You might also like