forked from AllenDowney/ModSimPy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrabbits2mine.tex
More file actions
101 lines (86 loc) · 2.3 KB
/
rabbits2mine.tex
File metadata and controls
101 lines (86 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
% Created 2017-09-26 Tue 19:25
% Intended LaTeX compiler: pdflatex
\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{grffile}
\usepackage{longtable}
\usepackage{wrapfig}
\usepackage{rotating}
\usepackage[normalem]{ulem}
\usepackage{amsmath}
\usepackage{textcomp}
\usepackage{amssymb}
\usepackage{capt-of}
\usepackage{hyperref}
\usepackage{minted}
\author{Kawin Nikomborirak}
\date{\today}
\title{}
\hypersetup{
pdfauthor={Kawin Nikomborirak},
pdftitle={},
pdfkeywords={},
pdfsubject={},
pdfcreator={Emacs 25.3.1 (Org mode 9.1.1)},
pdflang={English}}
\begin{document}
\tableofcontents
\begin{minted}[frame=single]{ipython}
%matplotlib inline
from modsim import *
\end{minted}
\begin{minted}[frame=single]{ipython}
system = System(t0=0,
t_end=10,
adult_pop0=10,
birth_rate=0.9,
death_rate=0.5,
juvenile_pop0=0,
mature_rate=0.33)
system
\end{minted}
\begin{minted}[frame=single]{ipython}
def run_simulation(system):
"""Runs a proportional growth model.
Adds TimeSeries to `system` as `results`.
system: System object with t0, t_end, p0,
birth_rate and death_rate
"""
juveniles = TimeSeries()
juveniles[system.t0] = system.juvenile_pop0
adults = TimeSeries()
adults[system.t0] = system.adult_pop0
for t in linrange(system.t0, system.t_end):
births = system.birth_rate * adults[t]
deaths = system.death_rate * adults[t]
maturations = juveniles[t] * system.mature_rate
adults[t + 1] = adults[t] + maturations - deaths
juveniles[t + 1] = juveniles[t] + births - maturations
system.adults = adults
system.juveniles = juveniles
\end{minted}
\begin{minted}[frame=single]{ipython}
run_simulation(system)
system.adults
\end{minted}
\begin{minted}[frame=single]{ipython}
def plot_results(system, title=None):
"""Plot the estimates and the model.
system: System object with `results`
"""
newfig()
plot(system.adults, 'bo-', label='adults')
plot(system.juveniles, 'rs-', label='juveniles')
decorate(xlabel='Season',
ylabel='Rabbit population',
title=title)
\end{minted}
\begin{minted}[frame=single]{ipython}
plot_results(system, title='Proportional growth model')
\end{minted}
\begin{center}
\includegraphics[width=.9\linewidth]{rab2fig/rabs.png}
\end{center}
\end{document}