P = [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1]
D = GeneralDiscreteDistribution(P)
counts = [0] * len(P)
nr_samples = 10000
for _ in range(nr_samples):
counts[D.get_random_element()] += 1
[1.0*x/nr_samples for x in counts]
import random
rndpoly1 = C(1)
polyOrd = random.sample(range(100), 1)
# print polyOrd
for i in range(polyOrd[0]):
randRoot = C(D.get_random_element()) + C(D.get_random_element())*C(I)
rndpoly1 = rndpoly1 * (z - randRoot)
rootarray = []
for root in rndpoly1.roots():
j = root[1]
for i in range(j):
rootarray.append(root[0])
Gout = Graphics()
Gout += points(rootarray,color='white', markeredgecolor = 'red', pointsize=20,zorder = 1, marker = "o")
for i in range(20):
derpoly = rndpoly1.derivative(z)
cparray = []
for root in derpoly.roots():
j = root[1]
for i in range(j):
cparray.append(root[0])
Gout += points(cparray,color='white', markeredgecolor = 'blue', pointsize=20,zorder = 1, marker = "*")
rndpoly1 = derpoly
show(Gout,aspect_ratio=1)