-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1ba7fcc
commit 8778f88
Showing
11 changed files
with
244 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
function HIV_Prototypecode | ||
x0 = [ 1000 0 0.001]; | ||
tspan = [0 1000]; | ||
options = odeset('Refine',10, 'RelTol',1e-4); | ||
[t,x] = ode45(@HIV, tspan, x0, options); | ||
|
||
%% Plot | ||
figure(1) | ||
hold on | ||
plot(t,x(:,1),'b','linewidth',2) | ||
plot(t,x(:,2),'r','linewidth',2) | ||
legend('T','I') | ||
title ('CD4^+ populations') | ||
xlabel('time in days') | ||
ylabel('Population size') | ||
|
||
figure(2) | ||
plot(t,x(:,3),'--r','linewidth',2) | ||
legend('V') | ||
title ('Virus population') | ||
xlabel('time in days') | ||
ylabel('Population size') | ||
|
||
figure(3) | ||
plot(t,x,'linewidth',2) | ||
legend('T','I','V') | ||
title ('All populations') | ||
xlabel('time in days') | ||
ylabel('Population size') | ||
end | ||
|
||
%initial values for model parameters | ||
function dx = HIV(~, x) | ||
|
||
lambda= 20; | ||
mu = 0.02; | ||
beta = 1.7714e-05; | ||
delta = 0.1; | ||
N = 500; | ||
c=2.4; | ||
betav = 0.00002; | ||
%% Thresholds | ||
R0 = N*beta*delta*lambda/((delta+mu)*(betav*lambda+c*mu)); | ||
betastar = ((c+350*betav)*(delta))/(350*(delta*N)); | ||
%% Model equations | ||
dx = zeros(3,1); % | ||
%% systems of differential equations | ||
dx(1) = lambda - mu*x(1) - beta*x(1)*x(3); | ||
dx(2) = beta*x(1)*x(3) - (mu+delta)*x(2); | ||
dx(3) = delta*N*x(2) - c*x(3) - betav*x(1)*x(3); | ||
|
||
|
||
|
||
|
||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
%% Get user input for logistic growth parameters and initial population values | ||
prompt = {'Enter the value of r:', 'enter the value of K:', 'Initial time t_1:', 'Final time t_f:', 'Initial population N_1:', 'Initial population N_2:', 'Initial population N_3:', 'Initial population N_4:','Initial population N_5:'}; | ||
name = 'Logistic Growth Parameters and Initial Population Values'; | ||
tspan = [1 50]; | ||
defaultinput = {'0.02', '1000', '0', '500', '100', '600', '900','1100','1600'}; | ||
parameters = inputdlg(prompt, name, tspan, defaultinput); | ||
|
||
%% Convert input to numeric values | ||
r = str2double(parameters{1}); | ||
K = str2double(parameters{2}); | ||
t_1 = str2double(parameters{3}); | ||
t_f = str2double(parameters{4}); | ||
N0 = str2double(parameters(5:end));% using multiple initial conditions. | ||
|
||
%% Set time range | ||
t = t_1:0.1:t_f; | ||
|
||
% Solve differential equation for each initial population value | ||
for i = 1:length(N0) | ||
[t,N] = ode45(@(t,N) r*N*(1-N/K), t, N0(i)); | ||
% Plot results for each initial population value on the same graph | ||
hold on | ||
plot(t,N,'linewidth',2) | ||
end | ||
|
||
% Set plot properties | ||
%title('Logistic Growth') | ||
xlabel('Time') | ||
ylabel('Population Size, N(t)') | ||
box on | ||
legend('Population 1', 'Population 2', 'Population 3','Population 4', 'Population 5') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
%% This code solves the Logistic growth model | ||
%% | ||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
function ODElogisticmod | ||
close all; | ||
clc | ||
%%%%%%%%%%%%%%%%%% Request parameter values from user %%%%%%%%%%%%%%%%%%%%% | ||
prompt={'Enter the value of r ',... | ||
'Enter the value of K ',... | ||
}; | ||
name='Parameter Values for Logistic Model'; | ||
numlines=1;%specifies the number of lines for each answer in numlines | ||
|
||
defaultanswer={'0.02','1000'}; | ||
options.Resize='on'; | ||
options.WindowStyle='normal'; | ||
options.Interpreter='tex'; | ||
% create a dialog box that returns user input for multiple prompts | ||
%in a cell array | ||
% inputdlg suspends execution until the user responds. | ||
parameters=inputdlg(prompt,name,numlines,defaultanswer,options); | ||
%%%%%%%%%%%%%%%%%%% Request Initial data from user %%%%%%%%%%%%%%%%% | ||
prompt1={'Enter the starting time, t_1',... | ||
'Enter the final time t_f',... | ||
'Enter the initial Population N_1','Enter the initial Population N_2','Enter the initial Population N_3'}; | ||
name1='Initial data'; | ||
numlines=2; | ||
defaultanswer1={'0','500','100','600','1500'}; | ||
|
||
options1.Resize='on'; | ||
options1.WindowStyle='normal'; | ||
options1.Interpreter='tex'; | ||
initialDat=inputdlg(prompt1,name1,numlines,defaultanswer1,options1); | ||
%%%%%%%%%%%%%%%%%%%%%% Convert cell arrays to numbers %%%%%%%%%%%%%%%%%%%%% | ||
r = str2double(parameters{1}); | ||
K = str2double(parameters{2}); | ||
|
||
t_1 = str2double(initialDat{1}); | ||
t_f = str2double(initialDat{2}); | ||
N_0 = str2double(initialDat(3:end)); | ||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
tspan = [t_1 t_f]; | ||
for i=1:length(N_0) | ||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Solve system %%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
[t,x] = ode45(@Logistic,tspan,N_0(i)); | ||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Plot results %%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
figure(1) | ||
hold on | ||
plot(t,x,'linewidth',2); | ||
xlabel('time'); | ||
ylabel('N'); | ||
legend | ||
%legend('Population N_1','Population N_2','Population N_3'); | ||
end | ||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
function xdot = Logistic(~,x) | ||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
N= x(1); | ||
|
||
|
||
dN = r*N*(1-(N/K)); | ||
|
||
xdot = dN; | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
% Created by Farai Chirove | ||
% 3MC workshop Northwest University | ||
% Contour plots and surface plots for R_0 | ||
clc | ||
close all | ||
|
||
% step size and time span | ||
h = 0.0001; | ||
tspan = 1:h:10; | ||
|
||
%parameter values | ||
lambda= 20; | ||
mu = 0.02; | ||
%beta = 1.7714e-05; | ||
%delta = 0.1; | ||
N = 500; | ||
c=2.4; | ||
betav = 0.002; | ||
|
||
U1 = 1.7714e-05:0.001:0.1; | ||
U2 = 0.1:0.001:0.2; | ||
U3 = 0:0.001:1; | ||
|
||
for i = 1:length(U1) | ||
for j = 1:length(U2) | ||
|
||
u1 = U1(i); u2 = U2(j); | ||
R0(i,j) = N*u1*u2*lambda/((u2+mu)*(betav*lambda+c*mu)); | ||
|
||
%R0(i,j) = ((1-u1)*(1-u2)*lambda*delta)/(mu*(mu+((1-u2)*gamma*phi*tau)/(ps*T))); | ||
%R0(i,j) = ((1-u1)*(1-u2)*lambda*beta)/(mu*(mu+d+(gamma*vartheta*tau)/(pi*T))); | ||
|
||
end | ||
end | ||
|
||
[X,Y] = meshgrid(U1,U2); | ||
|
||
Ro = R0; P=X; Q=Y; | ||
|
||
figure(1) | ||
%subplot(1,2,1) | ||
mesh(P,Q,Ro'), hold on | ||
[C,h] = contour(P,Q,Ro','color','k'); axis tight | ||
|
||
text_handle1 = clabel(C,h); | ||
set(text_handle1,'BackgroundColor',[1 1 .6],... | ||
'Edgecolor',[.7 .7 .7]) | ||
% Xlabel('\beta_1'), Ylabel('\beta_2'), Zlabel('R_0') | ||
% Xlabel('\phi_1'), Ylabel('\phi_2'), Zlabel('R_0') | ||
title('Change in $\mathcal{R}_{0}$ with $\beta$ and $\delta$', 'Interpreter', 'Latex','FontSize',20) | ||
xlabel('$\beta$', 'Interpreter', 'Latex','FontSize',20), | ||
ylabel('$\delta$', 'Interpreter', 'Latex','FontSize',20) | ||
zlabel('$\mathcal{R}_{0}$', 'Interpreter', 'Latex','FontSize',20) | ||
set(gcf, 'PaperUnits', 'inches') | ||
papersize = get(gcf, 'PaperSize'); | ||
width = 6; % Initialize a variable for width. | ||
height = 6; % Initialize a variable for height. | ||
left = (papersize(1)- width)/2; | ||
bottom = (papersize(2)- height)/2; | ||
myfiguresize = [left, bottom, width, height]; | ||
set(gcf, 'PaperPosition', myfiguresize); | ||
opt = struct('FontSize',20); | ||
set(get(gcf,'CurrentAxes'), opt) | ||
print -depsc FigureR0.eps | ||
|
||
figure(2) | ||
%subplot(1,2,2) | ||
[C,h] = contourf(P,Q,Ro'); | ||
text_handle = clabel(C,h); | ||
set(text_handle,'BackgroundColor',[1 1 .6],... | ||
'Edgecolor',[.7 .7 .7]) | ||
% Xlabel('\beta_1'), Ylabel('\beta_2') | ||
% Xlabel('\phi_1'), Ylabel('\phi_2') | ||
title('Level lines','FontSize',20) | ||
xlabel('$\beta$', 'Interpreter', 'Latex','FontSize',20) | ||
ylabel('$\delta$', 'Interpreter', 'Latex','FontSize',20) | ||
set(gcf, 'PaperUnits', 'inches') | ||
papersize = get(gcf, 'PaperSize'); | ||
width = 6; % Initialize a variable for width. | ||
height = 6; % Initialize a variable for height. | ||
left = (papersize(1)- width)/2; | ||
bottom = (papersize(2)- height)/2; | ||
myfiguresize = [left, bottom, width, height]; | ||
set(gcf, 'PaperPosition', myfiguresize); | ||
opt = struct('FontSize',20); | ||
set(get(gcf,'CurrentAxes'), opt) | ||
title('b','FontSize',20) | ||
print -depsc FigureRV.eps |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Files here are organised by lecturer, for simplicity. |
File renamed without changes.