0% found this document useful (0 votes)
84 views15 pages

Differential Equations and Solutions

The document contains worked examples of solving differential equations using Mathematica. It begins by solving simple separable differential equations algebraically and numerically. It then covers solving Bernoulli differential equations, including the logistic growth equation. The key steps are using DSolve to directly solve Bernoulli equations and including initial conditions when solving the logistic equation for a specific case.

Uploaded by

Yuxdar Contell
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)
84 views15 pages

Differential Equations and Solutions

The document contains worked examples of solving differential equations using Mathematica. It begins by solving simple separable differential equations algebraically and numerically. It then covers solving Bernoulli differential equations, including the logistic growth equation. The key steps are using DSolve to directly solve Bernoulli equations and including initial conditions when solving the logistic equation for a specific case.

Uploaded by

Yuxdar Contell
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

Chapter 2

Question 1
In[1]:= Clear@x, yD
(i) (a)
dy

dx
= ky and (b) y =c
kx
. Differentiating (b)
In[2]:= D@c E
k x
, xD
Out[2]= c
k x
k
Substituting y into dy/dx, then
dy

dx
= k c
k
x therefore k c
k
x = k c
k
x. Hence true.
(ii) (a)
dy

dx
= -
x

y
, (b) y = x
2
+ y
2
= c. From y then
In[3]:= Dt@x^2 + y^2, xD
Out[3]= 2 x + 2 y Dt@y, xD
which is equal to zero, since c is a constant. Solving we have
In[4]:= Solve@2 x + 2 y Dt@y, xD == 0, Dt@y, xDD
Out[4]= 99Dt@y, xD
x

y
==
Therefore -
x

y
= -
x

y
. Hence, true.
(iii) (a)
dy

dx
= -
2 y

x
, (b) y =
a

x
2
. From (b) differentiate with respect to x, then
In[5]:= D@ax^2, xD
Out[5]=
2 a

x
3
But y =
2 a

x
2
so that
dy

dx
= -
2 y

x
. Therefore -
2 y

x
= -
2 y

x
. Hence true.
Question 2
Solving and checking limiting values
This first series of equations solve for p(t). It is then checked for the limit t->0. The upper limit cannot be
checked because no assumptions can be made about the values of a and k.
In[6]:= Clear@p, slope, t, Gompequ, Gompequ2, a, k, p0D
In[7]:= eq1 := p'@tD == k p@tD Ha Log@p@tDDL
Chapter [Link] 1
In[8]:= DSolve@eq1, p@tD, tD
Out[8]= 99p@tD

k t
Ha
k t
+
k C@1D
L
==
In[9]:= DSolve@ 8eq1, p@0D == p0<, p@tD, tD
Solve::ifun : Inverse functions are being used by Solve, so some solutions may not be found.
Out[9]= 9p@tD

k t
Ha+a
k t
+Log@p0DL
=
In[10]:= p@t_D := E
a+E
k t+Log@a+Log@p0DD
In[11]:= p@0D
Out[11]= p0
In[12]:= Limit@p@tD, t > D
Out[12]= LimitA
a+
k t+Log@a+Log@p0DD
, t E
Properties of growth equation
The stationary values are obtained. The programme gives the upper stationary value and warns about the
existence of the lower one.
In[13]:= Solve@k p Ha Log@pDL == 0, pD
Solve::verif : Potential solution 8p 0< Hpossibly
discarded by verifierL should be checked by hand. May require use of limits.
Out[13]= 88p
a
<<
In[14]:= slope := D@k p Ha Log@pDL, pD
In[15]:= Solve@slope == 0, pD
Out[15]= 88p
1+a
<<
In[16]:= slope . %
Out[16]= 8k + k Ha Log@
1+a
DL<
In[17]:= PowerExpand@%D
Out[17]= 80<
The next set of equations considers a numerical example in order to plot the Gompertz equation to see what it
looks like.
In[18]:= Gompequ := k p Ha Log@pDL
In[19]:= 8k = 0.8, a = 5, p0 = 20<
Out[19]= 80.8, 5, 20<
In[20]:= Gompequ2 := p@tD
Chapter [Link] 2
In[21]:= Gompequ2
Out[21]=
5+
0.8 t+Log@5Log@20DD
In[22]:= Plot@Gompequ2, 8t, 0, 10<D;
2 4 6 8 10
20
40
60
80
100
120
140
In[23]:= Limit@Gompequ2, t > D
Out[23]=
5
In[24]:= N@%D
Out[24]= 148.413
In[25]:= N@E^4D
Out[25]= 54.5982
In[26]:= Plot@Gompequ, 8p, 0.1, 150<D;
20 40 60 80 100 120 140
10
20
30
40
It is to be noted that the Gompertz equation has two stationary values, one at zero and the other at
a
. Second,
it has very similar properties to that of the logistic growth equation. Third, however, the sustainable yield is
not half the carrying capacity, since the sustainable yield is given by
a-1
, which is much less than half the
carrying capacity.
Question 3
(i)
dy

