Solve system of differential equations using Euler forward and ode45
76 views (last 30 days)
Show older comments
I have a basic SIR model which is described by three differential equations:
and I want to solve these using Euler forward and ode45. I have never worked with these types of problems before but from research I have found that for Euler forward I should use the equations:
But all the examples I have seen using this are given initial values for the different parameters, which I haven't. So I don't even know where to start. I would appreciate if someone could push me in the right direction of how to solve this. Thank you!
0 Comments
Accepted Answer
Ameer Hamza
on 29 Sep 2020
When using Euler forward, you start with
S(1) = s0; % initial value of S
I(1) = i0; % initial value of I
R(1) = r0; % initial value of R
and then run for loop using the equations in your question
N = % total number of time steps
dT = % length of each time step
for i = 2:N
S(i) = S(i-1) + % equation for Sn in question
I(i) = I(i-1) + % equation for In in question
R(i) = R(i-1) + % equation for Rn in question
end
t = 0:dT:(N-1)*dT;
plot(t, S, t, I, t, R)
See these example of how Euler method can be written in MATLAB
4 Comments
Ameer Hamza
on 30 Sep 2020
Can you explain what is wrong with this plot? This seems to follow the expected trajectories of the SIR model.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!