Can you please write up the MatLab code for this question Th

Can you please write up the MatLab code for this question? Thank you.

Solution

a) For given pproblem, a system of ODE is given and values of Beta & Gamma are also defined.

The complete MATLAB function for the problem is as below:

function dxdt = SIR (t,x)

beta = 0.5; gamma = 0.2;

S = x(1);

I = x(2);

R = x(3);

  dxdt = [-beta*I*S; beta*I*S - gamma*I; gamma*I];

As can be observed that S, I & R are defined as x(1), x(2) & x(3). And dxdt is a column vector with columns as ds/dt, dI/dt & dR/dt, so, dxdt = [-beta*I*S; beta*I*S - gamma*I; gamma*I];

b) Intial values at t =0, is given in the problem and span is for 100 days. The MATLAB script using second order Runge-Kutta and function above i.e. SIR for first 100 days is as below:

x0 = [65000 1 0];

tspan = [0:100];

[t, sol_rk2]= ode23 (@SIR, tspan, x0);

x0 contains the intial value at t =0 of S, I & R in the sequence. Output of the script is t & sol_rk2, t is a column vector with no. of days and sol_rk2 is column matrix of 101x3 having values of S, I & R in three separate columns corresponding to days.

c) Script for calculation using ode45() is as below:

x0 = [65000 1 0];

tspan = [0:100];

[t, sol_45]= ode45 (@SIR, tspan, x0);

Output of the script is t & sol_45, t is a column vector with no. of days and sol_45 is column matrix of 101x3 havinf values of S, I & R in three separate columns corresponding to days.

Can you please write up the MatLab code for this question? Thank you.Solutiona) For given pproblem, a system of ODE is given and values of Beta & Gamma are

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site