matlab牛顿迭代法生成分形图,编好程序后运行总是出错,但不知道错在哪里,function newton2clcm=13;a1=-2;a2=2;b1=-1.5;b2=1.5;n=3;delta=0.01;hold onfor x=a1:0.02:a2for y=b1:0.02:b2f=f_iterat(x,y,n,m,delta);if f>0switch rem(f,7)cas

来源:学生作业帮助网 编辑:作业帮 时间:2024/11/25 23:42:24
matlab牛顿迭代法生成分形图,编好程序后运行总是出错,但不知道错在哪里,function newton2clcm=13;a1=-2;a2=2;b1=-1.5;b2=1.5;n=3;delta=0.01;hold onfor x=a1:0.02:a2for y=b1:0.02:b2f=f_iterat(x,y,n,m,delta);if f>0switch rem(f,7)cas
xUnF#M=Hibzi[!"e"%)@ȣM6pA<G3d )Q4H:{;wn{M6҆?>.z<>z1?L$/Jó'ᛟݓѣRNCN~}<|;{ ]6vC+;PnHEE TTLꦪ)~0lmW벺mbAER:Z7Q(DR,aɑZ&0` `J_: 5mR3B Wr%a.|Bq|qf׊M 9.[F3\pk &~ FAYE_^sӜՙ5M+^Wq [$`-Zt WlD~2H+n P Ϙ])<*E.DQKYT x^BT".J%&$]ʂ ;0&JΑA̅a!E:a} l\˲`M7! cP 5".F;@G B|W l9跗` } VW&Kxʈ}", lf^=Tcs( 15W%U7KOil%lQ*  ;$F{EGRKPh)%(%(KP3cs }%8ңd[2r,ŲNGzDj~ٳhpG 3)9;I? O~K>> ֩cyP6*KGRn`O)h.XMng̰}Zڳ| [)t˞ -4</|v-n7/

matlab牛顿迭代法生成分形图,编好程序后运行总是出错,但不知道错在哪里,function newton2clcm=13;a1=-2;a2=2;b1=-1.5;b2=1.5;n=3;delta=0.01;hold onfor x=a1:0.02:a2for y=b1:0.02:b2f=f_iterat(x,y,n,m,delta);if f>0switch rem(f,7)cas
matlab牛顿迭代法生成分形图,编好程序后运行总是出错,但不知道错在哪里,
function newton2
clc
m=13;a1=-2;a2=2;b1=-1.5;b2=1.5;n=3;
delta=0.01;
hold on
for x=a1:0.02:a2
for y=b1:0.02:b2
f=f_iterat(x,y,n,m,delta);
if f>0
switch rem(f,7)
case 0
plot(x,y,'w.');
case 1
plot(x,y,'b.');
case 2
plot(x,y,'r.');
case 3
plot(x,y,'y.');
case 4
plot(x,y,'g.') ;
case 5
plot(x,y,'c.') ;
case 6
plot(x,y,'m.');
end
end
end
end
hold off
function f=f_iterat(x,y,n,m,delta)
f=0;
for k=1:m
p=sqrt(x*x+y*y);
seta=f_arg(x,y);
x2=((n-1)*p*cos(seta)+p^(1-n)*cos((1-n)*seta))/2;
y2=((n-1)*p*sin(seta)+p^(1-n)*sin((1-n)*seta))/2;
dis=sqrt((x2-x)^2+(y2-y)^2);
if dis=0
seta=pi/2;
else
seta=-pi/2;
end
elseif x>0
seta=atan(y/x);
elseif x=0
seta=pi+atan(y/x);
elseif xf_arg at 48
if x==0
Output argument "seta" (and maybe others) not assigned during call to "C:\Documents
and Settings\liuxm\桌面\分形图的matlab生成\newton2.m>f_arg".
Error in ==> newton2>f_iterat at 35
seta=f_arg(x,y);
Error in ==> newton2 at 8
f=f_iterat(x,y,n,m,delta);

matlab牛顿迭代法生成分形图,编好程序后运行总是出错,但不知道错在哪里,function newton2clcm=13;a1=-2;a2=2;b1=-1.5;b2=1.5;n=3;delta=0.01;hold onfor x=a1:0.02:a2for y=b1:0.02:b2f=f_iterat(x,y,n,m,delta);if f>0switch rem(f,7)cas

function newton2
clc
m=13;
a1=-2;
a2=2;
b1=-1.5;
b2=1.5;
n=3;
delta=0.01;
hold on
for x=a1:0.02:a2
for y=b1:0.02:b2
f=f_iterat(x,y,n,m,delta);
if f>0
switch rem(f,7)
case 0
plot(x,y,'w.');
case 1
plot(x,y,'b.');
case 2
plot(x,y,'r.');
case 3
plot(x,y,'y.');
case 4
plot(x,y,'g.') ;
case 5
plot(x,y,'c.') ;
case 6
plot(x,y,'m.');
end
end
end
end
hold off
end
function f=f_iterat(x,y,n,m,delta)
f=0;
for k=1:m
p=sqrt(x*x+y*y);
if p==0 %修正1:为避免出现inf值,强制给个极小值
p=1e-9;
end
seta=f_arg(x,y);
x2=((n-1)*p*cos(seta)+p^(1-n)*cos((1-n)*seta))/2; %x,y=0时p^(1-n)出现inf
y2=((n-1)*p*sin(seta)+p^(1-n)*sin((1-n)*seta))/2; %同bug
dis=sqrt((x2-x)^2+(y2-y)^2);
if dis=0
seta=pi/2;
else
seta=-pi/2;
end
elseif x>0
seta=atan(y/x);
elseif x=0
seta=pi+atan(y/x);
elseif x