Dynamical models of ecosystems and epidemics