Ошибка RuntimeWarning: invalid value encountered in sqrt
При отработке кода возникает ошибка: RuntimeWarning: invalid value encountered in sqrt. Что нужно исправить?
import matplotlib.pyplot as plt
import numpy as np
import math
def logistic(r, x2, x1):
return r * np.sqrt(x2) * (1.0 - np.sqrt(x1))
left = 0.1
right = 3
n = 10000
r = np.linspace(left, right, n)
iterations = 3000
last = 100
x =[[], [], []]
for i in range(len(x)):
x[i]=0.01*np.ones(n)
index=0
for i in range(iterations):
x[index] = logistic(r, x[(index - 1) % len(x)], x[(index-2) % len(x)])
if i >= (iterations - last):
plt.plot(r, x[index], ',k', alpha=0.25)
index = (index+1) % len(x)
plt.xlim(left, right)
plt.ylim(0.1, 1.0)
plt.title('Бифуркационная диаграмма')
path = 'privet.png'
plt.savefig(path)