{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "24" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "b = 4;\n", "f(x) = b*x\n", "f(6)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "updateSIR (generic function with 1 method)" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "function updateSIR(popnvector)\n", " susceptibles = popnvector[1];\n", " infecteds = popnvector[2];\n", " removeds = popnvector[3];\n", " newS = susceptibles - λ*susceptibles*infecteds*dt\n", " newI = infecteds + λ*susceptibles*infecteds*dt - γ*infecteds*dt\n", " newR = removeds + γ*infecteds*dt\n", " return [newS newI newR]\n", "end" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1×3 Array{Float64,2}:\n", " 975.0 34.5 20.5" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dt = 0.5;\n", "λ = 1/200; γ = 1/10\n", "\n", "s,i,r = 1000.,10,20\n", "vect = [s i r]\n", "\n", "updateSIR(vect)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "# Values for the test run\n", "λ = 1/20000\n", "γ = 1/10\n", "dt = 0.5\n", "tfinal = 610\n", "s0 = 10000.0\n", "i0 = 4.0\n", "r0 = 0.0\n", "\n", "\n", "nsteps = round(Int64,tfinal/dt)\n", "resultvals = Array{Float64}(undef,nsteps+1,3)\n", "timevec = Array{Float64}(undef,nsteps+1)\n", "resultvals[1,:] = [s0, i0, r0]\n", "timevec[1] = 0.\n", "\n", "\n", "for step = 1:nsteps\n", " resultvals[step+1,:] = updateSIR(resultvals[step,:])\n", " timevec[step+1] = timevec[step] + dt\n", "end" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Plots.GRBackend()" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "using Plots\n", "gr()" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "plot(timevec,resultvals)" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "plot(timevec,resultvals,\n", " title = \"Example of SIR results\",\n", " xlabel = \"Epidemic day\",\n", " ylabel = \"Population size\",\n", " label = [\"Succeptible\" \"Infected\" \"Removed\"]\n", ")" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [], "source": [ "# Values for the test run\n", "λ = 2.3e-8 #0.0005\n", "γ = 1/20.\n", "dt = 0.5\n", "tfinal = 610\n", "s0 = 22.0e6 #150.0\n", "i0 = 4.0\n", "r0 = 0.0\n", "\n", "\n", "nsteps = round(Int64,tfinal/dt)\n", "resultvals = Array{Float64}(undef,nsteps+1,3)\n", "timevec = Array{Float64}(undef,nsteps+1)\n", "resultvals[1,:] = [s0, i0, r0]\n", "timevec[1] = 0.\n", "\n", "\n", "for step = 1:nsteps\n", " resultvals[step+1,:] = updateSIR(resultvals[step,:])\n", " timevec[step+1] = timevec[step] + dt\n", "end" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [], "source": [ "svals = resultvals[:,1];\n", "ivals = resultvals[:,2];" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "plot(svals,ivals,\n", " title = \"First look at I vs S plot\",\n", " xlabel = \"Succeptible\",\n", " ylabel = \"Infected\"\n", ")" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.1" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "1/10" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Julia 1.2.0", "language": "julia", "name": "julia-1.2" }, "language_info": { "file_extension": ".jl", "mimetype": "application/julia", "name": "julia", "version": "1.2.0" } }, "nbformat": 4, "nbformat_minor": 4 }