from numpy import *
from pylab import *
from math import *
def TentMap(a,x):
if x>= 0 and x<0.5:
return 2.*a*x
elif x>=0.5 and x<=1.:
return 2.*a*(1.-x)
# We set a = 0.98, a typical chaotic value
a = 0.98
N = 1.0
xaxis = arange(0.0,N,0.01)
Func = TentMap
subplot(211)
title(str(Func.func_name) + ' at a=%g and its second iterate' %a)
ylabel('X(n+1)') # set y-axis label
plot(xaxis,Func(a,xaxis), 'g', antialiased=True)
subplot(212)
ylabel('X(n+1)') # set y-axis label
xlabel('X(n)') # set x-axis label
plot(xaxis,Func(a,Func(a,xaxis)), 'bo', antialiased=True)
我的TentMap
功能无法正常工作。我不断收到错误The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
,我不明白我应该如何使用它们。基本上,该TentMap
函数接受一个值 X 并根据 X 是什么返回一个特定的值。因此,如果 0<=x<0.5 则返回 2 a x,如果 0.5<=x<=1 则返回 2 a (1-x)。