Problem Statement: The following set of ordinary differential equations (ODEs) describe the dynamics of a predator-prey system.
dr/dt = a*r - b*r*f r(0)=3 ...Rabbits (Prey)
df/dt =-c*f + d*r*f f(0)=2 ...Foxes (Predator)
where
a = 2
b = 2
c = 1
d = 1
Find r(0.1) and f(0.1) by manually advancing these ODEs from the
initial position (at t=0) to the next step (at t=0.1) with the
Euler's method and the Runge-Kutta's 4th-order method. Show your
work.
Solution:
Euler's Method for Numerical Integration of ODEs.
With a=2, b=2, c=1, and d=1, the dynamic equations are:
dr/dt = 2*r - 2*r*f = 2*r*(1-f)
df/dt = -f + r*f = f*(r-1)
Start with r=3 and f=2, and the slopes at this starting point are:
dr/dt = 2*3*(1-2) = -6
df/dt = 2*(3-1) = 4
With h=0.1
r (at t=0.1) = r(0) + dr/dt*h = 3 + -6*0.1 = 2.4
f (at t=0.1) = f(0) + df/dt*h = 2 + 4*0.1 = 2.4
Runge-Kutta's Method for Numerical Integration of ODEs.
In the following, we repeat with Runge-Kutta's 4th-Order Method.
1st evaluation is the same as Euler's Method.
r1 = 3
f1 = 2
1st slope for r and f (from Problem 1) ...
kr1= fr(r1,f1) = -6
kf1= ff(r1,f1) = 4
2nd evaluation is at:
r2 = 3 + kr1*h/2 = 3 + -6*0.05 = 2.7
f2 = 2 + kf1*h/2 = 2 + 4*0.05 = 2.2
2nd slope for r and f ...
kr2= fr(r2,f2) = 2*2.7*(1-2.2) = -6.48
kf2= ff(r2,f2) = 2.2*(2.7-1) = 3.74
3rd evaluation is at:
r3 = 3 + kr2*h/2 = 3 + -6.48*0.05 = 2.676
f3 = 2 + kf2*h/2 = 2 + 3.74*0.05 = 2.187
3rd slope for r and f ...
kr3= fr(r3,f3) = 2*2.676*(1-2.187) = -6.35
kf3= ff(r3,f3) = 2.187*(2.676-1) = 3.67
4th evaluation is at:
r4 = 3 + kr3*h = 3 + -6.35*0.1 = 2.365
f4 = 2 + kf3*h = 2 + 3.67*0.1 = 2.367
u = 9.8116/(1+9.8116) = 0.9075
4th slope for r and f ...
kr4= fr(r4,f4) = 2*2.365*(1-2.367) = -6.47
kf4= ff(r4,f4) = 2.367*(2.365-1) = 3.23
Weighted average slope for r and f ...
krave = (kr1+2*kr2+2*kr3+kr4)/6 = (-6-2*6.48-2*6.35-6.47)/6 = -6.36
kfave = (kf1+2*kf2+2*kf3+kf4)/6 = ( 4+2*3.74+2*3.67+3.23)/6 = 3.67
Update the values of r and f at t=h=0.1
r = r + krave*h = 3 + -6.36*0.1 = 2.364
f = f + kfave*h = 2 + 3.67*0.1 = 2.367
Problem Statement: Write a program to integrate the coupled set of ODEs from t=0 to t=10.
Solution:
|