SyntaxBomb - Indie Coders

Languages & Coding => SmallBASIC => Topic started by: bplus on March 28, 2020, 00:34:41

Title: Model of Disease Spread
Post by: bplus 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
 
 

Title: Re: Model of Disease Spread
Post by: bplus 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
 
Title: Re: Model of Disease Spread
Post by: lettersquash 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!  ???
Title: Re: Model of Disease Spread
Post by: bplus 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