Exploration Problem 1

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'] 
       
poly = (z - C(1))*(z - C(I)) print poly 
       
z^2 +
(-1.00000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000 - I)*z + I
z^2 + (-1.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 - I)*z + I
rndpoly1 = C(1) for i in range(100): randRoot = C(U.get_random_element()) + C(U.get_random_element())*C(I) rndpoly1 = rndpoly1 * (z - randRoot) * (z - conjugate(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 rndpoly1 = C(1) for i in range(50): randRoot = C(U.get_random_element()) + C(U.get_random_element())*C(I) rndpoly1 = rndpoly1 * (z - randRoot) * (z - conjugate(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) 
       
 
       
#Gaussian sigma = 1 G = RealDistribution('gaussian', sigma) rndpoly1 = C(1) for i in range(50): randRoot = C(G.get_random_element()) + C(G.get_random_element())*C(I) rndpoly1 = rndpoly1 * (z - randRoot) * (z - conjugate(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) 
       
# Exponential # from sage.probability.probability_distribution import GeneralDiscreteDistribution mu = 2 E = RealDistribution('exponential', mu) rndpoly1 = C(1) for i in range(15): randRoot = C(E.get_random_element()) + C(E.get_random_element())*C(I) rndpoly1 = rndpoly1 * (z - randRoot) * (z - conjugate(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(8): 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) 
       
Traceback (click to the left of this block for traceback)
...
TypeError: Not a supported probability distribution
Traceback (most recent call last):    rndpoly1 = C(1)
  File "", line 1, in <module>
    
  File "/tmp/tmpyDalAo/___code___.py", line 6, in <module>
    E = RealDistribution('exponential', mu)
  File "sage/probability/probability_distribution.pyx", line 549, in sage.probability.probability_distribution.RealDistribution.__init__ (build/cythonized/sage/probability/probability_distribution.c:3909)
  File "sage/probability/probability_distribution.pyx", line 774, in sage.probability.probability_distribution.RealDistribution.set_distribution (build/cythonized/sage/probability/probability_distribution.c:6946)
TypeError: Not a supported probability distribution
 
       
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] rndpoly1 = C(1) for i in range(15): randRoot = C(D.get_random_element()) + C(D.get_random_element())*C(I) rndpoly1 = rndpoly1 * (z - randRoot) * (z - conjugate(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(8): 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)