Solving system of differential equations using ode45
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Md Latiful Sunny Shounok
el 17 de Mzo. de 2020
Comentada: Md Latiful Sunny Shounok
el 17 de Mzo. de 2020
I'm required to solve this sytem of odes by using ode 45. Any help to nudge me in the right direction would be appreciated.

I know that I'm supposed to create a function containing the odes to put in to Ode45. However, I'm having a bit of trouble with that. For example :
function c=NewOde(t,y)
c(1,1)=(-6.9*((y(1)*y(3))/y(1)+y(2)+y(3)+y(4)+y(5)))-0*y(1);
c(2,1)=(6.9*((y(1)*y(3))/y(1)+y(2)+y(3)+y(4)+y(5)))-0.9*y(2);
Is this the correct way to start putting all the odes into the function to pass it on to ode45?
Thanks.
0 comentarios
Respuestas (1)
Steven Lord
el 17 de Mzo. de 2020
It is, but instead of substituting values for your parameters inline you might want to define a few helper variables at the start of your function. That would make your function look more like your mathematical equations, making it easier to understand when or if you need to review or change your code days, weeks, months, or years from now.
function c = NewOde(t, y)
S = y(1);
E = y(2);
I = y(3);
R = y(4);
D = y(5);
N = S + E + I + R;
beta = 6.9; % How often a contact results in an exposure
% etc.
dSdt = -beta*S*I/N - ...
...
c = [dSdt; ...]
end
Ver también
Categorías
Más información sobre Ordinary Differential Equations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
