matlab的Koch雪花程序怎样写啊?(不要Koch曲线的程序)

来源:百度知道 编辑:UC知道 时间:2024/07/08 04:23:50
选修了matlab,实在弄不懂这个软件

我正好收集了一个曲线程序,从mathworks主页下载的。修改一下吧。
把以下程序存为koch.m
>>koch(5)
运行。

%KOCH: Plots 'Koch Curve' Fractal
%
% koch(n) plots the 'Koch Curve' Fractal after n iterations
% e.g koch(4) plots the Koch Curve after 4 iterations.
% (be patient for n>8, depending on Computer speed)
%
% The 'kline' local function generates the Koch Curve co-ordinates using
% recursive calls, while the 'plotline' local function is used to plot
% the Koch Curve.
%
% Copyright (c) 2000 by Salman Durrani (dsalman@wol.net.pk)
%--------------------------------------------------------------------
function []=koch(n)
if (n==0)
x=[0;1];
y=[0;0];
line(x,y,'Color','b');
axis equal
set(gca,'Visible','off')
else
levelcontrol=10^n;
L=levelcontrol/(3^n);
l=ceil(L);
kline(0,0,levelcontrol,0,l