dx
= x H1 - y
2
L -1<y<1 then
dy

1-y
2
= x dx. Therefore integrating both sides
Chapter [Link] 3
In[27]:=

1

1 y
2
y
Out[27]=
1

2
Log@1 + yD +
1

2
Log@1 + yD
In[28]:=

x x
Out[28]=
x
2

2
Hence,
1

2
Log@1 + yD +
1

2
Log@1 + yD=
x
2

2
+c where c is the constant of integration. Solving for y we
obtain
In[29]:= SolveA
1

2
Log@1 + yD +
1

2
Log@1 + yD ==
x
2

2
+ c, yE
Solve::verif : Potential solution 8y < Hpossibly
discarded by verifierL should be checked by hand. May require use of limits.
Solve::ifun : Inverse functions are being used by Solve, so some solutions may not be found.
Out[29]= 99y
1 +
2 c+x
2

1 +
2 c+x
2
==
(ii)
dy

dx
= y
2
- 2 y + 1. But y
2
- 2 y + 1 = H1 - yL
2
. Hence
dy

H1-yL
2
= dx. Integrating both sides
In[30]:=

1

H1 yL
2
y
Out[30]=
1

1 + y
In[31]:=

1 x
Out[31]= x
Solving for y
In[32]:= SolveA
1

1 + y
+ c == x, yE
Out[32]= 99y
1 + c x

c x
==
(iii)
dy

dx
=
y
2

x
2
hence
dy

y
2
=
dx

x
2
. Integrating both sides
In[33]:=

1

y
2
y
Out[33]=
1

y
In[34]:=

1

x
2
x
Out[34]=
1

x
Introducing the constant of integration and solving, we have
Chapter [Link] 4
In[35]:= SolveA
1

y
==
1

x
+ c, yE
Out[35]= 99y
x

1 + c x
==
Question 4
(i)
dy

dx
= x
2
- 2 x + 1 and y=1 when x=0. Hence dy = Hx
2
- 2 x + 1L dx. Integrating both sides
In[36]:=

1 y
Out[36]= y
In[37]:=

Hx
2
2 x + 1L x
Out[37]= x x
2
+
x
3

3
Adding the constant of integration and solving for y we obtain
In[38]:= SolveAy == x x
2
+
x
3

3
+ c, yE
Out[38]= 99y c + x x
2
+
x
3

3
==
Including initial values we can solve for c
In[39]:= SolveAy ==
1

3
H3 c + 3 x 3 x
2
+ x
3
L, cE . 8y > 1, x > 0<
Out[39]= 88c 1<<
Therefore y =
x
3

3
- x
2
+ x + 1.
(ii)
dy

dx
=
3 x
2
+4 x+2

2 Hy-1L
, y=-1 when x=0. Re-arranging gives 2 Hy - 1L dy = H3 x
2
+ 4 x + 2L dx and integrating both
sides
In[40]:=

2 Hy 1L y
Out[40]= 2 Jy +
y
2

2
N
In[41]:=

H3 x
2
+ 4 x + 2L x
Out[41]= 2 x + 2 x
2
+ x
3
Adding the constant of integration we obtain the equation y
2
- 2 y = x
3
+ 2 x
2
+ 2 x + c, and solving for c we
obtain
In[42]:= Solve@2 y + y
2
== 2 x + 2 x
2
+ x
3
+ c, cD . 8y > 1, x > 0<
Out[42]= 88c 3<<
Chapter [Link] 5
Hence, solving for y gives
In[43]:= Solve@2 y + y
2
== 2 x + 2 x
2
+ x
3
+ 3, yD
Out[43]= 99y 1
!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!
4 + 2 x + 2 x
2
+ x
3
=, 9y 1 +
!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!
4 + 2 x + 2 x
2
+ x
3
==
Question 5
In[44]:= Clear@f, h, x, yD
Bernoulli equations are those which can be expressed as follows:
dy

