SIR model using fsolve and Euler 3PDF

조회 수: 8 (최근 30일)
Faraz Vossoughian
Faraz Vossoughian 2020년 4월 15일
댓글: Ameer Hamza 2020년 4월 16일
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

답변 (1개)

Ameer Hamza
Ameer Hamza 2020년 4월 15일
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
Faraz Vossoughian
Faraz Vossoughian 2020년 4월 15일
i have been asked to use this in conjuction with fsolve to solve non linear ode system SIR model. and im not sure how to implement it
Ameer Hamza
Ameer Hamza 2020년 4월 16일
This seems like an iterative formula. I don't know what solving it with fsolve() even means.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by