在Matlab中为Mandelbrot着色 [英] Coloring the Mandelbrot set in Matlab

查看:226
本文介绍了在Matlab中为Mandelbrot着色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了一个程序来计算mandelbrot集中的点.对于不属于mandelbrot集合的点,我跟踪起始点发散到幅度大于2的位置需要进行多少次迭代.基本上,对于不在mandelbrot集合中的每个点,我都有一个计数器,它有多快散度范围为1到256.id想要做的就是根据散度的快慢为每个点赋予颜色.例如,在255次迭代中发散的点可能是白色的,发散得越快,它所着色的越多.我进行了一个简单的调整,将超过20步的发散点显示为红色,将10-19步发散的点显示为蓝色,将5-9步发散的点显示为黄色,如下所示. /p>

现在我无法对所有可能的255分度进行此操作.我该如何制作一个毕业规模并在Matlab中实现它.在此先感谢您的帮助.如果有人想知道更多,请询问.谢谢!

编辑很抱歉,该图片似乎无法正常运行.基本上我需要这个.我正在绘制点,为每个点分配一个介于1和255之间的值,并且我希望颜色根据分配给它的值逐渐变化.谢谢!

解决方案

在Matlab中绘制mandelbrot集的简单方法如下

function mandelbrot(n, niter)

x0 = -2;   x1 = 1;
y0 = -1.5; y1 = 1.5;

[x,y] = meshgrid(linspace(x0, x1, n), linspace(y0, y1, n));

c = x + 1i * y;
z = zeros(size(c));
k = zeros(size(c));

for ii = 1:niter
    z   = z.^2 + c;
    k(abs(z) > 2 & k == 0) = niter - ii;
end

figure,
imagesc(k),
colormap hot
axis square

这只是跟踪迭代次数,直到在数组k中发散为止,并使用线性色标通过imagesc对其进行绘制.结果是

>> mandelbrot(800, 40)

I made a program to calculate points that are in the mandelbrot set. For the points not belonging to the mandelbrot set I keep track of how many iterations it take for the starting point to diverge to where the magnitude is greater that 2. Basically for every point not in the mandelbrot set I have a counter of how fast it diverges on a scale of 1 to 256. What id like to do is give each point a color according to how fast it diverges. For instance the points that diverge in 255 iterations could be white and the faster it diverges the more it gets colored. I've made an easy adjustment where diverging points that diverge in more than 20 steps are colored red, the ones that diverge in 10-19 steps are blue and one that diverge in 5-9 steps are yellow and it looks like this.

Now I cant do this for all possible 255 rates of divergence. How can I make a graduating scale and implement it in Matlab. Thanks in advance for any help. If anyone would like to know any more please ask. Thanks!

EDIT I am sorry but the image seems to not work. Basically what I need it this. I am plotting points, to each point a value between 1 and 255 is assigned and I want the color to gradually change depending on the value assigned to it. Thanks!

解决方案

A simple approach to plotting the mandelbrot set in Matlab is as follows

function mandelbrot(n, niter)

x0 = -2;   x1 = 1;
y0 = -1.5; y1 = 1.5;

[x,y] = meshgrid(linspace(x0, x1, n), linspace(y0, y1, n));

c = x + 1i * y;
z = zeros(size(c));
k = zeros(size(c));

for ii = 1:niter
    z   = z.^2 + c;
    k(abs(z) > 2 & k == 0) = niter - ii;
end

figure,
imagesc(k),
colormap hot
axis square

This just keeps track of the number of iterations until divergence in the array k, and plots it using a linear color scale by using imagesc. The result is

>> mandelbrot(800, 40)

这篇关于在Matlab中为Mandelbrot着色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