Skip to content

Newton Fractal

Oscar Veliz edited this page Nov 26, 2021 · 23 revisions

Newton Fractal video

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.

Correction to Video

Video Mistakes and How to Fix Them

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.

Examples

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.

z3 - 1

a = {1,0} #1+0*i
p(z) = z**3 - 1
dp(z) = 3*z**2

z^3-1

a = {.25,.25} #1/4+i/4

z^3-1,a=.25+.25i

z8+15z4-16

a = {1,0} #1+0*i
p(z) = z**8 + 15*z**4 - 16
dp(z) = 8*z**7 + 60*z**3

z^8-15z^4+16

a = {.5,.5}

z^8-15z^4+16halfhalfi

sin(z)

a = {1,0} #1+0*i
p(z) = sin(z)
dp(z) = cos(z)

sin(z)

centerx = pi / 2
centeri = 0
r = .05

sin(z)-zoom

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:

Coloring by Roots

Of the two contrasting images below the first is created using the provided code but you can create the second image with additional work.

z3 - 1

z^3-1 Colored Roots

z8+15z4-16

z^8-15z^4+16 Colored Roots

Instructions

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: -halfsqrtthreeover2 equalone -half-sqrtthreeover2 Then remove the background, recolor, and combine using your favorite photo editor such as Paint.NET.

Multivariable Newton Fractals

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²-y=1 ; x-y²=-1

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

phiphi phiphi-color

a = complex(0.5,0.5)

phiphi-a

x²+y²=1 ; x+2y²=1

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

circle-parabola circle-parabola-color

a = complex(0.5,0.5)

circle-parabola-a

Creating a 3D multivariable fractal

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.

Global Newton Fractals

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. globalz^3-1 globalz^3-1withi globalz^2+1 globalsystem1 globalsystem2