# MATLAB MATLAB help-ode45

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 realise 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!

Related Math Software Workshop News on Phys.org

### Want to reply to this thread?

"MATLAB help-ode45"

### Physics Forums Values

We Value Quality
• Topics based on mainstream science
• Proper English grammar and spelling
We Value Civility
• Positive and compassionate attitudes
• Patience while debating
We Value Productivity
• Disciplined to remain on-topic
• Recognition of own weaknesses
• Solo and co-op problem solving