Solve system of differential equations using Euler forward and ode45
24 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Katara So
am 29 Sep. 2020
Kommentiert: Ameer Hamza
am 30 Sep. 2020
I have a basic SIR model which is described by three differential equations:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/368269/image.png)
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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/368272/image.png)
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 Kommentare
Akzeptierte Antwort
Ameer Hamza
am 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 Kommentare
Ameer Hamza
am 30 Sep. 2020
Can you explain what is wrong with this plot? This seems to follow the expected trajectories of the SIR model.
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!