Python Forum
Iteration Inverse Method
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Iteration Inverse Method
#1

Hello, I'm studying the Julia set of a complex polynomial function P. One method for to produce its Julia set, consist in select one point z of its Julia set, and calculate the inverse iterates P^-k(z). This is the iteration inverse Method. I was trying to make a program for produce computer images by this method, but I'm learning to program python. This is the program which i create, but it's wrong and I don't know how correct it.

def resuelve(a):
    y=sqrt(a+0.285+0.01j)
    return [-y,y]
    
def iteration(a):
    xs=[a]
    ys=[]
    iter=1
    while iter <3:
        iter=iter+1
        xs=xs+ys
        for i in range((iter-1)**2,iter**2-1):
            ys=ys+resuelve(xs[i])
    return xs
Furthermore, I don't know to plot a list in python. Could yo help me please?. Thank in advance.
Reply
#2
For plot, see https://matplotlib.org/users/pyplot_tutorial.html
Reply
#3
Thank so much, I have resolved this way
# -*- coding: utf-8 -*-
from numpy import *
import matplotlib.pyplot as plt

def inversa(a,c):
    y=sqrt(a-c)
    return [-y,y]

def fijo1(a):
    y=(1+sqrt(1-4*a))/2
    return y
    
def fijo2(a):
    y=(1+sqrt(1+4*a))/2
    return y
    
      
def nofijo(a,c):
    xs=[a]
    ys=inversa(a,c)
    for i in range(0,2):
        if ys[i]==a:
            xs=xs
        else: 
            xs=xs+[ys[i]]
    return xs
    
def iterationfijo(a,c,m):
    xs=nofijo(a,c)
    iter=0
    while iter <m:
        iter=iter+1
        for i in range(2**(iter-1),2**iter):
            xs=xs+inversa(xs[i],c)
    return xs
    
def iterainvlatex(a,c,m):
    xs=iterationfijo(a,c,m)
    for i in range(0,2**(m+1)):
        print "\\fill",(xs[i].real,xs[i].imag), "circle[radius=1pt];"

def draw(a,c,m):
    X = [x.real for x in iterationfijo(a,c,m)]
    Y = [x.imag for x in iterationfijo(a,c,m)]
    plt.scatter(X,Y, color='red')
    plt.show()
In the program iterainvltatex, a is the variable of the function f(z)=z**2+c, c is a complex constant, and m is the number of the iteration. The program give a code which you can use in latex with tikz. The program draw plot the same but in python.
Reply
#4
It would be nice if you can tell us some reasonable values for a and c and m for function draw(a,c,m).
Reply
#5
For example if we choose c=-0.8i, a must be a element of the Julia set of the function f(z)=z**2-0.8i. In particular, at least one fixed point is a element of the Julia set, furthermore if the fixed point is a repelling fixed point(the module of their derivate is bigger than one) is ever a element of the Julia set. In this case both fixed point are in the Julia set, so we can choose
draw(-0.8j,fijo1(-0.8j),15)
If I change 15 with a bigger number my computer can't draw, and this is a problem because there are too many point which are too nearly. For this reason, I'm trying to make a program which select only elements far to each other.
def modulo(a,c,m):
    xs=[a]
    iter=0
    p=0
    while iter<m:
        iter=iter+1
        for i in range(p,len(xs)):
             ys=inversa(xs[i],c)
             for k in range(0,len(xs)):
                 for l in range(0,2):
                    if sqrt((ys[l].real-xs[k].real)**2+(ys[l].imag-xs[k].imag)**2)<=0.01:
                        xs=xs
                    else:
                        xs=xs+[ys[l]]
                        p=p+1
                    return xs
But I have to correct it. If I get it finished i will post.
Reply
#6
Ok, I will wait.
Reply
#7
Excuse de delay, this it's the program that I created.

def inversa(a,c):
    y=sqrt(a-c)
    return [-y,y]

   
def fijo1(a):
    y=(1+sqrt(1-4*a))/2
    return y
   
            
def fijo2(a):
    y=(1-sqrt(1-4*a))/2
    return y 
def mod(c):
    y=2*abs(fijo1(c))
    x=2*abs(fijo2(c))
    return [x,y]
          
 
def inversalista(xs,c,p):
    ys=[]
    for i in range(p,len(xs)):
        ys=ys+inversa(xs[i],c)
    return ys

def distancia(a,b):
    y=sqrt((a.real-b.real)**2+(a.imag-b.imag)**2)
    return y

def distancialista(xs,a):
    y=[]
    for i in range(0,len(xs)):
        y=y+[distancia(xs[i],a)]
    return y
  



def puntoslejanos(list1,a,dis):
    y=distancialista(list1,a)
    cont=0
    i=0
    while i<len(y):
        if y[i]>=dis:
            i=i+1
            cont=cont+1
        else:
            i=i+1
            cont=cont
    return cont

def alejados(xs,ys,dis):
    zs=[]
    for i in range(0,len(ys)):
        if puntoslejanos(xs,ys[i],dis)!=len(xs):
            zs 
        else:
            zs.append(ys[i])
    return (zs)

      



def iteradamii(xs,c,p,dis):
    ys=inversalista(xs,c,p)
    xs+=alejados(xs,ys,dis)
    return xs
   

def posiciter(xs,c,p,dis):
    pos=len(iteradamii(xs,c,p,dis))-len(xs)
    return (pos)
    
            
def metiterinv(a,c,m,dis):
    xs=[a]
    itera=0
    p=0
    while itera<m:
        itera=itera+1
        xs=iteradamii(xs,c,p,dis)
        p=posiciter(xs,c,p,dis)
    return xs

def iterainvlatex1(a,c,m,dis):
    xs=metiterinv(a,c,m,dis)
    for i in range(0,len(xs)):
        print "\\fill",(xs[i].real,xs[i].imag), "circle[radius=0.5pt];"


def plotinverse(a,c,m,dis):
    xs=metiterinv(a,c,m,dis)
    X = [x.real for x in xs]
    Y = [x.imag for x in xs]
    plt.scatter(X,Y, color='red')
    plt.show()
    
For a complex rational function P(z)=z^2+c, the programs iterainvlatex and plotinverse, take a element a, a number of iterations m and a positive value dist. And applicate the Iteration inverse method, although in each iteration omitte the elements which distance of another element of the list it's smaller than dis.

iterainvlatex output the code for tikz in latex, for example

[Image: 2s01l51.jpg]

Thank you for your help.
Reply
#8
Thanks
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020