#!/usr/bin/env python # -*- coding: utf-8 -*- # Created on Aug 20, 2014 23:23 import math # classic logistic function def lf(t,k,p0,r): return (k*p0*math.exp(r*t))/(k+p0*(math.exp(r*t)-1)) # modified logistic function with non-renewable term k = 100 # renewable carrying capacity kn = 0 # nonrenewable carrying capacity nr = .04 # nonrenewable rate of consumption p0 = 1 # initial population p = p0 maxv = 10000000 # iterations r = 10.0/maxv # population growth rate per period v = [] for t in range(0,maxv+1): p *= 1 + r * (kn+k-p)/k kn = max(kn-p * nr,0) lp = lf(t,k,p0,r) v.append((p,lp)) # title line s = '%8s %12s' % ('t','|1-a/b|') print(s) print('-' * len(s)) # data display for t,(a,b) in enumerate(v): if(t % (maxv/10) == 0): print('%8d %12.8f' % (t,abs(1-a/b)))