---
title: "Math 339SP -- Extinction"
author: "Tim Chumley"
output:
  pdf_document: default
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(tinytex)
library(expm)
library(pracma)
```


## Extinction probabilities

The code below shows an iterative numerical method for approximating
the extinction probability in a Galton-Watson process which has an offspring
distribution with probability generating function $$G(s)$$. The code requires
you to put in your function $$G$$ as well as an initial guess $$e_0$$ for the 
extinction probability and a number of steps $$N$$ for the iteration to run.
Larger values of $$N$$ give a better approximation but the method converges
at an exponential rate.

```{r}
# user inputs
G = function(x) {1/6 + x/2 + x^2/3}
N = 25
e_0 = 1/3

# iterative method
e = array(0, N+1)
e[1] = e_0
for (n in 1:N) {
  e[n+1] = G(e[n])
}

# approximate probability of extinction
e[N+1]
```




