November 29, 2020, 05:00:49 PM

Author Topic: Model of Disease Spread  (Read 497 times)

Offline bplus

  • Full Member
  • ***
  • Posts: 147
Model of Disease Spread
« on: March 28, 2020, 12:34:41 AM »
Thanks to TomToad's link, I managed to replicate the model in the link with SmallBASIC. I confess I fudged some stuff to get graphs to match. Pretty simple, if I can figure it out, but we gotta start from somewhere.

Code: [Select]
' Model Disease Spread.bas trans to SB from QB64, bplus 2020-03-27
' Numberphile math model of disease spread
' [youtube]https://www.youtube.com/watch?v=k6nLfCbAzgo[/youtube]
 
Trans = 3.2 ' Transmission Rate - this number is the one we might have greatest control over
Recov = .23 ' Recovery Rate - mostly up to nature but medicines might speed up recovery rate
I = .01 ' Infected
S = 1 - I ' Susceptible
dt = .015 ' time interval for snapshots = pixels on y-axis
ytitle = ymax - 20
yaxis = ytitle - 10
at 10, ytitle: ? "The Curve: Blue = Susceptible, Red Infected, Green = Neither S nor I"
WHILE t < xmax
    newS = S + dSdt ' update main variables
    newI = I + dIdt
    newR = R + dRdt
    PSET t, yaxis - (yaxis - 20) * newS, 9
    PSET t, yaxis - (yaxis - 20) * newI, 12
    PSET t, yaxis - (yaxis - 20) * newR, 10
    S = newS ' now change the values for next loop
    I = newI
    R = newR
    t = t + 1 'next snapshot along y-axis
WEND

FUNC dSdt ()
    dSdt = (-Trans * S * I) * dt
END
FUNC dIdt ()
    dIdt = (Trans * S * I - Recov * I) * dt
END
FUNC dRdt ()
    dRdt = (Recov * I) * dt
END
 
 


Offline bplus

  • Full Member
  • ***
  • Posts: 147
Re: Model of Disease Spread
« Reply #1 on: March 28, 2020, 12:45:03 AM »
By severely cutting the transmission rate the disease will die out before all Susceptible (Blue) are Infected.
(Below I increased dt because cutting Transmission rate increases the longevity of the time of infections.)

Code: [Select]
' Model Disease Spread.bas trans to SB from QB64, bplus 2020-03-27
' Numberphile math model of disease spread
' [youtube]https://www.youtube.com/watch?v=k6nLfCbAzgo[/youtube]
 
Trans = .8 '<<< from 3.2, Transmission Rate - this number is the one we might have greatest control over
Recov = .23 ' Recovery Rate - mostly up to nature but medicines might speed up recovery rate
I = .01 ' Infected
S = 1 - I ' Susceptible
dt = .025 '>>> from .015, time interval for snapshots = pixels on y-axis
ytitle = ymax - 20
yaxis = ytitle - 10
at 10, ytitle: ? "The Curve: Blue = Susceptible, Red Infected, Green = Neither S nor I"
WHILE t < xmax
    newS = S + dSdt ' update main variables
    newI = I + dIdt
    newR = R + dRdt
    PSET t, yaxis - (yaxis - 20) * newS, 9
    PSET t, yaxis - (yaxis - 20) * newI, 12
    PSET t, yaxis - (yaxis - 20) * newR, 10
    S = newS ' now change the values for next loop
    I = newI
    R = newR
    t = t + 1 'next snapshot along y-axis
WEND

FUNC dSdt ()
    dSdt = (-Trans * S * I) * dt
END
FUNC dIdt ()
    dIdt = (Trans * S * I - Recov * I) * dt
END
FUNC dRdt ()
    dRdt = (Recov * I) * dt
END
 

Offline lettersquash

  • Jr. Member
  • **
  • Posts: 73
    • Lettersquash Blog
Re: Model of Disease Spread
« Reply #2 on: April 04, 2020, 10:19:05 PM »
Very clever - you've inspired me to write a much more modest program to graph the crashing of my investments!  ???

Offline bplus

  • Full Member
  • ***
  • Posts: 147
Re: Model of Disease Spread
« Reply #3 on: April 05, 2020, 05:11:02 AM »
The rich get richer by sucking up stock pennies on the dollar at these times.

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal