资源描述:
《科赫雪花曲线的MATLAB编程实现.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、科赫雪花曲线的MATLAB编程实现2.1经一次迭代的科赫曲线MATLAB实现程序如下:x1=[122.534];y1=[00000];h1=plot(x1,y1,'linewidth',2,'erasemode','xor');axisequalaxisoffforg=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);fork=2:length(x1);t=linspace(x1(k-1),x1
2、(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];endA=angle((y2(4:4:end)-y2(2:4:end))*i+(x2(4:4:end)-x2(2:4:end)));forg=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
3、:4:end))/2+real(g*exp(i*(A+pi/2)));set(h1,'ydata',y2,'xdata',x2);drawnow;end二次迭代后所得科赫曲线如图二:图二2.3经三次迭代的科赫曲线MATLAB实现程序如下x3=x2(1);y3=y2(1);fork=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];endA=angle((y3(4:4
4、:end)-y3(2:4:end))*i+(x3(4:4:end)-x3(2:4:end)));forg=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.4经四次迭代的科赫曲线MATLAB实现程序如下x4=x3(1
5、);y4=y3(1);fork=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];endA=angle((y4(4:4:end)-y4(2:4:end))*i+(x4(4:4:end)-x4(2:4:end)));forg=linspace(0,1,40)*sin(pi/3)/27;y4(3:4:end)=(y4(4:4:end)+y4(2:4:end))/2+im
6、ag(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四次迭代后所得科赫曲线如图四:图四2.5经五次迭代的科赫曲线MATLAB实现程序如下x5=x4(1);y5=y4(1);fork=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=
7、[t(2),mean(t),t(3:4)];y5=[y5,tt];endA=angle((y5(4:4:end)-y5(2:4:end))*i+(x5(4:4:end)-x5(2:4:end)));forg=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