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/12/19 04:20:08
matlab牛顿迭代法生成分形图,编好程序后运行总是出错,但不知道错在哪里,functionnewton2clcm=13;a1=-2;a2=2;b1=-1.5;b2=1.5;n=3;delta=0.0

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