2016-04-24 78 views
1

以下代码取自here情节黑白mandelbrot套装

我试图让下列更改下面的代码

如果c不是集的一部分,绘制白色 像素,如果它是一组的一部分,情节黑色像素。

我得到这样的输出: enter image description here

但我要绘制这样一个黑白的Mandelbrot图像:

enter image description here

使用imshow命令绘制你的图片

任何人都可以帮忙吗?

m=601; 
    n=401; 
    count_max = 200; 

    %Change the range of x's and y's here 
    x_max = 1; 
    x_min = - 2; 
    y_max = 1; 
    y_min = - 1; 

% 
% Create an array of complex sample points in [x_min,x_max] + [y_min,y_max]*i. 
% 
    I = (1 : m); 
    J = (1 : n); 
    X = ((I - 1) * x_max + (m - I) * x_min)/(m - 1); 
    Y = ((J - 1) * y_max + (n - J) * y_min)/(n - 1); 
    [ Zr, Zi ] = meshgrid (X, Y); 
    C = complex (Zr, Zi); 
% 
% Carry out the iteration. 
% 
    epsilon = 0.001; 

    Z = C; 
    ieps = 1 : numel (C); 

    %Iterate through 1 to maximum no. of iterations 
    for i = 1 : count_max 
    Z(ieps) = Z(ieps) .* Z(ieps) + C(ieps); 
    W(ieps) = exp (- abs (Z(ieps))); 
    ieps = ieps (find (epsilon < W(ieps))); 
    end 
% 
% Display the data. 
% 
    d = log (abs (Z)); 
    t = delaunay (Zr, Zi); 
% 
% To see individual pixels, use 'flat' color. 
% 
h = trisurf (t, Zr, Zi, d, 'FaceColor', 'flat', 'EdgeColor', 'flat'); 
% h = trisurf (t, Zr, Zi, d, 'FaceColor', 'interp', 'EdgeColor', 'interp'); 

    view (2) 
    axis equal 
    axis on 
    title_string = sprintf ('Mandelbrot set, %d x %d pixels, %d iterations', ... 
    m, n, count_max); 
    title (title_string) 
    xlabel ('Real Axis'); 
    ylabel ('Imaginary Axis'); 
% Terminate. 

回答

1

属于集合,而不是属于集合的区别是什么都没有比epsilon < W(ieps),你已经在使用,在你的代码。图中的颜色信息来自trisurf (t, Zr, Zi, d,...)的第四个参数。

因此,我建议的trisurf命令之前执行以下操作:

d(1 : numel (C)) = 1; 
d(ieps) = 0; 

该第一设置为1的所有元素,然后设置一个是该组的一部分,以零的那些元件,根据这是条件已经在收敛测试的最后一次迭代中计算出来了。

要绘制黑色和白色,只需使用colormap graytrisurf

希望有所帮助。

+0

是的,它可以告诉我如何使用'imshow'命令而不是'view(2)'查看图像? – newguy

+0

当我这样做时'imshow(h)'当我只对2D感兴趣时,我在命令窗口中看到3D视图以及一些错误消息。 – newguy

+0

@newguy为什么你想在标准图上使用'imshow'?我想你需要首先将三维数据处理成二维图像,以便使用'imshow()'。 –