On Aug 31, 2008, at 12:06 AM, vakaras wrote: > > Hello, > > I tried to plot Mandelbrot set using sage, but > function atkrenta works too long (sometimes > longer than 1 second). It seems that the main > problem is z.real() and z.imag() methods. Is > here any method to make this to work fast > enough? > > Here is my code: > > n = 200; > x = 200; > y = 200; > x1 = -1; > x2 = 1; > y1 = -1; > y2 = 1; > > def atkrenta(c): > z = 0; > for i in range(n): > z = z*z + c; > if (z.real()*z.real() + z.imag()*z.imag() > 4): > return i; > > p = []; > for i in range(n): > p.append([]); > for r in range(x*x1, x*x2, (x2-x1)): > for i in range(y*y1, y*y2, (y2-y1)): > c = r/x + I*i/y; > atkrito = atkrenta(c); > p[atkrito].append([r, i]); > print atkrito; > > P.S. If I change z.real()*z.real() + z.imag()*z.imag() > 4 to > z.abs() > 1 it works faster, but still too long.
I would write "I = CDF.0" at the top, to use the ComplexDoubleField to do all your arithmetic. This should be much, much faster. Using z.abs() > 2 should speed things up immensely as well. If that's still not fast enough, there is still lots of room for improvement. - Robert --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---