Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
a couple of questions for some experienced coders

Subject: a couple of questions for some experienced coders

From: Brett Calhoon

Date: 12 Apr, 2009 22:29:01

Message: 1 of 3

so i'm really new to matlab scripting. i am working on a mandelbrot zoom program at present and have a couple of issues and would love some feedback.

first, i have been using ginput to generate the new axis points for the zoom, however i would like to allow the user to drag over the area they would like to zoom but i can't seem to find right commands.

also i've been looking at vectorization code and am having a little trouble understanding certain things, for example in Lucio Andrade-Cetto's vectorization for mandelbrot sets he has the following code

[x,y]=meshgrid([0:stepsR-1]*slR+lowerR,[0:stepsI-1]*slI+lowerI);
  Zvalues=ones(size(x));
  initZ=zeros(size(x));
  c=(x+i*y);


    
    z=initZ;
    h_z=1:(stepsR*stepsI);
    for counter=1:MaxIter
      z(h_z)=z(h_z).^2+c(h_z);
      h_z= h_z(find(abs(z(h_z))<2));
      Zvalues(h_z)=Zvalues(h_z)+1;
    end

what purpose does the array Zvalues serve? why would you not directly iterate with z?

and for the plot
 pcolor(x,y,log(double(Zvalues)));

the part that i don't understand is log(double(Zvalues)), any illumination would be greatly appreciated

Subject: a couple of questions for some experienced coders

From: Roger Stafford

Date: 13 Apr, 2009 00:48:01

Message: 2 of 3

"Brett Calhoon" <myriadbeings@gmail.com> wrote in message <grtpvd$7bf$1@fred.mathworks.com>...
> .......
> also i've been looking at vectorization code and am having a little trouble understanding certain things, for example in Lucio Andrade-Cetto's vectorization for mandelbrot sets he has the following code
>
> [x,y]=meshgrid([0:stepsR-1]*slR+lowerR,[0:stepsI-1]*slI+lowerI);
> Zvalues=ones(size(x));
> initZ=zeros(size(x));
> c=(x+i*y);
>
> z=initZ;
> h_z=1:(stepsR*stepsI);
> for counter=1:MaxIter
> z(h_z)=z(h_z).^2+c(h_z);
> h_z= h_z(find(abs(z(h_z))<2));
> Zvalues(h_z)=Zvalues(h_z)+1;
> end
>
> what purpose does the array Zvalues serve? why would you not directly iterate with z?
>
> and for the plot
> pcolor(x,y,log(double(Zvalues)));
>
> the part that i don't understand is log(double(Zvalues)), any illumination would be greatly appreciated

  'Zvalues' is giving you counts of how many iterations at each point it takes for abs(z(h_z)) there to reach the value 2. The h_z list will continue to grow shorter and shorter with each iteration. From there on they would diverge on out toward infinity if continued. These counts will differ for each initial complex value of c. It is this count that is essential in giving different colors to the wonderful mandelbrot images. That is what the mandelbrot image is all about. The black areas are those that have never reached 2 by the time the 'counter' reaches 'MaxIter' and if 'MaxIter' is selected large enough, presumably they never will.

  Incidentally the 'find' operation is not necessary. Matlab's logical indexing method

 h_z= h_z(abs(z(h_z))<2);

would give the same results and be somewhat more efficient.

Roger Stafford

Subject: a couple of questions for some experienced coders

From: Roger Stafford

Date: 13 Apr, 2009 02:43:01

Message: 3 of 3

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <gru241$c6e$1@fred.mathworks.com>...
> ......
> 'Zvalues' is giving you counts of how many iterations at each point it takes for abs(z(h_z)) there to reach the value 2.
> .....

  I neglected to mention that the way these 'Zvalues' counts vary is highly dependent on the resolution that is selected in 'stepsR' and 'stepsI'. They retain a fine structure at arbitrarily small scales and this is what is meant in calling them "fractals".

Roger Stafford

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us