- #1
klinklindeman
- 2
- 0
Hello,
I am trying to write a program on MATLAB using ode45 to solve the following equations:
S'=-bSZ-sS
Z'=bSZ+gR-aSZ
R'=sS+aSZ-gR
These are all derivatives with respect to t, differential equations.
a, b, a and g are all constants.
I realize I need to have two m files, one which defines the functions, and one which calls that and uses ode45. The code for my first m file is:
function Yout = program1(S,Z,R);
global beta gamma alpha sigma;
% set the parmeter values
tend = 10;
S0 = 500;
I0 = 1;
b=0.0095;
g=0.0001;
a= 0.005;
s=0.0001;
Sdot=(-b)*S*Z-(gg*S);
Zdot=(b*S*Z)+(g*R)-(a*S*Z);
Rdot=(s*S)+(a*S*Z)-(g*R);
udot = [Sdot; Zdot; Rdot];
I'm not sure if that is suitable, and I also need help writing the second m file. I need to plot Z and R on the same plot, vs t. I am really stuck, I have been working for hours, looking at examples, trying different combinations. MATLAB is most definitely not my strong point.
Thanks for the help!
I am trying to write a program on MATLAB using ode45 to solve the following equations:
S'=-bSZ-sS
Z'=bSZ+gR-aSZ
R'=sS+aSZ-gR
These are all derivatives with respect to t, differential equations.
a, b, a and g are all constants.
I realize I need to have two m files, one which defines the functions, and one which calls that and uses ode45. The code for my first m file is:
function Yout = program1(S,Z,R);
global beta gamma alpha sigma;
% set the parmeter values
tend = 10;
S0 = 500;
I0 = 1;
b=0.0095;
g=0.0001;
a= 0.005;
s=0.0001;
Sdot=(-b)*S*Z-(gg*S);
Zdot=(b*S*Z)+(g*R)-(a*S*Z);
Rdot=(s*S)+(a*S*Z)-(g*R);
udot = [Sdot; Zdot; Rdot];
I'm not sure if that is suitable, and I also need help writing the second m file. I need to plot Z and R on the same plot, vs t. I am really stuck, I have been working for hours, looking at examples, trying different combinations. MATLAB is most definitely not my strong point.
Thanks for the help!