Ooops
September 27, 2021, 07:26:19

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

Offline bplus

  • Full Member
  • ***
  • Posts: 221
Model of Disease Spread
« on: March 28, 2020, 00:34:41 »
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: 221
Re: Model of Disease Spread
« Reply #1 on: March 28, 2020, 00:45:03 »
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: 96
    • Lettersquash Blog
Re: Model of Disease Spread
« Reply #2 on: April 04, 2020, 22:19:05 »
Very clever - you've inspired me to write a much more modest program to graph the crashing of my investments!  ???
I'll have you know, I'm coding all the right commands, just not necessarily in the right order.

Offline bplus

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

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal