%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%         6.gyakorlat         %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Nemlin. din. rsz-ek alapjai %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%        2014.11.05/06        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%          Fraktálok     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Accuracy=0.01;
epszilon=0.001;
x = -0.5: epszilon: 0.5;
y = x;
[X,Y] = meshgrid(x,y);

z0 = X + 1i*Y; %a komplex síkon vagyunk

depth = 20; %iterációk száma
for k = 1:depth
	z0 = z0 - (z0.*z0.*z0 + 1)./(3.*z0.*z0); %Newton közelítés az x^3+1=0 egyenlet megoldására
    %3 db ,megoldás van a komplex síkon: -1; 1/2+i*gyök3/2; 1/2-i*gyök3/2; 
    %z0 = z0 - (z0.*z0.*z0 -2*z0 + 2)./(3.*z0.*z0-2);
end
equ_root=roots([1 0 0 1]); %polinom gyökeinek kiszámítása
%equ_root=roots([1 0 -2 2])
%más-más értéket/színt (20,40,60) adok a pontoknak attól függõen, hogy melyik megoldáshoz jut az adott pontból indítva a rendszer 
Red=(abs(z0 - equ_root(1))<Accuracy)*60;
Green=(abs(z0 - equ_root(2))<Accuracy)*40;
Blue=(abs(z0 - equ_root(3))<Accuracy)*20;
%ami nem konvergál adott iteráció szám alatt az marad 0:= sötétkék
fraktal_abra=(Red+Green+Blue);

figure;
image(fraktal_abra); %a 3 db szín mátrixot összegzem és ábrázolom
axis xy;
xlabel('Re');
ylabel('Im');
colorbar;

%egyéb egyenletek: pl: x^3-1; x^3-2z+2 3x^2-2