科赫雪花曲线的MATLAB编程实现

更新时间:2023-09-16 04:05:01 阅读量: 高中教育 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

科赫雪花曲线的MATLAB编程实现

2.1 经一次迭代的科赫曲线 MATLAB实现程序如下: x1=[1 2 2.5 3 4]; y1=[0 0 0 0 0];

h1=plot(x1,y1,'linewidth',2,'erasemode','xor'); axis equal axis off

for g=linspace(0,1,40)*sin(pi/3); y1(3)=g;

set(h1,'ydata',y1); drawnow; end

一次迭代所得科赫曲线如图一: 图一:

2.2 经二次迭代的科赫曲线

MATLAB 实现程序如下: x2=x1(1); y2=y1(1);

for k=2:length(x1);

t=linspace(x1(k-1),x1(k),4) ; tt=[t(2),mean(t),t(3:4)]; x2=[x2,tt];

t=linspace(y1(k-1),y1(k),4); tt=[t(2),mean(t),t(3:4)]; y2=[y2,tt]; end

A=angle((y2(4:4:end)-y2(2:4:end))*i+(x2(4:4:end)-x2(2:4:end))); for g=linspace(0,1,40)*sin(pi/3)/3;

y2(3:4:end)=(y2(4:4:end)+y2(2:4:end))/2+imag(g*exp(i*(A+pi/2))); x2(3:4:end)=(x2(4:4:end)+x2(2:4:end))/2+real(g*exp(i*(A+pi/2))) ; set(h1,'ydata',y2,'xdata',x2); drawnow; end

二次迭代后所得科赫曲线如图二: 图二

1

2.3 经三次迭代的科赫曲线 MATLAB 实现程序如下 x3=x2(1); y3=y2(1);

for k=2:length(x2);

t=linspace(x2(k-1),x2(k),4); tt=[t(2),mean(t),t(3:4)]; x3=[x3,tt];

t=linspace(y2(k-1),y2(k),4); tt=[t(2),mean(t),t(3:4)]; y3=[y3,tt]; end

A=angle((y3(4:4:end)-y3(2:4:end))*i+(x3(4:4:end)-x3(2:4:end))); for g=linspace(0,1,40)*sin(pi/3)/9;

y3(3:4:end)=(y3(4:4:end)+y3(2:4:end))/2+imag(g*exp(i*(A+pi/2))); x3(3:4:end)=(x3(4:4:end)+x3(2:4:end))/2+real(g*exp(i*(A+pi/2))); set(h1,'ydata',y3,'xdata',x3); drawnow; end

三次迭代后所得科赫曲线如图三: 图三

2

2.4经四次迭代的科赫曲线 MATLAB 实现程序如下 x4=x3(1); y4=y3(1);

for k=2:length(x3);

t=linspace(x3(k-1),x3(k),4); tt=[t(2),mean(t),t(3:4)]; x4=[x4,tt];

t=linspace(y3(k-1),y3(k),4); tt=[t(2),mean(t),t(3:4)]; y4=[y4,tt]; end

A=angle((y4(4:4:end)-y4(2:4:end))*i+(x4(4:4:end)-x4(2:4:end))); for g=linspace(0,1,40)*sin(pi/3)/27;

y4(3:4:end)=(y4(4:4:end)+y4(2:4:end))/2+imag(g*exp(i*(A+pi/2))); x4(3:4:end)=(x4(4:4:end)+x4(2:4:end))/2+real(g*exp(i*(A+pi/2))); set(h1,'ydata',y4,'xdata',x4); drawnow; end

四次迭代后所得科赫曲线如图四: 图四

3

2.5 经五次迭代的科赫曲线 MATLAB 实现程序如下 x5=x4(1); y5=y4(1);

for k=2:length(x4);

t=linspace(x4(k-1),x4(k),4); tt=[t(2),mean(t),t(3:4)]; x5=[x5,tt];

t=linspace(y4(k-1),y4(k),4); tt=[t(2),mean(t),t(3:4)]; y5=[y5,tt]; end

A=angle((y5(4:4:end)-y5(2:4:end))*i+(x5(4:4:end)-x5(2:4:end))); for g=linspace(0,1,40)*sin(pi/3)/81;

y5(3:4:end)=(y5(4:4:end)+y5(2:4:end))/2+imag(g*exp(i*(A+pi/2))); x5(3:4:end)=(x5(4:4:end)+x5(2:4:end))/2+real(g*exp(i*(A+pi/2))); set(h1,'ydata',y5,'xdata',x5); drawnow; end

五次迭代后所得科赫曲线如图五: 图五

4

5

本文来源:https://www.bwwdw.com/article/nl5h.html

Top