0

I am trying to calculate the Mandelbrot set in Python 3.6 and i don't want to use the complex objects to calculate it. Does anybody have a getIterationCount(x, y) function?

I tried to rewrite java code to python but it didn't work.

def getIterationCount(x, y):
    maxiter = 100
    z = complexe(x, y)
    c = z
    for n in range(0, maxiter):
        if abs(z) > 2:
            return n
        z = z*z + c
    return maxiter
martineau
  • 119,623
  • 25
  • 170
  • 301
MaxTheGuy
  • 51
  • 9
  • Do you mean that you want to write your own code to square and sum your own representations of complex numbers? – quamrana May 05 '19 at 15:30
  • Yes, i want to calulate the fundamental z = z² + c without complexe numbers – MaxTheGuy May 05 '19 at 15:56
  • After about 15 seconds of googling: [Example: Class for complex numbers](http://hplgit.github.io/primer.html/doc/pub/class/._class-solarized005.html) – martineau May 05 '19 at 16:07
  • You just do the same thing, but write out what happens to the real and imaginary parts separately. – interjay May 05 '19 at 16:22

1 Answers1

2

I can write it for you if you mean to work only with real numbers:

def getIterationCount(ca,cb):
    maxiter = 100
    za, zb = ca,cb
    for n in range(0, maxiter):
        if za**2+zb**2 > 4:
            return n
        za, zb = za*za - zb*zb + ca, 2*za*zb + cb

    return maxiter
quantummind
  • 2,086
  • 1
  • 14
  • 20