-
-
Notifications
You must be signed in to change notification settings - Fork 21
Newton Fractal
The video covering Newton Fractals can be found here https://youtu.be/MWD2A0Vg2V0. Code to generate these fractals is given in NewtonFractal.plt written in gnuplot. To run the program have gnuplot installed (gnuplot.info) then type gnuplot NewtonFractal.plt
in the terminal in the directory where NewtonFractal.plt is saved. Alternatively, open the gnuplot app then go to File > Open and select the NewtonFractal.plt file, or from gnuplot cd
to correct directory and then type load 'NewtonFractal.plt'
. The fractal will be generated and stored in NewtonFractal.png and can take a while depending on the number of iterations, function complexity, and resolution. You can edit the .plt file using any text editor though I would recommend VS Code with the gnuplot syntax highlighting extension. Multivariable Newton Fractal instructions are on bottom of page.
The derivative of the arctangent in the Newton Fractal video is incorrect however this error is only in the slides not in the numerical examples and fractal images.
The following fractals were created using the following functions and settings normally centered at 0 + 0i with r of 2 and a 16:9 ratio.
a = {1,0} #1+0*i
p(z) = z**3 - 1
dp(z) = 3*z**2
a = {.25,.25} #1/4+i/4
a = {1,0} #1+0*i
p(z) = z**8 + 15*z**4 - 16
dp(z) = 8*z**7 + 60*z**3
a = {.5,.5}
a = {1,0} #1+0*i
p(z) = sin(z)
dp(z) = cos(z)
centerx = pi / 2
centeri = 0
r = .05
Complex numbers like 0 + i are defined in gnuplot like {0,1}
and can be used in normal operations such as multiplication and addition as well as in functions like sin and abs. Examples of and documentation on color palettes can be found at pm3dcolors. The complete gnuplot documentation can be found at gnuplot.info/documentation.html or by typing help
from inside gnuplot.
Reference links:
- Numerical Recipes http://numerical.recipes/
- Wikipedia: Newton Fractal https://en.wikipedia.org/wiki/Newton_fractal
Of the two contrasting images below the first is created using the provided code but you can create the second image with additional work.
Change the palette to gray using set palette gray
. Then alter the ending condition of abs(p(z)) < 0.0000001
to abs(z - solution) < 0.0000001
where solution
is a root of the polynomial such as solution = {-0.5,0} - sqrt(3)/2*{0,1}
which would create the following images:
Then remove the background, recolor, and combine using your favorite photo editor such as Paint.NET.
To find the new Iteration Function for each system of nonlinear equations it is recommended that you use the symbolic programming example program from the Generalized Newton's Method video to solve for these. You can run the program online here with source code here and documentation here.
#x^2-y-1=0
#x-y^2+1=0
cx(x,y) = x - a * ( (2*y)*(x**2-y-1)/(4*x*y-1) - (x-y**2+1)/(4*x*y-1) )
cy(x,y) = y - a * ( (-2*x*(x-y**2+1))/(4*x*y-1) + (x**2-y-1)/(4*x*y-1) )
a = complex(0.5,0.5)
#x^2+y^2-1=0
#x+2*y^2-1=0
cx(x,y) = x - a * ( (-2*y)*(-x-2*y**2+1)/(-8*x*y+2*y) - 4*y*(x**2+y**2-1)/(-8*x*y+2*y) )
cy(x,y) = y - a * ( (-2*x*(-x-2*y**2+1))/(8*x*y-2*y) - (x**2+y**2-1)/(8*x*y-2*y) )
a = complex(0.5,0.5)
Create 3 square slices without ticks one for each variable set to zero. Setting i=0
is the default by only plotting in the x and y. Set x=0
by using complex(0,x)
in place of x
in the splot
. Use the same process for y=0
. It is best to rename the resulting images to keep track of which image is which plane. Then run the provided MATLAB / GNU Octave code found here to create a 3D model by combining the slices. Press any key to start the camera rotation.
Following programs work similar to those described above. Video covering the global newton method can be found here. Code can be found here and here.