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개)

Matt J
Matt J 2022년 1월 2일
편집: Matt J 2022년 1월 2일

0 개 추천

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])
ans =
-0.5000 + 0.8660i -0.5000 - 0.8660i 1.0000 + 0.0000i

댓글 수: 2

hamza kharbouch
hamza kharbouch 2022년 1월 2일
<< You seem to think z.^3-1 will have the 3 real roots,
>> oh my bad . a typo
thank u very much
Matt J
Matt J 2022년 1월 2일
You're welcome, but if the answer works for you, please Accept-click it.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Programming에 대해 자세히 알아보기

태그

질문:

2022년 1월 2일

댓글:

2022년 1월 2일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by