Hello,(adsbygoogle = window.adsbygoogle || []).push({});

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!

**Physics Forums | Science Articles, Homework Help, Discussion**

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# MATLAB MATLAB help-ode45

Can you offer guidance or do you also need help?

Draft saved
Draft deleted

Loading...

Similar Threads for MATLAB help ode45 |
---|

MATLAB MATLAB: forces acting on an object |

MATLAB Matlab histogram |

MATLAB Sovling Bernoulli's differential equation in matlab? |

MATLAB MATLab: Not enough inputs for nlinfit |

MATLAB Help needed to fix a matlab code |

**Physics Forums | Science Articles, Homework Help, Discussion**