'''Discrete model of limited growth (Verhulst):
    
Input:
    beta ... growth factor, program works for 0 <= beta <= 3
    A ... initial value, 0 <= A <= 1+1/beta is required
    N ... number of terms of the sequence to be computed
    
Typical call of program: 
    from python05_2 import fct
    fct(0.1, 2.5, 50)  #fct(A,beta,N)

'''

import numpy as np
import matplotlib.pyplot as plt

def fct(A,beta,N):
    #check whether admissible range is exceeded
    if (beta < 0 or beta > 3 or A < 0 or A > 1 + 1./beta):
        print('beta = ', beta, ', ' 'A = ', A, '; Input parameters: range exceeded')
        return
    else:
        #recursion
        x = A * np.ones(N)
        for n in range(1,N):
            x[n] = x[n-1] + beta*x[n-1]*(1-x[n-1]) 

    #plots
    t = range(1,N+1)
    s = [-1, N+1]
    plt.figure(1)
    plt.plot(t,x,t,x,'*',s,[0, 0],s,[1, 1])
    plt.axis([-1, N+1, -0.2, 1.6])
    plt.show()
    return x