Model of Disease Spread

Started by bplus, March 28, 2020, 00:34:41

Previous topic - Next topic

bplus

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.


' Model Disease Spread.bas trans to SB from QB64, bplus 2020-03-27
' Numberphile math model of disease spread
' https://www.youtube.com/watch?v=k6nLfCbAzgo

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




1 person likes this

bplus

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.)


' Model Disease Spread.bas trans to SB from QB64, bplus 2020-03-27
' Numberphile math model of disease spread
' https://www.youtube.com/watch?v=k6nLfCbAzgo

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


1 person likes this

lettersquash

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.

bplus

The rich get richer by sucking up stock pennies on the dollar at these times.
1 person likes this