SIR model using fsolve and Euler 3PDF

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

Answers (1)

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 Comments

Thanks a lot Ameer, however im asked not to use ode solve command and instead use Euler implicit (3PDF) in conjucnction with fsolve command to solve this problem. I already made a function euler implici (3pdf) but im not sure how to incorporate the fsolve command,
I don't know about that method. If you can write a brief equation to implement it, maybe I can suggest a solution.
sure,
the formula for 3pdf is shown below. Its implicit method.
This is just a simple equation. WHat is confusing about this?
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
This seems like an iterative formula. I don't know what solving it with fsolve() even means.

Sign in to comment.

Tags

Asked:

on 15 Apr 2020

Commented:

on 16 Apr 2020

Community Treasure Hunt

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

Start Hunting!