3Blue1Brown just released a popular video about Newton fractal.
I notice there is a build-in example under "Compiled function tools" guide in the document. This code is quite fast and it generates the fractal with high order of iteration. I put the compiled code in Manipulate to create this animation. The control is a Slider2D type. I move one root of =1 around and keep other fixed.
5
x
Compiled code
Compiled code
This part of the code are just copy and paste from the link. You need a compiler to successfully convert the code into native C code. On windows I recommend Visual studio community/professional version; On Mac OSX or Linux, you can just use the system provide compilers like XCode clang or GCC.
In[]:=
newt=Compile[{{z0,_Complex},{roots,_Complex,1},{colors,_Real,2},{maxiter,_Integer}},Module[{z=z0,terms=z0-roots,ar=Abs[roots],iter=0,rind=0,i,n=Length[roots],mind,c,r},While[(rind0)&&(iter<maxiter),Do[If[Abs[terms[[i]]]≤$MachineEpsilonar[[i]],rind=i];,{i,n}];If[rind0,z=z-(1.+0.I)/Total[(1.+0.I)/terms];terms=z-roots;iter++;]];If[rind0,ar=Abs[terms];rind=1;mind=ar[[1]];Do[If[ar[[i]]<mind,rind=i;mind=ar[[i]]];,{i,2,n}]];c=colors[[rind]];r=N[iter]/maxiter;If[r<.5,c+=(1.-2.r)*(1.-c),c=c*(1.-r)]],CompilationOptions{"InlineExternalDefinitions"True},RuntimeOptions"Speed",CompilationTarget"C"];
In[]:=
hues[n_]:=Table[Apply[List,ColorConvert[Hue[i/n],"RGB"]],{i,n}];
In[]:=
points=Table[x+(0.+1.I)y,{x,-1.,1.,.005},{y,-1.,1.,.005}];
In[]:=
wrap=Compile[{{z,_Complex},{roots,_Complex,1},{colors,_Real,2},{maxiter,_Integer}},newt[z,roots,colors,maxiter],RuntimeAttributesListable,ParallelizationTrue,CompilationOptions{"InlineExternalDefinitions"True}];
n=5;roots=N[Table[Exp[2PiIt],{t,0,1-1/n,1/n}]]
Out[]=
{1.,0.309017+0.951057,-0.809017+0.587785,-0.809017-0.587785,0.309017-0.951057}
Animation
Animation
I put the ComplexListPlot inside the fractal graphics to show the attractions and the moving root.
Manipulate[With[{ver={p.{1,I},0.309017+0.951057I,-0.809017+0.587785I,-0.809017-0.587785I,0.309017-0.951057I}},Graphics[{Raster[wrap[points,{p.{1,I},0.309017+0.951057I,-0.809017+0.587785I,-0.809017-0.587785I,0.309017-0.951057I},hues[5],30]],Dynamic@Inset[ComplexListPlot[MapThread[Callout[#1,#2]&,{ver,Range[5]}],Prolog{Transparent,EdgeForm[Dashed],Polygon[ReIm[ver]]},PlotStyle{PointSize[0.03],Yellow},PlotRange{{-1,2},{-1.5,1.5}}],{100,90}]},ImageSize->400]],{{p,{1,0}},{-2,-2},{2,2}},SynchronousUpdatingFalse]
Out[]=