Logo by Fiery - Contribute your own Logo!

END OF AN ERA, FRACTALFORUMS.COM IS CONTINUED ON FRACTALFORUMS.ORG

it was a great time but no longer maintainable by c.Kleinhuis contact him for any data retrieval,
thanks and see you perhaps in 10 years again

this forum will stay online for reference
News: Support us via Flattr FLATTR Link
 
*
Welcome, Guest. Please login or register. March 28, 2024, 03:03:39 PM


Login with username, password and session length


The All New FractalForums is now in Public Beta Testing! Visit FractalForums.org and check it out!


Pages: [1]   Go Down
  Print  
Share this topic on DiggShare this topic on FacebookShare this topic on GoogleShare this topic on RedditShare this topic on StumbleUponShare this topic on Twitter
Author Topic: Having fun with scilab and the mandelbrot set  (Read 5616 times)
0 Members and 1 Guest are viewing this topic.
ker2x
Fractal Molossus
**
Posts: 795


WWW
« on: February 22, 2012, 10:06:57 PM »

I'm learning scilab, i don't understand everything in the code below.
But i find interesting the way to compute the mandelbrot set  grin

If you don't know scilab, it's free, opensource, powerful, multiplateform, slow smiley
http://www.scilab.org/

Code:
// In the row matrix J, we store the indices of the points in the Mandelbrot set.
// Initially, the matrix J contains the indices from 1 to xsize*ysize,
// meaning that all the points are in the set.
// During the computation, we are going to remove points from the set,
// by setting the corresponding entry of J to zero.
// In the current iteration, the set of indices of points which are in the set
// is therefore computed with the L = J(J>0) statement.
// Hence, when the algorithm progresses, there are less and less points in the
// set so that the matrix L has a decreasing number of entries.
// The operations are done only on the entries defined in L.
// This makes the algorithm faster and faster.

function R = computeMandelbrotVect(xsize,ysize,nmax,xmin,xmax,ymin,ymax)
    //Init matrix
    xvect = linspace( xmin, xmax, xsize );
    yvect = linspace( ymin, ymax, ysize );
    [X,Y]=meshgrid(xvect,yvect);

    //Inits values
    Z = zeros(xsize,ysize);    //The Z of Z = Z²+C
    R = -ones(xsize,ysize);   
    W = zeros(xsize,ysize);    // Will store the distance from 0,0
   
    C=X+%i*Y;                  //Set the value of C
    J = 1:xsize*ysize;         
    for k=0:nmax               // 0 to max iteration
        L = J(J>0);               
        Z(L) = Z(L).^2+C(L);       // Z = Z² + C
        W(L) = abs(Z(L));          // Compute Distance
        M = find(W(L)>2);          // Find if Distance > 2
        R(L(M)) = k;               
        J(L(M)) = 0;               
    end
    R = R';
    // The maximum number of colors
    CMAX = 1000;
    f=gcf();
    f.color_map = jetcolormap(CMAX);
    D = R;
    k = find(R<>-1);
    D(k) = floor(R(k)/max(R(k))*CMAX);
    k = find(R==-1);
    D(k) = CMAX;
    Matplot(D);
    f.children.isoview="on";
    f.children.axes_visible=["off" "off" "off"];
endfunction

stacksize("max");
xsize = 200;
ysize = 200;
nmax = 1000;
xmin = -2.0;
xmax = 1.0;
ymin = -1.0;
ymax = 1.0;

mprintf("begin...");
computeMandelbrotVect(xsize,ysize,nmax,xmin,xmax,ymin,ymax);
mprintf("done!");
Logged

often times... there are other approaches which are kinda crappy until you put them in the context of parallel machines
(en) http://www.blog-gpgpu.com/ , (fr) http://www.keru.org/ ,
Sysadmin & DBA @ http://www.over-blog.com/
ker2x
Fractal Molossus
**
Posts: 795


WWW
« Reply #1 on: February 22, 2012, 10:09:32 PM »

this part
Code:
C=X+%i*Y; 

is like
Code:
C=complex(X,Y)
Logged

often times... there are other approaches which are kinda crappy until you put them in the context of parallel machines
(en) http://www.blog-gpgpu.com/ , (fr) http://www.keru.org/ ,
Sysadmin & DBA @ http://www.over-blog.com/
Pages: [1]   Go Down
  Print  
 
Jump to:  

Related Topics
Subject Started by Replies Views Last post
3D Mandelbrot Movies Showcase (Rate My Movie) David Makin 0 5464 Last post December 09, 2006, 11:38:14 PM
by David Makin
Mandelbrot 3d Mutatorkammer Gallery cKleinhuis 2 6202 Last post March 19, 2008, 05:45:40 PM
by GFWorld
3d mandelbrot Selfmade lycium 0 7048 Last post April 27, 2008, 09:16:43 PM
by lycium
The Mandelbrot Set Introduction to Fractals and Related Links « 1 2 » billboll 25 48494 Last post February 15, 2013, 02:23:51 AM
by KingOfOwls
Scilab vs Mathlab vs Mathematica ? General Discussion ker2x 8 8603 Last post June 17, 2010, 04:23:20 PM
by hobold

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines

Valid XHTML 1.0! Valid CSS! Dilber MC Theme by HarzeM
Page created in 0.177 seconds with 27 queries. (Pretty URLs adds 0.007s, 2q)