Problem_1_Exploration

226 days ago by sasa2815

 
       
# Definitions C = ComplexField(1000) U = RealDistribution('uniform',[0,1]) R.<z> = C['z'] 
       
# Using the code for Method 2 rndpoly1 = C(1) for i in range(100): rndpoly1 = rndpoly1 * (z - C(U.get_random_element()) - C(U.get_random_element())*C(I)) 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) 
       
# Explore Problem (1) # We want to see what happens if we construct a polynomial by taking the product of (z-x_i)*(z-conjugate(x_i)) n/2 times # The polynomials are constructed almost the exact same way rndpoly2 = C(1) for i in range(50): randRoot = C(U.get_random_element()) + C(U.get_random_element())*C(I) rndpoly2 = rndpoly2 * (z - randRoot) * (z - conjugate(randRoot)) rootarray = [] for root in rndpoly2.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) 
       
# Let's see what happens when we take a derivative derpoly = rndpoly2.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 = "o") show(Gout,aspect_ratio=1) 
       
# What about a lot of derivatives? Gout = Graphics() Gout += points(rootarray,color='white', markeredgecolor = 'red', pointsize=20,zorder = 1, marker = "o") for i in range(25): derpoly = rndpoly2.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 = "o") rndpoly2 = derpoly show(Gout,aspect_ratio=1) 
       
# How about some other distributions? # Gaussian sigma = 1 G = RealDistribution('gaussian', sigma) rndpoly = C(1) for i in range(50): 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]) Gout = Graphics() Gout += points(rootarray,color='white', markeredgecolor = 'red', pointsize=20,zorder = 1, marker = "o") for i in range(25): 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 = 'blue', pointsize=20,zorder = 1, marker = "o") rndpoly = derpoly show(Gout,aspect_ratio=1) 
       
# Rayleigh sigma = 1 RAY = RealDistribution('rayleigh', sigma) rndpoly = C(1) for i in range(50): randRoot = C(RAY.get_random_element()) + C(RAY.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]) Gout = Graphics() Gout += points(rootarray,color='white', markeredgecolor = 'red', pointsize=20,zorder = 1, marker = "o") for i in range(25): 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 = 'blue', pointsize=20,zorder = 1, marker = "o") rndpoly = derpoly show(Gout,aspect_ratio=1) 
       
# 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) 
       
# Kabluchko with Problem 1 # We want to see what happens if we construct a polynomial by taking the product of (z-x_i)*(z-conjugate(x_i)) n/2 times # The polynomials are constructed almost the exact same way rndpoly2 = C(1) for i in range(50): randRoot = C(U.get_random_element()) + C(U.get_random_element())*C(I) rndpoly2 = rndpoly2 * (z - randRoot) * (z - conjugate(randRoot)) rootarray = [] for root in rndpoly2.roots(): j = root[1] for i in range(j): rootarray.append(root[0]) derpoly = rndpoly2.derivative(z) cparray = [] for root in derpoly.roots(): j = root[1] for i in range(j): cparray.append(root[0]) kabluchko_sum = (1/100)*sum(rootarray) - (1/100)*sum(cparray) Gout = Graphics() Gout += points(kabluchko_sum,color='white', markeredgecolor = 'red', pointsize=20,zorder = 1, marker = "o") show(Gout,aspect_ratio=1) 
       
# Repeat for n/2 = 5:50 # We want to see what happens if we construct a polynomial by taking the product of (z-x_i)*(z-conjugate(x_i)) n/2 times # Do we still see convergence to 0 (does Kabluchko still hold?) from sage.plot.colors import red, blue, lime N = 5 Gout = Graphics() plot_pts=[] while N < 50: q=50/N rndpoly2 = C(1) for i in range(N): randRoot = C(U.get_random_element()) + C(U.get_random_element())*C(I) rndpoly2 = rndpoly2 * (z - randRoot) * (z - conjugate(randRoot)) rootarray = [] for root in rndpoly2.roots(): j = root[1] for i in range(j): rootarray.append(root[0]) derpoly = rndpoly2.derivative(z) cparray = [] for root in derpoly.roots(): j = root[1] for i in range(j): cparray.append(root[0]) kabluchko_sum = abs((1/(2*N))*sum(rootarray)) - abs((1/(2*N))*sum(cparray)) plot_pts.append((2*N,kabluchko_sum)) #Gout += list_plot(kabluchko_sum,color='white', markeredgecolor = Color(1,0,0).blend(Color(0,0,1),fraction=q), pointsize=20,zorder = 1, marker = "o") N = N + 1 list_plot(plot_pts,color="green") 
       
# Repeat for n/2 = 5:150 # We want to see what happens if we construct a polynomial by taking the product of (z-x_i)*(z-conjugate(x_i)) n/2 times # Do we still see convergence to 0 (does Kabluchko still hold?) from sage.plot.colors import red, blue, lime N = 5 Gout = Graphics() plot_pts=[] while N < 150: q=250/N rndpoly2 = C(1) for i in range(N): randRoot = C(U.get_random_element()) + C(U.get_random_element())*C(I) rndpoly2 = rndpoly2 * (z - randRoot) * (z - conjugate(randRoot)) rootarray = [] for root in rndpoly2.roots(): j = root[1] for i in range(j): rootarray.append(root[0]) derpoly = rndpoly2.derivative(z) cparray = [] for root in derpoly.roots(): j = root[1] for i in range(j): cparray.append(root[0]) kabluchko_sum = abs((1/(2*N))*sum(rootarray)) - abs((1/(2*N))*sum(cparray)) plot_pts.append((2*N,kabluchko_sum)) #Gout += list_plot(kabluchko_sum,color='white', markeredgecolor = Color(1,0,0).blend(Color(0,0,1),fraction=q), pointsize=20,zorder = 1, marker = "o") N = N + 1 list_plot(plot_pts,color="green") 
       
^C
Traceback (click to the left of this block for traceback)
...
__SAGE__
^C
Traceback (most recent call last):    N = 5
  File "", line 1, in <module>
    
  File "/tmp/tmpJSwL4z/___code___.py", line 29, in <module>
    for root in derpoly.roots():
  File "sage/rings/polynomial/polynomial_element.pyx", line 7691, in sage.rings.polynomial.polynomial_element.Polynomial.roots (build/cythonized/sage/rings/polynomial/polynomial_element.c:67636)
  File "cypari2/gen.pyx", line 4357, in cypari2.gen.Gen.polroots
  File "src/cysignals/signals.pyx", line 98, in cysignals.signals.sig_raise_exception
KeyboardInterrupt
__SAGE__