Newton Fractal, roots of equation z 4=1

Asked

Viewed 523 times

5

I’m trying to plot a graph of an image called Newton Fractal:

Newton Fractal

Follows model:

The problem is to plot the roots of the equation z^4 = 1, where it has 4 roots being (-1, 1, i and -i), where to find the roots I use Newton’s method to make the approximation.

The different colors (red, green, yellow or blue) in the image mean which root Newton’s method is approaching (and black if it’s not any), but I’m not getting the code that generates the image. I’m using Scilab which is very similar to Matlab.

Follow what I’ve managed to do:

function [z] = f(x,y)
    clc
    f(x,y) = z^4 -1 = 0;
    f1(x,y) = 4*z^3;
    niter = 100;
    x0 = 0.5;

    for i=1:niter
        for j=1:niter;
    end

   [X,Y] = meshgrid(x,y);

    Z(i,j) = f(x(i), y(j) );
  end
end

surf(X,Y,Z)
endfunction.
  • 3

    Look, I personally know almost nothing about Matlab, but looking at his code, it seems to me that the end the inner loop is in the wrong place.

1 answer

2

Made in Matlab

%Cria matriz de valores iniciais
[X,Y]=meshgrid(-1:.002:1,-1:.002:1);
Z=X+i*Y;

%Cria funções
f=@(z) z.^4-1;
fp=@(z) 4*z.^3;

plot(Z,'.');

%NEWTON RAPHSON
for k=1:50
    Z=Z-f(Z)./fp(Z);
end

z=[1 i -1 -i]; %Raízes

%A matriz W contém o número da raíz que cada elemento Z converge 
W=5*ones(size(Z));%Cria matriz W

%Aproxima cada raiz
for k=1:4, 
    I=(abs(Z-z(k))<.3); 
    W(I)=k;
end 

%Cria o mapa de cores referentes as raizes
cmap=[0 0 1;1 0 0;0 1 0;1 1 0;0 0 0]; %[Azul;Vermelho;Verde;Amarelo;Preto]
%OS pontos que não convergem estarão em preto
%define o mapa de cores
colormap(cmap);
%Usando o mapa de cores cria imagem (W)
pcolor(X,Y,W),shading flat

And if you want to leave the image with shadows just follow the described link

http://www.chiark.greenend.org.uk/~sgtatham/Newton/

For more information:

http://www.mathworks.com/matlabcentral/newsreader/view_thread/257685

Browser other questions tagged

You are not signed in. Login or sign up in order to post.