Module OneDMaps:
def LogisticMap(a,nIts,x):
for n in xrange(0,nIts):
return 4.*a*x*(1.-x)
Actual Program:
# Import plotting routines
from pylab import *
import OneDMaps
def OneDMap(a,N,x,f):
return x.append(f(a,N,x))
# Simulation parameters
# Control parameter of the map: A period-3 cycle
a = 0.98
# Set up an array of iterates and set the initital condition
x = [0.1]
# The number of iterations to generate
N = 100
#function name in OneDMaps module
func = LogisticMap
# Setup the plot
xlabel('Time step n') # set x-axis label
ylabel('x(n)') # set y-axis label
title(str(func) + ' at r= ' + str(a)) # set plot title
# Plot the time series: once with circles, once with lines
plot(OneDMap(a,N,x,func), 'ro', OneDMap(a,N,x,func) , 'b')
The program is supposed to call a function from a module OneDMaps.py and then plot it against it’s iterates. I get the error “Can’t multiply sequence by non-int of type float” and i’ve tried using LogisticMap(float(a)…) but that didn’t work. Also I want the function name to show up in the title of the plot but i get “at r=0.98 instead of it saying LogisticMap at r= 0.98.
You set up a
listlike this:You then multipy it by a
float:You can’t do that. Perhaps you wanted
xto be anarrayinstead of alist?(That would do the multiplication elementwise)
Note that adding lists concatenates:
Multiplication by an integer is the same as concatenating that many times:
But that makes no sense for floats,
(what should you get if you multiply by 3.5 for example?)