Dnia Sat, 27 Feb 2010 21:43:19 +0100, Andrej Vodopivec napisa?(a):
>> (%i3)
>> f(x,y,n) :=
>> block([i:0,ER:4,iMax:n,x0:x,y0:y],
>> ?while abs(x)<ER and abs(y)<ER and i<iMax do
>> ?(x:x^2-y^2+x0,y:2.0*x*y+y0,i:i+1), min(ER,abs(x),abs(y)))$
>> compile(f);
>>
>>
>> (%i4)
>> (%o4) [f]
>> (%i5)
>> (dx : 2.7/70, dy : dx) $
>>
>>
>> (%i6)
>> for i:-2.0 thru 0.7 step dx do
>> for j:-1.2 thru 1.2 step dy do
>> f(i,j,4) $
>>
>>
>> (%i7) time(%o6);
>>
>> (%o7) [0.79]
>
> This can be improved even more if you declare variable:
>
> (%i1) f(x,y,n) :=
> block([i:0,ER:4,iMax:n,x0:x,y0:y],
> while abs(x)<ER and abs(y)<ER and i<iMax do
> (x:x^2-y^2+x0,y:2.0*x*y+y0,i:i+1), min(ER,sqrt(x^2+y^2)))$
> (%i2) dx: dy: 2.7/70$
> (%i3) compile(f);
> (%o3) [f]
> (%i4) for i:-2.0 thru 0.7 step dx do
> for j:-1.2 thru 1.2 step dy do
> f(i,j,4)$
> (%i5) time(%);
> (%o5) [0.447]
> (%i6) f(x,y,n) :=
> block([i:0,ER:4,iMax:n,x0:x,y0:y],
> mode_declare([x,y,x0,y0], float, [i,ER,iMax,n], integer),
> while abs(x)<ER and abs(y)<ER and i<iMax do
> (x:x^2-y^2+x0,y:2.0*x*y+y0,i:i+1), min(ER,sqrt(x^2+y^2)))$
> (%i7) compile(f);
> WARNING-> Assigning variable iMax, whose mode is fixnum,a value of mode
> any. WARNING-> Assigning variable x0, whose mode is float,a value of
> mode any. WARNING-> Assigning variable y0, whose mode is float,a value
> of mode any. (%o7) [f]
> (%i8) for i:-2.0 thru 0.7 step dx do
> for j:-1.2 thru 1.2 step dy do
> f(i,j,4)$
> (%i9) time(%);
> (%o9) [0.065]
>
> Andrej
Thx very much for all answers.
You are right that it can be improved.
But R uses unimproved code and its much faster.
I think that there is also another item.
In the R code there is an array for all the frames and if I'm not wrong
next frame is computed from prevoius value.
So Z1 is computed once, z2 once, z3 once ....
In Maxima code using pm3d every frame is computed independently,
so z1 is computed 20-times, z2 is computed 19-times, and so on.
Here are my times for computed single frames :
iMax grid_70 grid_200
1 20
2 53
3 97
4 138
5 180
6 28.82 228
7 290
8 376
9 507
10 727 (sum = 2616 sec = 43 min )
11 1108
12 1800
as you see it is much different then :
"It runs in 7.2 seconds on my laptop."
If I could use R-method in Maxima then time for frames
1-20 would be 20 X 20 sec (aprox).
The R-method is very efficient.
Best regards
Adam