Solving system of differential equations using ode45
显示 更早的评论
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.
回答(1 个)
Steven Lord
2020-3-17
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
类别
在 帮助中心 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
