lecture10.mw

> with(plots):

Warning, the name changecoords has been redefined

> with(plottools):

Warning, the assigned name arrow now has a global binding

> # Complex Numbers

> # a complex number is of the form x + yi

> # where i = sqrt(-1).

> # x is called the Real part, y is the Imaginary part

> # Maple uses I for sqrt(-1)

> # (to allow the use of i in for loops, for example).

> # addition is componentwise, i.e.

> # (x +y*I) + (u + v*I) = (x+u) + (y+v)*I

> # multiplication is done using the relation I^2 = -1:

> # (x + y*I) * (u + v*I) = (x*u - y*u) + (x*v + y*u)*I

> # i.e

> #

> c1 := 1 + 2*I;

c1 := 1+2*I

> c2 = 2 + 3*I;

c2 = 2+3*I

> c1 + c2;

(1+2*I)+c2

> c1 * c2;

(1+2*I)*c2

> # inversion is a little more complicated:

> # we have 1/(x+y*I) = x/(x^2+y^2) - y/(x^2+y^2)*I

> #i.e.

> 1/c1;

1/5-2/5*I

> # One may think of the complex numbers as

> # spead out in a plane, with the Real and Imaginary

> # parts corresponding to the x and the y coordinates,

> # respectively.

> #

> # The absolute value of c=(x + y*I)

> # is defined as sqrt(x^2 + y^2).

> # It is the "distance from the origin".

> #

> # Complex numbers sometimes show chaotic behavior.

> # For example, for a given z0 = x + y*I,

> # iteration of the function

> # z -> z^2 + z0

> # may or may not result in arbitrarily large  

> # absolute values of z.

> #

> mandelbrotSet := proc(x,y)
 local z, m;

 z := evalf( x + y*I );

 m := 0;

 to 10 while abs(z) < 2 do

   z := z^2 + (x+y*I);

   m := m + 1;

 end;

 return m;

end;

>

>

mandelbrotSet := proc (x, y) local z, m; z := evalf(x+I*y); m := 0; to 10 while abs(z) < 2 do z := z^2+x+I*y; m := m+1 end do; return m end procmandelbrotSet := proc (x, y) local z, m; z := evalf(x+I*y); m := 0; to 10 while abs(z) < 2 do z := z^2+x+I*y; m := m+1 end do; return m end procmandelbrotSet := proc (x, y) local z, m; z := evalf(x+I*y); m := 0; to 10 while abs(z) < 2 do z := z^2+x+I*y; m := m+1 end do; return m end procmandelbrotSet := proc (x, y) local z, m; z := evalf(x+I*y); m := 0; to 10 while abs(z) < 2 do z := z^2+x+I*y; m := m+1 end do; return m end procmandelbrotSet := proc (x, y) local z, m; z := evalf(x+I*y); m := 0; to 10 while abs(z) < 2 do z := z^2+x+I*y; m := m+1 end do; return m end procmandelbrotSet := proc (x, y) local z, m; z := evalf(x+I*y); m := 0; to 10 while abs(z) < 2 do z := z^2+x+I*y; m := m+1 end do; return m end procmandelbrotSet := proc (x, y) local z, m; z := evalf(x+I*y); m := 0; to 10 while abs(z) < 2 do z := z^2+x+I*y; m := m+1 end do; return m end proc

> mandelbrotSet(0.1,0.1);

10

> plot3d(mandelbrotSet, -3/2..3/2,-3/2..3/2, grid=[50,50]);

[Plot]

> plot3d(0, -2 .. 0.7, -1.1 .. 1.1, orientation=[-90,0], grid=[250, 250],
style=patchnogrid, scaling=constrained, color=mandelbrotSet);

[Plot]

> # we can make it faster and nicer:

> #http://www.math.utsa.edu/mirrors/maple/mfrmandf.htm

> restart: with(plots):

Warning, the name changecoords has been redefined

> mandelbrot_fast:=proc(x, y)
   local xn, xnold, yn, m;

   Digits:=10; # optional

   xn:=x;

   yn:=y;

   for m from 0 to 25 while evalhf(sqrt(xn^2+yn^2)) < 2 do

      xnold:=xn;   

      xn:=evalhf(xn^2-yn^2+x);

      yn:=evalhf(2*xnold*yn+y)

   od;

   m;

end:

> plot3d(0, -2 .. 0.7, -1.1 .. 1.1, orientation=[-90,0], grid=[250, 250],
style=patchnogrid, scaling=constrained, color=mandelbrot_fast);

[Plot]

>