分形中的 Julia 集和 Mandelbrot 集(只是记一下代码)

1.Julia集分形图的MATLAB程序

function Julia(c,k,v)
if nargin < 3 %当输入的参数小于3时,自动赋值
    c = 0.2 + 0.65i;
    k = 14;
    v = 500;
end
r = max(abs(c),2); %设置发散点所超出的圆的半径
d = linspace(-r,r,v);
A = ones(v,1)*d + i * (ones(v,1)*d)';
B = zeros(v,v);
for s=1:k %迭代
    B = B + (abs(A) <= r);
    A = A.*A + ones(v,v).* c;
end
imagesc(B); %绘图
colormap(jet); %着色
axis equal
axis off

>>>Julia(0.2+0.65i,14,500)

2.Mandelbrot集分形图的MATLABL程序

function Mandelbrot(iter,pixel)
switch nargin
    case 0
        iter=23;   %迭代次数
    pixel=400;     %横坐标的点数
end
r = 3/4;
x = linspace(-2.5,1.5,pixel);    %生成向量
y = linspace(-1.5,1.5,round(pixel*r)');     %生成包含所有像素点的矩形
[Re,Im] = meshgrid(x,y);
C = Re + i * Im;
B = zeros(round(pixel*r),pixel);
Cn = B;   %C0=0+0i
for l=1:iter
    Cn = Cn.*Cn + C;
    B = B + (abs(Cn < 2));
end;
imagesc(B);
colormap(jet);  %着色
axis equal
axis off

    

>>>Mandelbrot(23,400)

猜你喜欢

转载自blog.csdn.net/Enderman_xiaohei/article/details/87944718
今日推荐