Когда я запускаю свой код, он возвращает пустой график.Я не могу понять, почему мой код делает это.Мне также нужен график, когда он получается, когда ml <0 меняет цвет на синий.Когда ml> 0 меняет цвет на другой, а ml = 0, получается другой цвет.Я приведу код ниже.Если бы кто-то мог помочь, это было бы здорово, так как я не очень знаком с питоном.
(ax1) = plt.subplots(1,1, figsize=(8,9),
sharex=True)
#initial conditions
d= 0.1
eps = 0.000001
#defining the equations as functions
#xnew equation
def f(a,b,x,y):
z = 1-b*y
r = a*x*z*(1-x*z)
if r>eps:
return r
else:
return 0
#ynew equation
def g(b,d,x,y):
r = (1-d)*y*(1+b*x)
if r>eps:
return r
else:
return 0
#Equation A
def A(a,b,x,y):
return a*(1-2*x - b*y + 4*b*x*y - 2*b**2*x*y**2)
#Equation B
def B(b,a,x,y):
return a*b*x*(2*x - 1 - 2*b*x*y)
#Equation C
def C(b,d,x,y):
return (1-d)*b*y
#Equation D
def D(b,d,x,y):
return (1-d)*(1+b*x)
#Equation E, which is max lyapunov exponent equation formed from the parameters above
def e(a,b,x,y,yn):
return log((A(a,b,x,y)+(B(b,a,x,y)*yn))**2 +(C(a,b,x,y)+
(D(b,d,x,y)*yn))**2 / (1 + yn**2))
#next ydash value calculated after the max lyapunov exponent is calculated
def yz(a,b,x,y,yn):
return (C(b,d,x,y)+(D(b,d,x,y)*yn))/(A(a,b,x,y)+(B(b,a,x,y)*yn))
#defining the function
def lyapunov():
#initial conditions
d=0.1
b=0.4
xold = 0.5
yold = 0.01
#looping values of a and b 0<a<5 and 0<b<6
for i in range(100):
a = 1+ 4*i/100
xold = 0.5
yold = 0.01
ydash = 1
yn=1
for i in range(100):
b = 1+ 5*i/100
xold = 0.5
yold = 0.01
ydash = 1
yn=1
#looping round x and y values
for j in range(100):
xnew=f(a,b,xold,yold)
ynew=g(b,d,xold,yold)
ydash =1
#the new value of xnew is xold same for y
xold = xnew
yold = ynew
#setting ml =0 as it starts at 0. inital
ml = 0
yn=1
#calculating the two equations and plotting ml against a and
#b. Also, need to print out the max ml value along with x and y
#value in a text file.
for k in range(100):
outfile = open('lyapunov.txt', 'w')
#finding sum of max lyapunov exponent then * by 0.5*N, in this case N is 100
ml = e(a,b,xold,yold,yn)
ml = ml + e(a,b,xold,yold,yn)
ml = (ml/100)*2
#ydash equation
ydash = yz(a,b,xold,yold,yn)
#now setting xold and yold equal to the equations xnew,ynew were so it keeps looping around each time, xold is no longer 0.5. Keeps taking new values. Same with yold.
xold=f(a,b,xold,yold)
yold=g(b,d,xold,yold)
#writing to file
outfile.write(str(xold)+'\t'+str(yolf)+'\t'+str(ml)+'\n')
#plotting a,ml and b,ml
ax1.plot(a, ml,',k')
ax1.plot(b, ml, ',k')
#closing the file
outfile.close()
#setting graph axis
ax1.set_ylim(0, 5)
ax1.set_xlim(0, 6)
#title
ax1.set_title('Lyapunov Exponent')
lyapunov()