dx
+ f HxL y = hHxL y
a
Mathematica can solve such equations directly with the DSovle command.
(i)
dy

dx
- y = -y
2.
In[45]:= DSolve@y'@xD y@xD == Hy@xDL^2, y@xD, xD
Out[45]= 99y@xD

x

x

C@1D
==
(ii)
dy

dx
- y = xy
2
.
In[46]:= DSolve@y'@xD y@xD == x Hy@xDL^2, y@xD, xD
Out[46]= 99y@xD

x

x
+
x
x C@1D
==
HiiiL
dy

dx
= 2 y - e
x
y
2
.
In[47]:= DSolve@y'@xD == 2 y@xD E^x Hy@xDL^2, y@xD, xD
Out[47]= 99y@xD
3
2 x

3 x
C@1D
==
Question 6
In[48]:= Clear@a, b, pD
The logistic equation can be expressed:
dp

dt
- a p = - b p
2
which is a Bernoulli equation with f(t) = - a, h(t) = -b and a = 2.
In[49]:= DSolve@p'@tD a p@tD == b Hp@tDL^2, p@tD, tD
Out[49]= 99p@tD
a
a t

b
a t
+
C@1D
==
In order to solve for p(t) for initial p(0) = p0 it is necessary to clear the value of p from the previous result
before using DSolve with an initial condition.
In[50]:= Clear@a, b, p, p0D
Chapter [Link] 6
In[51]:= DSolve@ 8p'@tD a p@tD == b Hp@tDL^2, p@0D == p0<, p@tD, tD
Out[51]= 99p@tD
a
a t
p0

a b p0 + b
a t
p0
==
Question 7
The question gives the results: R(0) = 6.68, R(t) = 6.08 and l = 1.24510
-4
. Then
t =
1

