#!/usr/bin/env python3

# iterate.py
# iterate a function of an initial value x0
# N times. 
#
# mu = function parameter
# x0 = initial value of x
# N = number of iterations
# i = running index 
# x = iterated values
#
# Usage: [i,x] = iterate(mu, x0, N); 
 
import numpy as np

def iterate(mu, x0, N): # function declaration
    i = range(0,N)	    # i is an index vector numbered from 1 to N.

    x = np.zeros(N)		# initialize x, which is a vector of length N, or a 1xN matrix.

    y = x0;
    for k in i:			# iterate x with function mu*x 
        x[k] = y        # N times and store value in x(k)
        y = mu*y
    
    return i,x
