I have written a code for a system of nonlinear differential equations which models the Influenza disease. I was surprisingly shocked when I wanted to simulate this system with 4th order Runge-Kutta and ode45
function. The problem is that the results of these 2 methods are not the same. In fact, when I write a code for 4th order Runge-Kutta algorithm, the states will become larger and larger in each step time till they reach infinity. But the results are reasonable and rational when I simulate the system with ode45
function. I do not think the algorithm I wrote is incorrect. Can someone explain to me where I'm doing wrong In case if something is not valid in the coding?.
The codes I have written are as follows :
clc;clear;close all;
t = linspace(0,100,101)';
global alpha eta p f ep delta q beta kessi
kessi = 0.526; % Transition rate for the exposed
alpha = 0.244; % Recovery rate for the (symptomatic)
eta = alpha; % Infected
p = 0.667; % Recovery rate for the asymptomatic
f = 0.98; % 1-fatallity rate(one minus fatality rate)
ep = 0; % Infectivity reduction factor for the exposed
delta = 1; % Infectivity reduction factor for the asymptomatic
q = 0.5; % Contact reduction by isolation
beta = 1; % From CALCULATIONS
Influenza_Fun = @(t,x,u) [-beta*x(1)*(ep*x(2)+(1-q)*x(3)+delta*x(4))-u(1)*x(1)
beta*x(1)*(ep*x(2)+(1-q)*x(3)+delta*x(4))-kessi*x(2)
p*kessi*x(2)-alpha*x(3)-u(2)*x(3)
(1-p)*kessi*x(2)-eta*x(4)
f*alpha*x(3)+u(2)*x(3)+eta*x(4)+u(1)*x(1)];
% Initial Condtions
Ics = [15000 200 500 300 0]'; % [S0 E0 I0 A0 R0]';
u = [0 0]';
[~,States] = ode45(@(t,x)Influenza_Fun(t,x,u),t,Ics);
for i=1:5
plot(t,States(:,i),'LineWidth',2)
hold on
grid on
end
legend('S','E','I','A','R')
legend show
The above code will simulate the system based on ode45
function. The following code is my RK4 algorithm :
clc;clear;close all;
% { Control of Influenza disease based on Genetic Algorithm using desired Objective FUnction}
global alpha eta p f ep delta q beta kessi
kessi = 0.526; % Transition rate for the exposed
alpha = 0.244; % Recovery rate for the (symptomatic)
eta = alpha; % Infected
p = 0.667; % Recovery rate for the asymptomatic
f = 0.98; % 1-fatallity rate(one minus fatality rate)
ep = 0; % Infectivity reduction factor for the exposed
delta = 1; % Infectivity reduction factor for the asymptomatic
q = 0.5; % Contact reduction by isolation
beta = 1; % From CALCULATIONS
% Initial Condtions
Ics = [15000 200 500 300 0]'; % [S0 E0 I0 A0 R0]';
max_days = 100;
y(:,1) = Ics;
t = zeros(1,max_days);
h = 1;
t(1) = 0;
LB = [0 0]';
UB = [1 1]';
g = @yMatrix;
u = [0 0]';
Influenza_Fun = @(t,x,u) [-beta*x(1)*(ep*x(2)+(1-q)*x(3)+delta*x(4))-u(1)*x(1)
beta*x(1)*(ep*x(2)+(1-q)*x(3)+delta*x(4))-kessi*x(2)
p*kessi*x(2)-alpha*x(3)-u(2)*x(3)
(1-p)*kessi*x(2)-eta*x(4)
f*alpha*x(3)+u(2)*x(3)+eta*x(4)+u(1)*x(1)];
%% 2. mAiN Loop
for time = 1:max_days
k1 = Influenza_Fun(t(time),y(:,time),u);
k2 = Influenza_Fun(t(time)+(h/2),y(:,time)+k1,u);
k3 = Influenza_Fun(t(time)+(h/2),y(:,time)+k2,u);
k4 = Influenza_Fun(t(time)+h,y(:,time)+k3,u);
% y(i+1) = y(i) + (h/6)*(k1+2k2+2k3+k4)
y(:,time+1) = y(:,time)+(h/6)*(k1+2*k2+2*k3+k4);
t(time+1) = t(time)+h;
end
y = y';
for i=1:size(y,2)
plot(t,y(:,i),'LineWidth',2)
hold on
grid on
end