That's odd, your script only takes a few seconds for me.

By the way, if this is a sage script the you don't need the Integer()
wrappers, and you also don't need the semicolons.

2008/8/31 vakaras <[EMAIL PROTECTED]>:
>
> My code after changes:
>
> I = CDF.gen(0);
>
> n = Integer(200);
> x = Integer(200);
> y = Integer(200);
> x1 = -Integer(2);
> x2 = Integer(1);
> y1 = -Integer(1);
> y2 = Integer(1);
>
> def atkrenta(c):
>  z = Integer(0);
>  i = Integer(0);
>  sk = float(2);
>  for i in range(n):
>    z *= z;
>    z += c;
>    if (float(z.abs()) > sk):
>      break;
>  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/x, i/y]);
>
> But it's still too slow:
>
> $ time ./Mandelbrot.py
>
> real    13m24.017s
> user    6m40.961s
> sys     0m5.896s
>
> Has anybody more good ideas?
>
> On Aug 31, 10:50 am, Robert Bradshaw <[EMAIL PROTECTED]>
> wrote:
>> 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to