模块OneDMaps:
def LogisticMap(a,nIts,x):
for n in xrange(0,nIts):
return 4.*a*x*(1.-x)实际程序:
# 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') 程序应该从一个模块OneDMaps.py中调用一个函数,然后根据它的迭代来绘制它。我收到错误消息"Can't multiply sequence by non-int of type float“,并且我尝试使用LogisticMap(float(a)...)但这并不管用。另外,我希望函数名显示在绘图的标题中,但我得到的是"at r=0.98“而不是”LogisticMap at r= 0.98“。
发布于 2012-12-09 12:02:42
您可以像这样设置一个list:
x = [0.1]然后通过float对其进行多重复制
return 4.*a*x*(1.-x)你不能这么做。也许您希望x成为一个array而不是list
x = array([0.1])(这将以元素方式进行乘法)
请注意,添加列表将连接以下内容:
[0] + [1] == [0, 1]乘以一个整数等同于连接这么多次:
[0] * 3 == [0, 0, 0]但这对浮点数来说没有任何意义,
[0] * 3.0 #raises TypeError as you've seen(例如,如果你乘以3.5,你会得到什么?)
https://stackoverflow.com/questions/13784501
复制相似问题