l
ln(
RH0L

RHtL
M =
In[52]:= N@H1H1.24510^H4LLL Log@6.686.08DD
Out[52]= 755.93
Therefore table dates for approximately:
In[53]:= 1977 756
Out[53]= 1221
Hence the table dates from about 1220 AD (13th Century). However, King Arthur ruled in the 5th Century,
and so the table could not be the authentic round table of King Arthur.
Question 8
The question gives the results: R(0) = 6.68, R(1950) = 4.09 and l = 1.24510
-4
. Then
t-t
0
=
1

l
ln(
RH0L

RHtL
M =
In[54]:= N@H1H1.24510^H4LLL Log@6.684.09DD
Out[54]= 3940.35
Hence, t
0
=
In[55]:= 1950 3940
Out[55]= 1990
So Hammurabi reigned about 1990 BC. (Note: Historians put the reign of Hammurabi at about 1792-1750
BC.)
Question 9
(i)
Assume f
1
HtL = e
r t
and f
2
HtL = t e
r t
are linearly dependent, then
b
1
e
r t
+ b
2
t e
r t
= 0
e
r t
Hb
1
+ b
2
tL = 0
which implies b
1
+ b
2
t = 0 for all t only if b
1
= b
2
= 0. Hence, e
r t
and t e
r t
must be linearly independent.
Chapter [Link] 7
(ii)
Assume f
1
HtL = e
r t
, f
2
HtL = t e
r t
and f
3
HtL = t
2
e
r t
are linearly dependent, then
b
1
e
r t
+ b
2
t e
r t
+ b
3
t
2
e
r t
= 0
e
r t
Hb
1
+ b
2
t + b
3
t
2
L = 0
which implies b
1
+ b
2
t + b
3
t
2
= 0 for all t only if b
1
= b
2
= b
3
= 0. Hence, e
r t
, t e
r t
and t
2
e
r t
must be linearly
independent.
Question 10
In[56]:= Clear@r, s, y1, y2D
In[57]:= r = + I
Out[57]= +
In[58]:= s = I
Out[58]=
In[59]:= E^Hr tL
Out[59]=
t H+ L
Using the ComplexExpand on the pallete bar on the above output gives the result in terms of Cos and Sin. The
same can be done for E^(s t)
In[60]:= E
t
Cos@t D + I E
t
Sin@t D
Out[60]=
t
Cos@t D +
t
Sin@t D
In[61]:= E^Hs tL
Out[61]=
t H L
In[62]:= E
t
Cos@t D I E
t
Sin@t D
Out[62]=
t
Cos@t D
t
Sin@t D
Now form a linear combination of e
r t
and e
s t
, in each case using the ComplexExpand on the pallete bar to
simplify the result.
In[63]:=
1

2
E^Hr tL +
1

2
E^Hs tL
Out[63]=
1

2

t H L
+
1

2

t H+ L
In[64]:= y1 = E
t
Cos@t D
Out[64]=
t
Cos@t D
Chapter [Link] 8
In[65]:=
1

2 I
E^Hr tL +
i
k
j
j
1

2 I
y
{
z
z E^Hs tL
Out[65]=
1

2

t H L

1

2

t H+ L
In[66]:= y2 = E
t
Sin@t D
Out[66]=
t
Sin@t D
Therefore y = c1*y1 + c2*y2, ie
In[67]:= y = c1y1 + c2y2
Out[67]= c1
t
Cos@t D + c2
t
Sin@t D
Question 11
In[68]:= Clear@P, r, P0D
(i)
dP

dt
= r P
(ii) Setting P(0) = P0, we solve the differential equation.
In[69]:= DSolve@ 8P'@tD == r P@tD, P@0D == P0<, P@tD, tD
Out[69]= 88P@tD
r t
P0<<
In[70]:= P@t_D = E^Hr tL P0
Out[70]=
r t
P0
(iii)
In[71]:= P@5D . 8P0 > 2000, r > 0.075<
Out[71]= 2909.98
Question 12
Half life is given by t = ln(2)/0.05, ie
In[72]:= Log@2D0.05
Out[72]= 13.8629
Question 13
(i)
In[73]:= eq1 = x^2 + 2 x 15
Out[73]= 15 + 2 x + x
2
Chapter [Link] 9
In[74]:= Factor@eq1D
Out[74]= H3 + xL H5 + xL
In[75]:= Solve@eq1 == 0, xD
Out[75]= 88x 5<, 8x 3<<
(ii)
In[76]:= fx = D@eq1, xD
Out[76]= 2 + 2 x
In[77]:= turn = Solve@fx == 0, xD
Out[77]= 88x 1<<
In[78]:= sol = turn@@1, 1, 2DD
Out[78]= 1
In[79]:= fxx = D@fx, xD
Out[79]= 2
In[80]:= Plot@eq1, 8x, 6, 5<D;
-6 -4 -2 2 4
-15
-10
-5
5
10
15
20
In[81]:= slope5 = fx . x > 5
Out[81]= 8
In[82]:= slope3 = fx . x > 3
Out[82]= 8
Hence, x = -5 is an attractor since f

H5L < 0; and x = 3 is a repellor since f

H3L > 0.
Question 14
In[83]:= Clear@k, k0D
(i)
The equation is k(t) = [
a s

n+d
+e
-H1-aL Hn+dL t
(k
0
1-a
-
a s

n+d
)D
1H1-aL
and a = 4, a = 0.25, s = 0.1, d = 0.4 and n = 0.03
Chapter [Link] 10
In[84]:= k@t_D = H H40.1LH0.03 + 0.4L + E^HH1 0.25LH0.03 + 0.4L tL
Hk0^H1 0.25L H40.1LH0.03 + 0.4LLL^H1H1 0.25LL
Out[84]= H0.930233 +
0.3225 t
H0.930233 + k0
0.75
LL
1.33333
In[85]:= k1@t_D = k@tD . k0 > 0.5
Out[85]= H0.930233 0.335629
0.3225 t
L
1.33333
In[86]:= k2@t_D = k@tD . k0 > 1.2
Out[86]= H0.930233 + 0.216299
0.3225 t
L
1.33333
But k

= s a k
a
- (n+d)k hence
In[87]:= kdot = 0.14k^0.25 H0.03 + 0.4L k
Out[87]= 0.4 k
0.25
0.43 k
In[88]:= sol = NSolve@kdot == 0, kD
Out[88]= 88k 0.<, 8k 0.908076<<
In[89]:= ke = sol@@2, 1, 2DD
Out[89]= 0.908076
In[90]:= k3@t_D = k@tD . k0 > ke
Out[90]= H0.930233 + 0.
0.3225 t
L
1.33333
In[91]:= Plot@ 8k1@tD, k2@tD, k3@tD<, 8t, 0, 15<,
PlotRange > All, AxesOrigin > 80, 0.5<, AxesLabel > 8"t", "k"<D;
2 4 6 8 10 12 14
t
0.6
0.7
0.8
0.9
1
1.1
1.2
k
(ii)
Chapter [Link] 11
In[92]:= Plot@kdot, 8k, 0, 1<D;
0.2 0.4 0.6 0.8 1
0.05
0.1
0.15
(iii)
In[93]:= fk = D@kdot, kD
Out[93]= 0.43 +
0.1

k
0.75
In[94]:= fke = fk . k > ke
Out[94]= 0.3225
Let f(k) = s a k
a
- (n+d)k then the linear approximation is given by:
k

= f(k) +f '(k)(k-ke) = f '(k)(k-ke)


In[95]:= fprime = D@kdot, kD . k > ke
Out[95]= 0.3225
Since |fprime| < 1 then ke is a stable equilibrium.
Question 15
(i)
YHtL

agains Y is simply a linear line through the origin with slope


s

v
> 0. The phase line is horizontal with
fixed point at the origin, and arrows indicating an ever increasing value of Y for some YH0L > 0.
(ii)
Given the differential equation Y '(t) - (s/v)Y(t) = 0, we can solve as follows:
In[96]:= Clear@s, YD
In[97]:= DSolve@ 8Y'@tD HsvL Y@tD == 0, Y@0D == Y0<, Y@tD, tD
Out[97]= 99Y@tD
s t

v
Y0==
Chapter [Link] 12
Question 16
Given Y[t] = Y
0
e
r t
. Solving D '[t] = kY(t) = k Y
0
e
r t
. Since D is protected, we use x in its place.
In[98]:= Clear@x, r, YD
In[99]:= sol = DSolve@ 8x'@tD == k Y0 E^Hr tL, x@0D == x0<, x@tD, tD
Out[99]= 99x@tD

r t
k Y0 + r Hx0
k Y0

r
L

r
==
In[100]:= x = sol@@1, 1, 2DD
Out[100]=

r t
k Y0 + r Hx0
k Y0

r
L

r
In[101]:= y = Y0 E^Hr tL
Out[101]=
r t
Y0
In[102]:= xy
Out[102]=

r t
H
r t
k Y0 + r Hx0
k Y0

r
LL

r Y0
In[103]:=
k

E
r t
Hr x0 + k Y0L

r Y0
Out[103]=
k

r


r t
Hr x0 + k Y0L

r Y0
Where the second output is obtained using the simplify on the whole expression and expanding the numerator
from the pallete. Then using Apart it can be seen that this is the solution:
DHtL

YHtL
= (
D
0

Y
0
-
k

r
)e
-r t
+
k

r
Question 17
Let i denote the nominal interest rate and r the real interest rate. If p denotes the rate of inflation, then r=i-p.
Then
A
25 t
= 2 A
Hence
2 =
25 Ht-.05L
In[104]:= Solve@2 Exp@25 Hi 0.05LD, iD
Solve::ifun : Inverse functions are being used by Solve, so some solutions may not be found.
Out[104]= 88i 0.0777259<<
Therefore i = 7.77 %.
Chapter [Link] 13
Question 18
(a)
In[105]:= Clear@fD
In[106]:= f@g_D := 100 Log@2Dg
In[107]:= Map@f, 82.7, 5.0, 2.5, 2.0, 1.4, 2.4, 2.0, 0.2, 0.2<D
Out[107]= 825.6721, 13.8629, 27.7259, 34.6574,
49.5105, 28.8811, 34.6574, 346.574, 346.574<
(b)
Negative growth rates indicate a decline, so the figure indicates the number of years for GDP to halve in value.
Question 19
(a)
Assuming exponential growth, then
PH1992L = 1162000000 = 667073000
lH1992-1960L
In[108]:= Solve@1162000000 667073000
H19921960L
, D
Solve::ifun : Inverse functions are being used by Solve, so some solutions may not be found.
Out[108]= 99
1

32
LogA
1162000

667073
E==
In[109]:= NA
1

32
LogA
1162000

667073
EE
Out[109]= 0.0173437
(b)
China's population will double in
In[110]:= N@Log@2D0.0173D
Out[110]= 40.0663
(c)
At the beginning of the new millennium, China's population will be
Chapter [Link] 14
In[111]:= 1162000000
0.0173H20001992L
Out[111]= 1.3344810
9
Question 20
In[112]:= 5000
0.05 40
+ H20000.05L H
H0.05 40L
1L
Out[112]= 292508.
Chapter [Link] 15

You might also like