SIR model using fsolve and Euler 3PDF
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi ive been asked to solve SIR model using fsolve command in MATLAB, and Euler 3 point backward. Im really confused on how to proceed, please help. This is what i have so far. I created a function for 3PDF schme but im not sure how to proceed with fsolve and solve the system of nonlinear odes. The SIR model is shown as and 3Dpf scheme is formulated as
clc
clear all
gamma=1/7;
beta=1/3;
ode1= @(R,S,I) -(beta*I*S)/(S+I+R);
ode2= @(R,S,I) (beta*I*S)/(S+I+R)-I*gamma;
ode3= @(I) gamma*I;
R0=0;
I0=10;
S0=8e6;
odes={ode1;ode2;ode3}
fun = @root2d;
x0 = [0,0];
x = fsolve(fun,x0)
function [xs,yb] = ThreePointBDF(f,x0, xmax, h, y0)
% This function should return the numerical solution of y at x = xmax.
% (It should not return the entire time history of y.)
% TO BE COMPLETED
xs=x0:h:xmax;
y=zeros(1,length(xs));
y(1)=y0;
yb(1)=y0+f(x0,y0)*h;
for i=1:length(xs)-1
y(i+1)=y(i)+h*f(xs(i),y(i));
yb(i+1)=(4/3*y(i+1)-1/3*yb(i))+2*h/3*f(xs(i+1),y(i+1));
end
end
0 Kommentare
Antworten (1)
Ameer Hamza
am 15 Apr. 2020
You need to use ode45 to solve the system of ODEs. Study the following code to see how it is done.
clc
gamma=1/7;
beta=1/3;
R0=0;
I0=10;
S0=8e6;
dsdt = @(S,I,R) -(beta*I.*S)./(S+I+R);
didt = @(S,I,R) (beta*I.*S)./(S+I+R)-I*gamma;
drdt = @(S,I,R) gamma*I;
dXdt = @(R,S,I) [dsdt(R,S,I); didt(R,S,I); drdt(R,S,I)];
IC = [8000000; 10; 0];
[t, x] = ode45(@(t,X) dXdt(X(1),X(2),X(3)), [0 10], IC);
s_sol = x(:,1);
i_sol = x(:,2);
r_sol = x(:,3);
subplot(3,1,1);
plot(t, s_sol);
title('S');
subplot(3,1,2);
plot(t, i_sol);
title('I');
subplot(3,1,3);
plot(t, r_sol);
title('R');
6 Kommentare
Ameer Hamza
am 16 Apr. 2020
This seems like an iterative formula. I don't know what solving it with fsolve() even means.
Siehe auch
Kategorien
Mehr zu Ordinary Differential Equations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!