Newton-Raphson fractal script problem
이전 댓글 표시
matlab doesn't give results to this script and keeps running it non stop (i waited for +10 min)
any thoughts ?
f = @(z) z.^3-1;
df = @(z) 3*z.^2;
e = 0.00001;
x=-3:0.001:3;
y=x*1i;
[r,k]=ndgrid(x,y);
z=r+k; % setting a complexe plane
for i=1:6000
for j=1:6000
while f(z(i,j))<e %newton methode
dorime(i,j)=z(i,j)-f(z(i,j))/df(z(i,j));
end
end
end
%coloring in white,black,grey
if abs(dorime(i,j)-(-1+sqrt(3))/2) <e
fractale (i,j)=1;
end
if dorime (i,j)-1<e
fractale (i,j)=1/2;
end
if abs(dorime(i,j)-(-1-sqrt(3))/2) <e
fractale (i,j)=0;
end
% showing the fractal
imshow(fractal);
답변 (1개)
I would recommend doing the Newton's method iterations as below.
f = @(z) z.^3-1;
df = @(z) 3*z.^2;
e = 0.00001;
x=-3:0.001:3;
y=x*1i;
[r,k]=ndgrid(x,y);
z=r+k; % setting a complexe plane
maxiter=15;
iter=0;
while any( abs ( f(z) ) > e ,'all') && iter < maxiter %newton methode
z=z-f(z)./df(z);
iter=iter+1
end
dorime=z;
The rest of the code, I don't understand. You seem to think z.^3-1 will have the 3 real roots,
z = [ (-1-sqrt(3))/2) 1 (-1+-sqrt(3))/2)]
but it doesn't
roots([1 0 0 -1])
댓글 수: 2
hamza kharbouch
2022년 1월 2일
Matt J
2022년 1월 2일
You're welcome, but if the answer works for you, please Accept-click it.
카테고리
도움말 센터 및 File Exchange에서 Programming에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!