Exploration Problem 2

228 days ago by mafe3147

# Def U = RealDistribution('uniform',[0,1]) U.get_random_element() C = ComplexField(300) C(U.get_random_element()) + C(U.get_random_element()) * C(I) R.<z> = C['z'] import random random.sample(range(10), 1) 
       
[3]
[3]
import random rndpoly1 = C(1) polyOrd = random.sample(range(100), 1) # print polyOrd for i in range(polyOrd[0]): randRoot = C(U.get_random_element()) + C(U.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") show(Gout,aspect_ratio=1) 
       
# First Derivatives derpoly = rndpoly1.derivative(z) cparray = [] for root in derpoly.roots(): j = root[1] for i in range(j): cparray.append(root[0]) Gout = Graphics() Gout += points(rootarray,color='white', markeredgecolor = 'red', pointsize=20,zorder = 1, marker = "o") Gout += points(cparray,color='white', markeredgecolor = 'blue', pointsize=20,zorder = 1, marker = "*") show(Gout,aspect_ratio=1) 
       
# More Derivatives 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) 
       
# Uniform import random rndpoly1 = C(1) polyOrd = random.sample(range(100), 1) # print polyOrd for i in range(polyOrd[0]): randRoot = C(U.get_random_element()) + C(U.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") #show(Gout,aspect_ratio=1) 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) 
       
#Gaussian sigma = 1 G = RealDistribution('gaussian', sigma) import random rndpoly1 = C(1) polyOrd = random.sample(range(100), 1) # print polyOrd for i in range(polyOrd[0]): randRoot = C(G.get_random_element()) + C(G.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) 
       
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)