# Comparing Gaussians
# Create 3 Gaussian distributions with different variances and see behavior of polynomial and derivatives
sigma = 1
sigma1 = 2
sigma2 = 5
G = RealDistribution('gaussian', sigma)
G1 = RealDistribution('gaussian', sigma1)
G2 = RealDistribution('gaussian', sigma2)
# Generate 1st
rndpoly = C(1)
for i in range(25):
randRoot = C(G.get_random_element()) + C(G.get_random_element())*C(I)
rndpoly = rndpoly * (z - randRoot) * (z - conjugate(randRoot))
rootarray = []
for root in rndpoly.roots():
j = root[1]
for i in range(j):
rootarray.append(root[0])
# Generate 2nd
rndpoly1 = C(1)
for i in range(25):
randRoot = C(G1.get_random_element()) + C(G1.get_random_element())*C(I)
rndpoly1 = rndpoly1 * (z - randRoot) * (z - conjugate(randRoot))
rootarray1 = []
for root in rndpoly1.roots():
j = root[1]
for i in range(j):
rootarray1.append(root[0])
# Generate 3rd
rndpoly2 = C(1)
for i in range(25):
randRoot = C(G2.get_random_element()) + C(G2.get_random_element())*C(I)
rndpoly2 = rndpoly2 * (z - randRoot) * (z - conjugate(randRoot))
rootarray2 = []
for root in rndpoly2.roots():
j = root[1]
for i in range(j):
rootarray2.append(root[0])
Gout = Graphics()
Gout += points(rootarray,color='white', markeredgecolor = 'red', pointsize=20,zorder = 1, marker = "o")
Gout += points(rootarray1,color='white', markeredgecolor = 'blue', pointsize=20,zorder = 1, marker = "o")
Gout += points(rootarray2,color='white', markeredgecolor = 'green', pointsize=20,zorder = 1, marker = "o")
# Derivatives 1st
for i in range(10):
derpoly = rndpoly.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 = 'red', pointsize=20,zorder = 1, marker = "o")
rndpoly = derpoly
# Derivatives 2nd
for i in range(10):
derpoly1 = rndpoly1.derivative(z)
cparray = []
for root in derpoly1.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 = "o")
rndpoly1 = derpoly1
# Derivatives 3rd
for i in range(10):
derpoly2 = rndpoly2.derivative(z)
cparray = []
for root in derpoly2.roots():
j = root[1]
for i in range(j):
cparray.append(root[0])
Gout += points(cparray,color='white', markeredgecolor = 'green', pointsize=20,zorder = 1, marker = "o")
rndpoly2 = derpoly2
show(Gout,aspect_ratio=1)