MATLAB: How to solve a system of three equations with 2 parameters and initial values

ode45parameters

I was able to figure out how to solve the system with using only one parameter. Here are my lines:
clear all
clc
syms t x a
for a = [0:.25:1];
g = @(t,x,a)[3*(a-1)*x(1)+.01*x(3)-.0005*x(1)*x(2);.0005*x(1)*x(2)-.05*x(2)-.02*x(2);3*a+.05*x(2)-.01*x(3)];
[t,xa] = ode45(@(t,x) g(t,x,a),[0 50],[990 10 0]);
figure
plot(t,xa(:,1),t,xa(:,2),t,xa(:,3))
title(['Viral Spread of Infection'])
xlabel('t (days)')
ylabel('Population')
legend('S','I','R')
end
but now I am wanting to add another parameter "q" so that q = 0:2:10 and
g = [3*(a-1)*x(1)+.01*x(3)-.0005*x(1)*x(2)-q*x(2);.0005*x(1)*x(2)-.05*x(2)-.02*x(2)-q*x(2);3*a+.05*x(2)-.01*x(3)];
I tried just adding q to the same places as a, but it didn't work.
Please help!

Best Answer

I am guessing that I=x(2). (It would be nice to know for sure.)
This is one option:
av = 0 : 0.25 : 1;
qv = 0 : 2 : 10;
for k1 = 1:numel(av)
for k2 = 1:numel(qv)
g = @(t,x,a,q)[3*(a-1)*x(1)+.01*x(3)-.0005*x(1)*x(2)-q*x(2);.0005*x(1)*x(2)-.05*x(2)-.02*x(2)-q*x(2);3*a+.05*x(2)-.01*x(3)];
[t,xa] = ode45(@(t,x) g(t,x,av(k1),qv(k2)),[0 50],[990 10 0]);
figure
plot(t,xa(:,1),t,xa(:,2),t,xa(:,3))
title(['Viral Spread of Infection'])
xlabel('t (days)')
ylabel('Population')
legend('S','I','R')
end
end
This incorporates ‘q’ into your epidemiology model.
I leave it to you to determine if this is the best option for your homework problem.
EDIT For what it’s worth, ‘qI’ will throw an error because it is an undefined variable. You likely want ‘q*I’, since MATLAB does not recognise implied multiplication. Of course, we still have to know what ‘I’ is.
Related Question