一段画牛顿迭代收敛域的matlab程序,%% Perform Newton iterationsfor k=1:maxIter;Z=Z-(f(Z,d)./fprime(Z,d));endfunction y=f(x,d);y=(x.^d)-1;endfunction y=fprime(x,d);y=d*(x.^(d-1));end%% Find d roots of unity,and the maskfor j=1:d root=exp(2*
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/16 01:38:24
一段画牛顿迭代收敛域的matlab程序,%% Perform Newton iterationsfor k=1:maxIter;Z=Z-(f(Z,d)./fprime(Z,d));endfunction y=f(x,d);y=(x.^d)-1;endfunction y=fprime(x,d);y=d*(x.^(d-1));end%% Find d roots of unity,and the maskfor j=1:d root=exp(2*
一段画牛顿迭代收敛域的matlab程序,
%% Perform Newton iterations
for k=1:maxIter;
Z=Z-(f(Z,d)./fprime(Z,d));
end
function y=f(x,d);
y=(x.^d)-1;
end
function y=fprime(x,d);
y=d*(x.^(d-1));
end
%% Find d roots of unity,and the mask
for j=1:d
root=exp(2*pi*i/d)^j; % the jth root
Mj=abs(Z-root); % distance
% Each root gets a unique number in [1,d]
mask=(Mj
一段画牛顿迭代收敛域的matlab程序,%% Perform Newton iterationsfor k=1:maxIter;Z=Z-(f(Z,d)./fprime(Z,d));endfunction y=f(x,d);y=(x.^d)-1;endfunction y=fprime(x,d);y=d*(x.^(d-1));end%% Find d roots of unity,and the maskfor j=1:d root=exp(2*
%% set para
d=6;
tol=1e-5;
maxIter=100;
r=-2:0.01:2; %实部虚部的范围
[x y]=meshgrid(r); %产生实部虚部二维网格
Z=x+1i*y; %Z对应网格的虚平面
%% Define fuction
f=@(x,d) (x.^d)-1;
fprime=@(x,d) d*(x.^(d-1));
%% Perform Newton iterations
for k=1:maxIter;
Z=Z-(f(Z,d)./fprime(Z,d));
end
%% Find d roots of unity, and the mask
renderMat=0;
for j=1:d
root=exp(2*pi*1i/d)^j; % the jth root
Mj=abs(Z-root); % distance Z中每点都这个根的距离
% Each root gets a unique number in [1,d]
mask=(Mj<=tol)*j; %Mj<=tol返回满足误差的逻辑矩阵
%满足误差部分为1*j,不满足部分为0
renderMat=renderMat+mask;
%加起来之后renderMat中收敛于第j个根的区域数据都是j
%那么收敛于第j个根的区域都是同一种颜色
end
colormap(hsv(d+1)); % Set the color map
imagesc(r,r,renderMat) % Render the fractal
xlabel('Re(Z)');ylabel('Im(Z)');
h=colorbar;
set(h,'ytick',(2*(0:d)+1)*d/(d+1)/2);
str=arrayfun(@(x)num2str(x,'%.2f'),exp(2*pi*1i/d).^(1:d),'uniformoutput',false);
set(h,'yticklabel',[{'未收敛'},str]);