24小时热门版块排行榜    

CyRhmU.jpeg
查看: 3031  |  回复: 5

我要飞

铁虫 (正式写手)

[求助] 求助matlab里面画出x^3-1=0的Newton迭代的吸引域的程序

求助matlab里面画出x^3-1=0的Newton迭代的吸引域的程序
回复此楼

» 猜你喜欢

» 本主题相关价值贴推荐,对您同样有帮助:

已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

dbb627

荣誉版主 (著名写手)

【答案】应助回帖

CODE:
function AA
p=f(-1/2-sqrt(3)/2*i , -1/2+sqrt(3)/2*i, 1)


function p=f(A,B,C)
%>>p=f(-1/2-sqrt(3)/2*i , -1/2+sqrt(3)/2*i, 1)
h=0.01;
for a=-1:h:1
for b=-1:h:1
x0=a+b*i;
y=newton(x0);
if abs(y-A)<1.0e-6
plot(a,b,'r.');
hold on
elseif abs(y-B)<1.0e-6
plot(a,b,'g.');
hold on
elseif abs(y-C)<1.0e-6
plot(a,b,'y.');
hold on
end
end
end

p=0;


function y=newton(z)

if (z==0)
y=0;
return;
end

for i=1:1:2000
y=z-(z^3-1)/(3*z^2);
if(abs(y-z)<1.0e-7)
break;
end
z=y;
end

复制到editor中运行
图形如下


The more you learn, the more you know, the more you know, and the more you forget. The more you forget, the less you know. So why bother to learn.
2楼2011-10-16 14:13:12
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

锐利的碎片

木虫 (正式写手)

star watcher


dbb627(金币+1): 确实重了,多谢交流 2011-10-16 23:35:26
3楼2011-10-16 19:15:48
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

我要飞

铁虫 (正式写手)

??? function AA
    |
Error: Function definitions are not permitted at the prompt or in scripts.
你给的程序不对呀,出像上面这样的错呀
4楼2011-10-17 11:54:02
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

dbb627

荣誉版主 (著名写手)

【答案】应助回帖

我要飞(金币+10): 2011-10-19 19:01:17
引用回帖:
4楼: Originally posted by 我要飞 at 2011-10-17 11:54:02:
??? function AA
    |
Error: Function definitions are not permitted at the prompt or in scripts.
你给的程序不对呀,出像上面这样的错呀

我已经说了要在editor中保存为m文件运行
具体方法 在命令窗口输入edit 会弹出editor窗口,将代码复制,并保存在当前目录下,点击edito菜单中的run按钮

出现?? function AA
    |
Error: Function definitions are not permitted at the prompt or in scripts.

是你直接在命令窗口运行代码导致的
The more you learn, the more you know, the more you know, and the more you forget. The more you forget, the less you know. So why bother to learn.
5楼2011-10-19 14:17:26
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

yf_2011

铁虫 (初入文坛)

你好,matlab初学者,要画吸引域,但是不知道怎么画啊,程序保存为m文件后运行没有图像出来啊,谢谢了
6楼2012-06-07 21:43:51
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 我要飞 的主题更新
信息提示
请填处理意见