Newton`s Method and the Newton Fractal

Newton`s Method and the Newton Fractal
Newton’s Method and the
Newton Fractal
Author: Anthony Chiu
Supervisor: Dr. Graham Gough
BSc. Computer Science and Mathematics
School of Computer Science
The University of Manchester
Abstract
Newton’s Method is a numerical method for root-finding, defined by
f (xn )
xn+1 = xn − 0
f (xn )
When x0 is ‘sufficiently close’ to a root, Newton’s method
usually converges quadratically. However, in some cases the
choice of x0 will lead to Newton’s method converging to a root
further away, or not converge to a root at all.
When analysing this behaviour in the complex plane and
colouring each point in the plane according to the root it
converges to, it becomes apparent that the method exhibits
fractal nature. These coloured objects are called “Newton
fractals”.
The system created for this project draws Newton fractals for
many choices of f and has enabled some interesting investigations into Newton fractals.
i
Acknowledgements
I would like to express my gratitude to my supervisor, Graham
Gough, for his guidance throughout this project.
I would also like to thank my good friend Simon Loach for
proofreading this report and providing suggestions for improvements, James Montaldi for suggesting this project in
the first place, and my family and friends for their constant
support and encouragement.
ii
Contents
1 Introduction
1.1 Newton’s method . . . . . . . . . . . . . . .
1.1.1 Problems with Newton’s method . .
1.2 Newton fractals . . . . . . . . . . . . . . . .
1.2.1 Fractals . . . . . . . . . . . . . . . .
1.2.2 Basic construction of Newton fractals
1.3 The project . . . . . . . . . . . . . . . . . .
1.4 Report overview . . . . . . . . . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
2 Background
2.1 Overview . . . . . . . . . . . . . . . . .
2.2 Terminology . . . . . . . . . . . . . . .
2.2.4 Petals . . . . . . . . . . . . . .
2.2.5 Branches . . . . . . . . . . . . .
2.3 Existing systems . . . . . . . . . . . .
2.3.1 Features and capabilities . . . .
2.3.2 Comparison of existing systems
2.3.3 Required features . . . . . . . .
2.4 Proposal of features for a new system .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
6
. 6
. 6
. 6
. 7
. 8
. 8
. 10
. 10
. 10
3 Design
3.1 Overview . . . . . . . . . . . . .
3.2 Functional requirements . . . .
3.2.1 Component interactions
3.3 Non-functional requirements . .
3.4 Class diagram . . . . . . . . . .
3.5 GUI design . . . . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
12
12
12
13
13
14
14
.
.
.
.
.
.
.
.
17
17
17
17
17
17
17
18
18
.
.
.
.
.
.
4 Implementation
4.1 Overview . . . . . . . . . . . . . .
4.2 Technology choices . . . . . . . .
4.2.1 Programming language . .
4.2.2 Fractal drawing . . . . . .
4.2.3 String parsing . . . . . . .
4.2.4 Development environment
4.2.5 Dependencies . . . . . . .
4.2.6 Platform . . . . . . . . . .
iii
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
1
1
1
2
2
2
3
5
Contents
Contents
4.3
Drawing a fractal . . . . . . . . . . . . . . .
4.3.1 Time complexity . . . . . . . . . . .
4.4 Panning and zooming around the fractal . .
4.4.1 Panning . . . . . . . . . . . . . . . .
4.4.2 Zooming . . . . . . . . . . . . . . . .
4.5 Parsing strings as functions . . . . . . . . .
4.6 Evaluating functions . . . . . . . . . . . . .
4.7 Changing tolerance and maximum iterations
4.7.1 Increasing maximum iterations . . .
4.7.2 Decreasing maximum iterations . . .
4.7.3 Decreasing tolerance . . . . . . . . .
4.8 Orbits and periodic points . . . . . . . . . .
4.8.1 Drawing orbits . . . . . . . . . . . .
4.8.2 Periodic points . . . . . . . . . . . .
4.9 Exploring different branches . . . . . . . . .
4.9.1 Monomials with complex powers . . .
4.9.2 Selecting a branch in C++ . . . . . .
4.10 Summary . . . . . . . . . . . . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
18
18
19
20
20
21
22
23
23
24
24
24
24
24
25
25
26
27
5 Results
5.1 Overview . . . . . . . . . . . . . . . . . . . . . . . .
5.2 Drawing basic fractals . . . . . . . . . . . . . . . .
5.2.1 Changing the function . . . . . . . . . . . .
5.2.2 Changing maximum iterations and tolerance
5.3 Panning and zooming . . . . . . . . . . . . . . . . .
5.4 Orbits . . . . . . . . . . . . . . . . . . . . . . . . .
5.5 More interesting functions . . . . . . . . . . . . . .
5.5.1 Trigonometric functions . . . . . . . . . . .
5.5.2 Polynomials with complex powers . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
28
28
28
29
30
30
35
35
35
37
6 Testing and Evaluation
6.1 Overview . . . . . . . . . . . . . . . . . .
6.2 Function parser . . . . . . . . . . . . . .
6.2.1 Creating mathematical functions
6.2.2 Polynomial derivative . . . . . . .
6.3 Fractals . . . . . . . . . . . . . . . . . .
6.3.1 Basic fractal drawing . . . . . . .
6.3.2 Panning, zooming etc. . . . . . .
6.3.3 Automatic root finding . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
38
38
38
38
38
38
38
40
41
.
.
.
.
.
.
42
42
42
42
44
45
45
7 Conclusions
7.1 Overview . . . . . . . .
7.2 Achievements . . . . .
7.2.1 Targets met . .
7.2.4 Missing features
7.3 Further work . . . . .
7.3.1 Function parser
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
iv
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Contents
7.3.2
Contents
More multivalued functions . . . . . . . . . . . . . . . . . . . 45
8 Appendix A: Project Plan
47
Bibliography
52
v
Chapter 1
Introduction
1.1
Newton’s method
Newton’s Method (or the Newton-Raphson method) is a numerical method for finding the roots of a function f , defined by
xn+1 = xn −
f (xn )
.
f 0 (xn )
If f is a function of the real numbers Newton’s method can be illustrated graphically by drawing the tangent line to f at (xn , f (xn )). xn+1 takes the value where
the tangent line intersects the x-axis.
An example is illustrated in Figure 1.1.
Figure 1.1: Graphical representation of Newton’s method.
1.1.1
Problems with Newton’s method
With a ‘well chosen’ initial guess of x0 , Newton’s method converges quadratically.
If x0 is not ‘well chosen’, Newton’s method may not converge to the nearest root.
In some cases, Newton’s method will not converge at all. This usually occurs when
x0 is in the vicinity of a local extremum [14]. The first graph in Figure 1.2 shows
that when xn is near a local extremum it may not converge to the root to the nearest
root.
1
Chapter 1. Introduction
1.2. Newton fractals
The second graph shows the worst case scenario for Newton’s method, where
(xm , f (xm )) is a local extremum. If xm is not a root, it is clear that the tangent line
will never meet the x-axis, so Newton’s method will not converge at all1 .
Figure 1.2: Points near critical points are not ‘well-behaved’.
1.2
Newton fractals
The behaviour of Newton’s method can be captured in a coloured diagram. The
colour shows which root a point converges to, and the shading shows how quickly it
converges. We will see in Example 1.2.3 that these coloured diagrams are fractals.
1.2.1
Fractals
Although there is no universally accepted definition of a fractal [1], it is possible to
identify one by some properties. Two of these properties [10] are:
• A fractal is self-similar - subsets “look like” rescaled versions of larger parts
of the fractal.
• A fractal has an arbitrarily fine structure - more detail is revealed when magnified.
1.2.2
Basic construction of Newton fractals
Given a domain D and a function f : D → D, assign each root ri of f with a colour
ci . Choose a colour cnot to represent non-convergence.
For each2 x ∈ D we perform Newton’s method on f . If x converges to a root
ri in s steps, assign x with the colour ci , adjusting its brightness of the colouring
depending on s. If x does not converge to a root, assign x with the colour cnot .
This method creates an object which demonstrates the dynamical behaviour of
Newton’s method. When analysed in a little detail it is easy to see that this object
is actually a fractal.
m)
For these points we know that f 0 (xm ) = 0, so it impossible to compute ff0(x
(xm ) .
2
Of course it is usually impossible to go through all elements in D. It is much easier to consider
the points as pixels on a computer screen.
1
2
Chapter 1. Introduction
1.3. The project
Example 1.2.3. Define f : R → R by f (x) = −2x3 + 9x2 − 11x + 3. This has
the graph shown
in Figure 1.3, which shows√f has three real roots at z0 = 1.5,
√
1
z1 = 2 (3 − 5) ≈ 0.381966 and z2 = 12 (3 + 5) ≈ 2.61803. Assign the following
colours to these roots:
Root
z0
z1
z2
Colour
red
blue
green
10
5
-1
1
2
Figure 1.3: Graph for f (x) = −2x3 + 9x2 − 11x + 3.
If we construct a Newton fractal using the method described above, we obtain the
one-dimensional object shown in Figure 1.4. When magnifying the object at x = 1,
another green ‘strip’ appears followed by another blue ‘strip’, and so on. This shows
the self-similar nature of the object and so this object is indeed a fractal.
Example 1.2.4. Define f : C → C by f (z) = −2z 3 + 9z 2 − 11z + 3. This is the
same function with the same roots as the previous example but we are now working
in the complex plane.
Constructing a Newton fractal in the same method, we obtain the object shown
in Figure 1.5. The set of real numbers is a subset of the complex numbers, so the
pattern of colours in Figure 1.4 reappears on the real line in Figure 1.5.
As with the fractal in Example 1.2.3, magnifying the object at z = 1 reveals
more detail.
1.3
The project
Different choices for the function f creates different Newton fractals. The differences
can be quite startling, but there are not many examples of Newton fractals in the
public domain.
Existing systems that draw Newton fractals are introduced in Section 2.3. These
systems have restrictions on the number and types of functions it can draw Newton
fractals for.
This project focuses on a system which was created to draw Newton fractals for
a wide range of functions, and to analyse the results in more detail.
3
Chapter 1. Introduction
1.3. The project
↓
↓
↓
Figure 1.4: Newton fractal for f (x) = −2x3 + 9x2 − 11x + 3 on R (top). Successive
images show magnifications on the fractal at the point x = 1. The fractals have
been stretched to make it easier to see the details.
Figure 1.5: Newton fractal for f (z) = −2z 3 + 9z 2 − 11z + 3 on C.
4
Chapter 1. Introduction
→
1.4. Report overview
→
→
Figure 1.6: Magnifying the fractal centred at z = 1.
1.4
Report overview
Chapter 2 introduces the important mathematical concepts behind the project.
This chapter also introduces existing fractal systems which can also draw Newton fractals.
Chapter 3 outlines the requirements of the system and the desired underlying
structure of the system.
Chapter 4 discusses the main technique used to draw Newton fractals and how to
make various features efficient.
Chapter 5 illustrates the functioning system and describes how it is intended to
be used in practice.
Chapter 6 outlines how the various components of the system were tested.
Chapter 7 summarises the achievements of the project and how it could be improved.
5
Chapter 2
Background
2.1
Overview
This chapter outlines the possible features of the system. Before this is possible it is
necessary to introduce the mathematical background and a couple of existing fractal
systems.
2.2
Terminology
Definition 2.2.1. A (discrete time) dynamical system is a map φ : X → X
on a state space X. We will denote this by {X; φ}.
Suppose Newton’s method is used to find the roots of a function f : C → C.
}.
Then the dynamical system we will consider is {C; z − ff0(z)
(z)
Notation 2.2.2. Let {X; φ} be a dynamical system. Denote the n-th iterate of φ
by
φn (z0 ) = φ ◦ φ ◦ . . . ◦ φ(z0 ) = zn
{z
}
|
n times
Definition 2.2.3. Let {X; φ} be a dynamical system. The orbit of a point x ∈ X
is {φn (x)}∞
n=0 , the sequence of points obtained from continually applying φ.
For Newton’s method, the orbit of the initial guess z0 is the sequence of successive
approximations to a root.
2.2.4
Petals
Let φ(z) = z − ff0(z)
describe the Newton iteration for a function f : C → C. Given
(z)
the Newton fractal for f (z), a path-connected subset P ⊂ C is (informally) called a
‘petal’ if for all p ∈ P , φn (p) → r as n → ∞, where f (r) = 0.
Informally, a petal is a subset of a Newton fractal whose points all converge to
the same root. The word ‘petal’ derives from the petal-like shape of these subsets
of the Newton fractal for f (z) = z 3 − 1 (see Figure 2.1).
6
Chapter 2. Background
2.2. Terminology
Figure 2.1: ‘Petals’ of the Newton fractal for f (z) = z 3 − 1.
2.2.5
Branches
Suppose f : C → C is a complex multivalued function.
For the purposes of this project, a branch point of f is the point at infinity or
a singularity of f .
A curve joining two branch points is known as a branch cut of f . It is important
to note that the values of f (z) are discontinuous either side of a branch cut.
A branch of f is a restriction on the range of f , over which it is a single-valued
function. A branch is characterised by a choice of branch cut.
For this project, a branch will be defined by a straight line joining a singularity
of f with the point at infinity.
Example 2.2.6. Let f (z) = ln z = ln |z| + i(arg z + 2mπ), m ∈ Z. This is a
multivalued function with singularity at z = 0.
By choosing the range in which i(arg z+2mπ) must lie, the values of f (z) become
unique for all z. There are infinitely many possible branch cuts, two of which are
shown in Figure 2.2.
Branch cut
Branch cut
0
0
Figure 2.2: Possible branch cuts of ln z. Values of ln z across the branch cuts are
discontinuous.
7
Chapter 2. Background
2.3
2.3. Existing systems
Existing systems
There are several systems capable of rendering Newton fractals and other dynamical
systems. Fractal Science Kit (FSK) by Hilbert and Ultra Fractal (UF) by
Phreakware both are feature rich and are more flexible systems than the others
available.
2.3.1
Features and capabilities
Fractal Science Kit
Figure 2.3: Fractal Science Kit
Fractal Science Kit [7] allows the user to create many different types of fractals. It
has such a large number of customisation options available that it is clearly targeted
at experts who are familiar with the subject. Its features include:
• Show the orbit of points. The user clicks on a point on the plane and the
system shows the point’s orbit.
• Many types of fractals are available such as Mandelbrot, Newton and Sierpinski.
• Two colouring methods - ‘standard’ or orbit trap - both of which can be edited.
Standard The colour of a point is determined by the number of iterations
of the dynamical system before it meets the stopping criterion. It is
important to note that, for FSK, the colours do not indicate which root
the point converged to.
8
Chapter 2. Background
2.3. Existing systems
Orbit trap Orbit traps can create interesting images, but for the purposes
of this project we will not be discussing or exploring them.
• Save and load settings, which are stored in XML files. This is a particularly
useful feature because of the vast number of options available.
Ultra Fractal
Figure 2.4: Ultra Fractal
Ultra Fractal [12] has fewer options than FSK and is a lot easier to use as well.
It seems that its main purpose is for creating fractal art. Its features include:
• Option to auto-adjust the maximum number of iterations, which changes as
the user zooms in or out. This means that, unlike a lot of other systems, UF
can achieve a very deep level of zoom without losing detail.
• Fractal images are interlaced as they are being calculated. This is useful when
many iterations are being performed.
• The user can specify the exponent, p ∈ C, and a root, c ∈ C, for the Newton
fractal, where the function f is f (z) = z p − c.
• Animation creation. The user can move around the fractal or change some
variables, which can then be animated.
• Save and load settings using proprietary ufr files.
9
Chapter 2. Background
2.3.2
2.4. Proposal of features for a new system
Comparison of existing systems
Both FSK and UF have basic functions such as exporting the fractal details to XML
and ufr files respectively. Both systems can also change the variables which control
the tolerance or maximum number of iterations. They both can also change the
colouring gradient of the fractal, although they both only colour according to the
number of iterations and not the root the Newton fractal converges to.
FSK has a lot more variation in the fractal types than UF. Each fractal type can
be tweaked further and transformations applied as well. Its interface for changing
the properties is complicated and can be overwhelming for a new user. Conversely,
UF’s interface is a lot simpler, but also gives the user fewer options. However, UF
does allow the user to manually edit the fractal template files, which enables the
user to change any parameter used to generate the fractal.
The zoom depth of FSK is inferior, and appears to lose accuracy for deep levels
of zoom regardless of the number of iterations set.
2.3.3
Required features
To investigate the behaviour of Newton fractals, some features found in the existing
systems will be needed, along with features not found in either system. These are:
Given a function, draw the corresponding Newton fractal.
The existing systems are able to draw different Newton fractals, but they are
limited to preset functions with some adjustable parameters. UF allows the
user to freely edit the Newton iteration, but this requires the user to change
the template code and might not be suitable for non-expert computer users.
Changeable variables at runtime.
Both systems are able to change variables such as the maximum number of
iterations and tolerance.
Ability to view different branches of multivalued functions.
UF appears to be the only system that handles multivalued functions. However, it only shows the principal branch of the function.
Orbits of points/subsets of the fractal.
FSK is the only system that shows the orbits of points. However, because its
colouring schemes do not indicate which root points converge to, this feature
is not very useful or interesting.
Animation.
Ultra Fractal is capable of animating various changes made to the fractal. The
animations it produces are not very sharp because each frame is calculated
while the animation is running.
2.4
Proposal of features for a new system
The proposed system should include the following features:
10
Chapter 2. Background
2.4. Proposal of features for a new system
• Given a user-specified function f and its derivative f 0 , draw its Newton fractal.
It would be desirable for the user to only supply f , and then for the system
to calculate f 0 and the roots.
• Changeable variables at runtime. This will include the tolerance value and
maximum number of iterations, which will be auto-adjustable.
• View different branches of multivalued functions. The user should be able
to choose the values to which the arguments of the branch points will be
restricted.
• Orbits of points/subsets of the fractal. This feature will be similar to Fractal
Science Kit’s orbit feature, and will be extended to investigate if points in
‘petals’ share similar orbits.
• Animation of gradual changes to certain parameters of the function.
• A simple colouring system that can be customised to show the root a point
converges to or the number of iterations. This may be extended to include
other kinds of colouring schemes based on other criteria.
11
Chapter 3
Design
3.1
Overview
This chapter outlines the requirements of the system and describes the intended
structure of the finished system.
3.2
Functional requirements
After researching the existing fractal systems in the previous chapter, the following
functional requirements were identified for a new system:
Parse string as a mathematical function
The key feature missing from the other fractal systems is the ability to draw
Newton fractals for a user-specified function. A string parser was designed to
handle real polynomials initially, followed by complex polynomials and then
additions such as trigonometric and exponential functions.
Draw fractal
Edit fractal parameters
This includes the tolerance and maximum number of iterations values.
Pan/zoom around fractal
Basic functions for exploring the fractal.
View orbits of points
Edit branch of the function
Save/load fractal settings
This feature was not implemented due to lack of time (see Section 7.2.4). It
was desirable for the system to be able to save the settings (the function,
tolerance, maximum number of iterations, the complex plane coordinates, all
pixel data) to file. It could then have enabled the user to save interesting views
of a fractal to file and then load it with minimal time spent recalculating the
fractal.
12
Chapter 3. Design
3.3. Non-functional requirements
Create fractal animation
This feature was not implemented due to lack of time (see Section 7.2.4), and
was possibly too ambitious to implement because of other subject commitments. Changes to parameters of functions such as coefficients or powers can
show dramatically different fractals. If the gradual changes to the parameters
is animated, it could provide interesting animations.
3.2.1
Component interactions
Figure 3.1 shows how the different functional requirements interact with each other.
ts
rea
d
wri s/
tes
se
s
set es
lu
va
Fractal plotter
Fractal
settings file
nts
pri
ines
def ts
n
poi
on
cti
Colour
New
met ton's
hod
alu
es
un
sf
uses
sv
set
Orbit plotter
Edit parameters
s et
String parser
set
fram s
es
Pan/Zoom
Animator
Image file
Figure 3.1: How components interact with each other
3.3
Non-functional requirements
The following non-functional requirements were identified to aid the design of the
system:
Screen resolution
Over time, many computer users adopt higher display resolutions. This trend
can be verified by the display statistics for visitors to W3Schools, see Table
3.1. Although the fractal system is not a web application, these statistics give
a good insight into a potential users’ display resolution.
Date
Jan 2009
Jan 2008
Higher 1024 × 768 800 × 600 640 × 480 Unknown
57%
36%
4%
0%
3%
38%
48%
8%
0%
6%
Table 3.1: Browser display statistics for W3Schools [11]
From this it is clear that the system should be designed for resolutions of
1024 × 768 and higher.
13
Chapter 3. Design
3.4. Class diagram
Performance
Newton’s method is performed for each point on the screen. This means that
drawing a fractal involves a lot of calculations, particularly for non-convergent
points. The system needs to be as efficient as possible and to reuse any information from previous calculations.
Usability
The user should be able to make quick changes to the function and other
parameters. The interface should be kept simple.
3.4
Class diagram
The important classes for the system were identified and an outline class diagram
of the system was detailed as in Figure 3.2. This was largely followed except the
system only allowed one instance of a Fractal. This was for simplicity purposes
because of the lack of experience using Qt to show tabs. Given more time, this could
be implemented.
An addition to this design involved storing more data in each Pixel. For more
information, see Chapter 4.
3.5
GUI design
A GUI was needed for the benefit of the user, typically a mathematician. It was
decided that all the features of the system should be available on the same screen,
reducing the number of menus. A GUI design (see Figure 3.3) helped with ensuring
that all the important features were accounted for.
As noted above, multiple instances of Fractals was not implemented. The toolbar of buttons across the top was omitted because not all features were implemented.
Instead, all features were included in the panel on the right. The progress bar on
the bottom was replaced by the fractal being rendered gradually.
14
Chapter 3. Design
3.5. GUI design
Fractal
-f: mathfunction
-derivative: mathfunction
-roots: list<Root>
-bottomLeft: complex
-topRight: complex
-maxIterations: unsigned int
-tolerance: double
-screenSize: pair<int, int>
-autoAdjust: bool
-displayBuffer: Pixel[][]
-branchLowerBound: double
+setFunction(newF:string): bool
+setDerivative(newDeriv:string): bool
+addRoot(root:complex): bool
+removeRoot(root:complex): bool
+clearRoots(): void
+setBottomLeft(bl:complex): void
+setTopRight(tr:complex): void
+save(filename:string): bool
+load(filename:string): bool
+setScreenSize(width:int, height:int): bool
+setAutoAdjust(state:bool): void
+draw(): void
+drawOrbit(c:complex): void
+setBranchLowerBound(b:double): void
+getBranchLowerBound(): double
0..*
displays
creates
1
FractalPlotter
1 -fractals: list<Fractal>
+addFractal(): bool
+addFractal(filename:string): bool
+ removeFractal(f:Fractal): void
Animation
0..* -frames: Fractal[]
-speed: double
+addFrame(f:Fractal): void
+clearFrames(): void
Pixel
-root: Root
-numIterations: int
1..* -colour: Colour
+getRoot(): Root
+getNumIterations(): int
+getColour(): Colour
+setRoot(r:Root): void
+setNumIterations(n:int): void
+setColour(c:Colour): void
1
1
0..*
colours
characterised by
1
1..*
Colour
Root
-colour: Colour
-value: complex
+getColour(): Colour
+getValue(): complex
+setColour(col:Colour): void
+setValue(value:complex): void
colours
0..*
1
Figure 3.2: Class diagram
15
-red: double
-green: double
-blue: double
+getRed(): double
+getGreen(): double
+getBlue(): double
+setRed(r:double): void
+setGreen(r:double): void
+setBlue(r:double): void
Chapter 3. Design
3.5. GUI design
Newton Plot
File Help
New
fractal
Open
Save
Fractal1
Pointer Move
Zoom
in
Zoom
out
View
orbit
Anim. Create
frame anim.
Step size
Fractal2
Function
a
t
c
I
l
a
r
F
e
g
a
m
f(z)=
z^3 - 1
f'(z)=
3z^2
Roots
-0.5+0.866i, 1, -0.5-0.866i
Options
Tolerance
0.01
Max iterations
20
Auto adjust
Location
Bottom left
-2 - 2i
Top right
2 + 2i
Fractal
Width
512
Height
768
Branch
-3.14159 <= arg(z) < 3.14159
Rendering...
Figure 3.3: GUI design
16
Chapter 4
Implementation
4.1
Overview
This stage of the project involved the implementation of the ideas planned in the
design stage. This chapter focuses on the main ideas behind the calculating of
Newton fractals and the techniques used to create an efficient system.
4.2
4.2.1
Technology choices
Programming language
The fractal system was written in C++. Although I had a more exposure to Java,
I decided to use C++ because I wanted more experience with it. The system also
needed to be as efficient as possible because of the number of calculations involved
in Newton’s method. This made C++ more ideal than Java.
4.2.2
Fractal drawing
I had no previous experience creating a graphical user interface (GUI) for a C++
application, so the Qt framework was chosen because of its relative ease of use.
OpenGL was chosen for the actual drawing of the fractals because of past experience. This ultimately became the QtOpenGL module when the fractal drawing was
integrated with Qt.
4.2.3
String parsing
I had no prior experience of string parsing, so I was recommended to use Flex for
the lexical analysis of a string and GNU Bison for the actual parsing.
4.2.4
Development environment
The integrated development environment (IDE) of choice was Visual Studio. A Qt
add-in for Visual Studio also made it easier to understand the basics of creating Qt
applications.
17
Chapter 4. Implementation
4.3. Drawing a fractal
Eclipse was later chosen as the IDE to use in Linux (see Section 4.2.6).
4.2.5
Dependencies
Aside from the obvious dependency on the Qt and QtOpenGL libraries, the only
external libraries used were the Boost C++ libraries. These were primarily used as
part of the string parser.
4.2.6
Platform
It was always desirable, but not essential, for the system to be cross-platform. This is
reflected in the choices of C++, OpenGL and Qt, which are all available on multiple
platforms.
The system was initially developed in Windows but problems with the slow speed
of the system meant that development switched to Linux where there were no such
problems. Qt’s qmake, which generates makefiles for Qt applications, made the
transition to Linux relatively straightforward.
The reason for the speed problem in Windows was never identified, but these
problems were later resolved by resetting the project settings in Visual Studio. Consequently, the system runs in both Windows and Linux with little speed difference.
4.3
Drawing a fractal
A Newton fractal is drawn using the calculate fractal function shown in Listing
4.1. In short, the function performs Newton’s method for each pixel on the screen
using the find root function. This returns the root the point converged to and the
number of iterations it took to converge. This information is used to set the colours
of a screen buffer.
The colour of a point p is determined by:
• p.root - the root it converges to.
• p.numIts - the number of iterations taken to converge.
Each root is characterised by a Colour, an RGB triplet. Suppose we have
p.root.colour = (r, g, b). Denote a brightness factor bri = 1 - (p.numIts
/ maxIterations ). Then p.colour = (bri * r, bri * g, bri * b).
This leads to a fractal where brighter areas converge quickly and darker areas
converge slowly. By default, non-convergent points are coloured black.
4.3.1
Time complexity
Suppose we have a screen w pixels wide by h pixels high. Set m as the maximum
number of Newton iterations. Then the best case time complexity is O(wh) and the
worst case time complexity is O(whm). It is clear that if we have a large screen
and/or m is large, then this method will be extremely slow. However, it is important
to note that it is the most accurate way of drawing a Newton fractal.
18
Chapter 4. Implementation
4.4. Panning and zooming around the fractal
void F r a c t a l : : c a l c u l a t e f r a c t a l ( )
{
point info ptinfo ;
// Blank the screen .
b l a n k f l i s t ( ∗ c u r r e n t L i s t , Colour : :NONROOT) ;
// Go through each pixel on screen .
for ( int j = s c r e e n H e i g h t − 1 ; j >= 0 ; −−j )
{
f o r ( int i = 0 ; i < s c r e e n W i d t h ; ++i )
{
// Perform Newton ’s method . Sets colour info , etc.
// to_complex converts a screen point to its complex
// representation .
ptinfo = find root (
t o c o m p l e x ( i , j , p l a n e , screenWidth , s c r e e n H e i g h t ) ,
maxIterations ) ;
// Set the pixel information to the fractal buffer .
s e t f l i s t (∗ c u r r e n t L i s t , i , j , p t i n f o ) ;
}
// Draw gradually .
i f ( j % 256 == 0 )
updateGL ( ) ;
}
updateGL ( ) ;
}
Listing 4.1: Function for drawing a fractal
To overcome this problem, the system reuses information when navigating around
the fractal (Section 4.4), evaluates polynomials using Horner’s rule (Section 4.6),
reuses information when certain variables are changed (Section 4.7) and detects
periodic points to avoid unnecessary iterations (Section 4.8).
4.4
Panning and zooming around the fractal
The screen represents a subset V of the complex plane which is represented by the
class variable plane in the Fractal class. plane consists of a pair of complex
numbers representing the bottom left and top right coordinates of V . The values of
plane change when panning or zooming around the fractal.
We have seen that calculating a fractal can be slow, so the system was designed
to avoid recalculating known information where possible.
19
Chapter 4. Implementation
4.4.1
4.4. Panning and zooming around the fractal
Panning
Let A ⊂ C denote the original view of the complex plane and let γ : C → C be a
translation defined by γ(z) = z + d, d ∈ C. Then the panned view A0 = γ(A).
If, as in Figure 4.1, A ∩ A0 6= ∅ then the colour information in this overlapping
region can be reused when drawing A0 .
Figure 4.1: Panning around the plane. The pixel information in the regions where
A and A0 overlap can be reused.
This observation is used in the panning function. If the point was represented in
the original view, the pixel information is copied from the old screen buffer to its new
position on the next screen buffer. The memcpy C++ function is used for directly
copying the pixel information, making this process more efficient. The colours of
the other points are calculated in the usual way using Newton’s method.
The use of a second screen buffer means that more memory is used. Unfortunately, this is necessary because the system would otherwise be extremely slow.
4.4.2
Zooming
A similar observation can be made for zooming out. In Figure 4.2, all of the information in the original view A is contained in the zoomed-out view A0 . In a similar
implementation to the panning function above, all pixel information in A can be
copied to its new position in A0 .
Figure 4.2: Zooming out from A shows a wider view of the fractal, A0 . In this case
A0 contains all of the points in A, so we can reuse all of this information.
However, there is a noticeable difference between the panning and zooming implementations. For panning, all the information in the overlapping region is reused
20
Chapter 4. Implementation
4.5. Parsing strings as functions
whereas after zooming out, the original view is displayed using a smaller part of the
screen. So although information is reused, some of it is discarded. This causes a
slightly less accurate representation of the fractal to be drawn, which can be seen
in Figure 4.3. Therefore, this method of zooming out is an optional feature.
Figure 4.3: Difference between reusing information (left) and recalculating everything (right). Notice the different bands of the green region at the bottom are less
‘smooth’ when reusing information.
For zooming in to the fractal, there is no immediately obvious technique for
improving the speed, so the system performs Newton’s method on every point.
4.5
Parsing strings as functions
The string to mathematical function parser was implemented using Flex, a lexical analyser, and GNU Bison, a parser generator. I had no experience with string
parsing and time restrictions made it difficult to learn Flex and Bison. Incorporating Bison in C++ code was particularly difficult. Therefore, a Flex Bison C++
Template [6] was used to write the parser.
The lexical analyser (scanner) reads in the input string. It has a set of rules for
recognising numbers and mathematical terms. These rules determine which token
to return to the parser. The parser has a set of grammar rules, each comprising
of a pattern of tokens. If one of the grammar rules matches, the parser builds a
mathematical function accordingly.
The scanner and parser are brought together by the Driver class. The Driver
acts as an intermediate class between the Fractal class and the parser.
The parser was developed incrementally, at each stage adding support for:
1. Real polynomials.
2. Complex polynomials (including complex powers).
3. Trigonometric, exponential and logarithmic terms.
21
Chapter 4. Implementation
4.6. Evaluating functions
At the end of the implementation stage, the parser handles a linear combination
of monomial, sin(z), cos(z), tan(z), exp(z) and log(z) terms. There is scope to
improve this - see Section 7.3.1 for more information.
4.6
Evaluating functions
The function f (z) supplied by the user consists of a linear combination of monomial,
trigonometric, exponential and logarithmic terms. Newton’s method is called multiple times per pixel and the value of f (zn ) and f 0 (zn ) is required for the (n + 1)th
iteration. This requires the evaluation of a function to be as efficient as possible.
The system has a Polynomial class which is made up of Monomials. To evaluate
a Polynomial at the point z0 , one can either:
1. evaluate all the Monomials at z0 , and sum the results.
2. use Horner’s rule.
Definition 4.6.1. (Horner’s rule) [13]
Let
n
X
p(z) =
ai z i = a0 + a1 z + a2 z 2 + . . . + an z n
i=0
be a polynomial, where ai ∈ C (0 ≤ i ≤ n). By factoring out powers of z, p(z) can
be rewritten
p(z) = a0 + z(a1 + z(a2 + . . . + z(an−1 + an z) . . .))
In general, method (1) involves more multiplications than Horner’s rule. In the
fractal system, Horner’s rule has been implemented for evaluating polynomials with
real powers. All other terms are evaluated individually.
The implementation of Horner’s rule uses an array, called terms, of complex
numbers to store the monomial terms. Each index represents the power of the
monomial and each element represents the coefficient.
For example, the polynomial p(x) = 3 − 2z + 4z 3 will be stored in terms as
follows:
index
0 1 2 3 ...
coefficient 3 -2 0 4 . . .
max index
0
Note that terms has a fixed maximum index, so polynomials of a higher order
have to be evaluated using the other method.
This array allows direct access to the coefficients. This is quicker than sorting
the Monomials in order of power and then calling the accessor function to retrieve
the coefficient.
The highest power (or order) of the polynomial is also stored so that only the
necessary multiplications are performed. The implementation of Horner’s rule is
shown in Listing 4.2.
22
Chapter 4. Implementation
4.7. Changing tolerance and maximum iterations
s t d : : complex<f l o a t > v a l u e = 0 . 0 f ;
// Start from highest power .
for ( int i = o r d e r ; i >= 1 ; −−i )
{
// Add the next coefficient and multiply by z.
v a l u e = ( v a l u e + terms [ i ] ) ∗ z ;
}
// Add the constant term.
v a l u e += terms [ 0 ] ;
Listing 4.2: Horner’s rule
4.7
Changing tolerance and maximum iterations
The maximum iterations and tolerance may be adjusted at runtime. These are
denoted by the class variables maxIterations and tolerance respectively.
The screen buffer is a two-dimensional array of Pixels. A Pixel stores
• colour - the Colour of the pixel.
• root - the Root to which it converges.
• numIterations - the number of iterations performed.
• lastPt - the last point in the orbit.
• isPrePeriodic - whether it is a pre-periodic point (see Section 4.8).
There is a lot of information which can be reused to minimise the number of
repeated calculations. This is demonstrated below with regards to changing the tolerance and maximum iterations, and in Section 4.8 for some non-convergent points.
Note that if the maximum iterations is changed, this changes the value of the
brightness factor mentioned in Section 4.3. This means that, even if no additional
calculations are necessary, the colour of all points will still have to be calculated
again.
4.7.1
Increasing maximum iterations
Suppose maxIterations is increased from m to n. Then all Pixels p with
p.numIterations <= m have already converged. For these points, it is sufficient
to copy the old information and only calculate the new colour.
The remaining Pixels q have q.numIterations > m, i.e. q did not converge.
Note that the system has stored the last point in the orbit of q, so the first m
iterations do not need to be performed again. Therefore, only a maximum of (n m) iterations needs to be performed for each q.
23
Chapter 4. Implementation
4.7.2
4.8. Orbits and periodic points
Decreasing maximum iterations
Suppose maxIterations is decreased from m to n. Then all Pixels p with
p.numIterations <= n still converge under the new maxIterations . Again, it
is sufficient to copy the old information and calculate the new colour.
The remaining Pixels q have q.numIterations > n and therefore do not converge under the new maxIterations . q.colour can be set to black instantly.
However, the first n iterations will need to be performed again in order to set a new
q.lastPt . I decided it was important to store q.lastPt because of the tremendous speed benefit it brings when increasing the maximum iterations. Of course
this adds extra computation time when decreasing the maximum iterations, which
is unfortunate.
4.7.3
Decreasing tolerance
If the tolerance is decreased, more iterations will need to be performed for most
Pixels p. As with increasing the maximum iterations, p.lastPt is used to avoid
performing the first p.numIterations iterations.
When the tolerance is increased, there is no obvious method to speeding up the
calculation. Therefore the whole fractal is recalculated.
4.8
4.8.1
Orbits and periodic points
Drawing orbits
The orbit (see Definition 2.2.3) of a point p is determined by performing Newton’s
method for p. The orbit is stored as a vector of complex numbers, denoted here as
orb. The system simply draws the orbit as a set of connected lines from orb[i] to
orb[i+1] for each i < orb.size()-1. This is illustrated in Figure 4.4.
4.8.2
Periodic points
In the Newton fractal for f (z) = z 3 − 2z + 2 there are many ‘large’ black areas
- subsets which do not converge. As seen in Figure 4.5 the orbits of all points in
these black areas eventually oscillate between one black region and another. It turns
out that, with enough iterations, this settles into a period 2 orbit where the orbit
oscillates between the points 0 and 1. This behaviour is discussed in more detail in
Section 7.2.1.
The points that oscillate between each other are called periodic points. The
points which eventually settle into a periodic orbit are called preperiodic points.
Note that periodic points may have period greater than 2.
It is clear that periodic and preperiodic points will never converge to a root. If
not handled appropriately, each of these points will take maxIterations iterations
before Newton’s method terminates.
To avoid this, when performing Newton’s method the system stores the orbit in
a temporary vector. After each iteration, the system checks whether the current
24
Chapter 4. Implementation
4.9. Exploring different branches
Figure 4.4: The orbit of a point in f (z) = z 3 − 1.
point is a point in the last m points of the orbit (m a fixed natural number). If it
is, a periodic point has been detected and Newton’s method terminates.
4.9
Exploring different branches
Due to a lack of time, the only support for multivalued functions is for polynomials
with complex powers.
C++ has no native support for multivalued functions, so the C++ function
pow(x, y) only returns the value of xy for the principal branch. Similarly, abs(z)
returns the argument of z in the principal branch.
4.9.1
Monomials with complex powers
α
Consider a monic monomial f (z) = z α , α ∈ C. Using z α = elog z it can be shown
that f (z) is a multivalued function:
f (z) = z α = rα eiα(θ+2πn)
(4.1)
where r = |z|, n ∈ Z.
A different choice of n selects a different branch with the cut along the negative
real axis.
25
Chapter 4. Implementation
4.9. Exploring different branches
Figure 4.5: The orbit of a point in f (z) = z 3 − 2z + 2.
4.9.2
Selecting a branch in C++
The new pow function in Listing 4.3 was written to implement Equation 4.1.
complex<f l o a t > pow ( complex<f l o a t > z , complex<f l o a t > p , int n )
{
return pow ( abs ( z ) , p )
∗ exp ( p ∗ complex<f l o a t >(0.0 f ,
a r g ( z ) + ( 2 . 0 f ∗ PI ∗ ( f l o a t ) n ) ) ) ;
}
Listing 4.3: Selecting branches
To allow a branch cut which is not along the negative real axis, the system has
to use two choices of n.
Suppose we set lb to be the lower bound of the branch. We can define lowerN,
the smaller possible n, by lowerN = floor((lb + PI)/(2*PI)). It is then possible
to determine what value of n to use by observing Figure 4.6. All points which lie
between lb and the negative real axis uses n = lowerN. Otherwise, n = lowerN +
1. The code for this is in Listing 4.4.
int F r a c t a l : : g e t p o i n t n ( complex<f l o a t > z )
{
// The actual argument of z.
f l o a t argZ = a r g ( z ) + ( 2 . 0 f ∗ PI ∗ branchN ) ;
26
Chapter 4. Implementation
4.10. Summary
Up
p
Lo er b
o
we
r b und
ou
nd
Figure 4.6: The choice of n depends where the point is in C.
// Decide on choice of n depending on where z lies.
i f ( argZ >= l b )
return lowerN ;
else
return lowerN + 1 ;
}
Listing 4.4: Choosing the correct n.
Like trigonometric functions, computing complex powers is very time consuming. When the user changes branches, as long as lb is not changed by more than
2π, it is possible to reuse information like when panning and zooming. The only
recalculations required are the points with argument between the new and old values
of lb.
4.10
Summary
The basic ideas behind drawing a Newton fractal are very simple. This chapter has
focused on the techniques used to make the features of the system as efficient as
possible.
27
Chapter 5
Results
5.1
Overview
This chapter describes how the system is intended to work in practice.
5.2
Drawing basic fractals
As mentioned in Section 3.5, the GUI was designed to include all features on the
same screen. Figure 5.1 shows the system after it starts, displaying the Newton
fractal for f (z) = z 3 − 1 by default.
Figure 5.1: The Newton Plot GUI.
28
Chapter 5. Results
5.2.1
5.2. Drawing basic fractals
Changing the function
The function used to draw the Newton fractal can be changed. As expected, this is
done by changing the f (z) field. As shown in Figure 5.2, the user can also choose
to specify the derivative in the f 0 (z) field and the roots in its respective field. Using
the values of f (z), f 0 (z) and roots in 5.2, the user can click the Set button (or press
Enter) to draw the Newton fractal in Figure 5.3.
Figure 5.2: Fields related to the function.
Figure 5.3: The Newton fractal for f (z) = z 3 − 2z + 2.
For polynomials it is also possible to leave the f 0 (z) field blank because it can
be calculated automatically. Likewise, it is possible to leave the roots field blank
for any function. In this case, Newton’s method is used to approximate the roots
instead.
29
Chapter 5. Results
5.3. Panning and zooming
If either field is left blank, these values are printed in blue to inform the user the
values were calculated by the system. This is shown in Figure 5.4.
Figure 5.4: f 0 (z) and the roots have been calculated by the system.
For some context, the “Show roots” checkbox may be used to display the roots
of f (z). The “Show axes” checkbox shows the real and imaginary axes. Figure 5.5
shows the axes and the roots as white crosses.
5.2.2
Changing maximum iterations and tolerance
The user is free to change the maximum iterations at runtime using the field in Figure
5.6. Increasing this the maximum iterations to 50 creates a brighter fractal (Figure
5.7) whereas decreasing it to 10 iterations creates many dark ‘non-convergent’ areas
(Figure 5.8).
Similarly, changing the tolerance is also possible at runtime. An extreme example
is shown in Figure 5.9, where the tolerance is set to 1.2.
5.3
Panning and zooming
There are a few different ways to explore a fractal:
Panning
• Arrow keys pan in their respective directions.
• Dragging with the right mouse button pans the camera in that direction.
30
Chapter 5. Results
5.3. Panning and zooming
Figure 5.5: Showing the roots and axes.
Figure 5.6: Fields to tweak the maximum iterations and tolerance.
31
Chapter 5. Results
5.3. Panning and zooming
Figure 5.7: Increasing to a maximum of 50 iterations.
Figure 5.8: Decreasing to a maximum of 10 iterations.
32
Chapter 5. Results
5.3. Panning and zooming
Figure 5.9: Increasing tolerance to 1.2.
Zooming
• The + and - keys zoom in and out respectively.
• The mouse wheel scrolled up and down zooms in and out respectively.
• Dragging the left mouse button draws a box. The system zooms to the
region in the box.
It is also possible to state the bottom left and top right coordinates of the fractal
to show, as in Figure 5.10.
Figure 5.10: Fields to adjust the coordinates of the fractal.
Examples of panning, zooming in and zooming out are show in Figures 5.11, 5.12
and 5.13 respectively.
33
Chapter 5. Results
5.3. Panning and zooming
Figure 5.11: Panning across the fractal.
Figure 5.12: Zooming into an area.
34
Chapter 5. Results
5.4. Orbits
Figure 5.13: Zooming out.
5.4
Orbits
There are two methods for viewing the orbits of points on the fractal.
Middle click The user middle clicks on a point on the fractal. The orbit for this
point is drawn.
Mouse move The orbit is drawn for the point under the mouse pointer. The orbit
changes as the mouse pointer is moved.
An example of an orbit is shown in Figure 5.14. The orbit starts in a blue region
near the top right and converges to the root in the blue region at the bottom.
5.5
5.5.1
More interesting functions
Trigonometric functions
By specifying f (z) = sin(z) we get a very interesting fractal in 5.15. sin(z) has
infinitely many roots and so it is helpful that the user does not need to specify any
roots at all.
The system also uses a fixed palette of nine colours for up to nine roots. When
a fractal has more roots, the palette ‘wraps around’ and reuses colours. There is no
feature that allows the user to select their own colours, so this ensures every root is
assigned a colour. Of course, if colours are reused, there will be petals of the same
colour which converge to different roots. The user can overcome this problem by
using the orbits feature to determine which root these regions converge to.
35
Chapter 5. Results
5.5. More interesting functions
Figure 5.14: The orbit of a point on the fractal.
Figure 5.15: The default (left), far away (centre) and close (right) views of f (z) =
sin(z).
36
Chapter 5. Results
5.5.2
5.5. More interesting functions
Polynomials with complex powers
Suppose the user specifies a polynomial with complex powers. The lower bound of
the branch can be set in the “Branch” field, as shown in Figure 5.16. The resulting
Newton fractal will have a discontinuity across the branch cut.
Figure 5.16: The lower bound of the branch defines the whole branch.
by
The user can click on the “-” or “+” buttons to decrease or increase the branch
respectively.
π
6
Figure 5.17: Branches of f (z) = z 3−i − 1: 0 ≤ arg(z) < 2π (left),
(centre), π3 ≤ arg(z) < 7π
(right).
3
37
π
6
≤ arg(z) <
13π
6
Chapter 6
Testing and Evaluation
6.1
Overview
This chapter outlines the methods used to test various components of the system.
6.2
Function parser
The function parser is an important part of the system. A test program was written
to test the parser individually before it was integrated into the fractal system. The
test program was given a string as input. If successfully parsed, a corresponding
instance of a mathfunction was created.
6.2.1
Creating mathematical functions
The parser was improved incrementally, adding support for more types of functions
each time. At each stage a set of test data was used to test the parser. The test
program was expected to output a string representation of the parsed function and
its value at arbitrarily chosen real and complex number. The expected output for
each stage is listed in Table 6.1 which verifies that the function parser works as
expected.
6.2.2
Polynomial derivative
The test program also calculated the derivatives of polynomials with the expected
output in Table 6.2. The actual output of the test program matches these expected
values.
6.3
6.3.1
Fractals
Basic fractal drawing
The system is capable of drawing the Newton fractal for a wide range of functions.
It is sufficient to test functions whose Newton fractals are in the public domain.
38
Chapter 6. Testing and Evaluation
f(z)
1
z
z^2
z^3
2z
-z
-3z
3z^3
-z^4 + 4z + 1z^2 + 1
z + z
z^i
z^(1+i)
z^1+i
(1+i)z
1+iz
iz^(2-i)
sin(z)
cosz
-tan z
ln(z)
2log(z)
e^z
iexp^(z)
6.3. Fractals
f(2)
f(1-i)
1
1
2
1−i
4
−2i
8
−2 − 2i
4
2 − 2i
−2
−1 + i
−6
−3 + 3i
24
−6 − 2i
−3
9 − 6i
4
2 − 2i
0.769 + 0.639i
2.063 + 0.745i
1.538 + 1.278i
2.808 − 1.318i
2+i
1
2 + 2i
2
1 + 2i
2+i
−14.802 + 12.295i 0.858 − 0.310i
0.909
1.298 − 0.635i
−0.416
0.834 + 0.989i
2.185
−0.272 + 1.084i
0.693
0.347 − 0.785i
1.386
0.693 − 1.571i
7.389
1.469 − 2.287i
7.389i
2.287 + 1.469i
Table 6.1: Test data for the math function parser.
f(z)
1
z
z^2
z^3
2z
-z
-3z
3z^3
-z^4 + 4z + 1z^2 + 1
z + z
z^i
z^(1+i)
z^1+i
(1+i)z
1+iz
iz^(2-i)
z^(1+i) - z^2
f’(z)
0
1
2z
3z^2
2
-1
-3
9z^2
-4z^3 + 4 + 2z
2
iz^(-1+i)
(1 + i)z^i
1
1 + i
1 + i
(1+2i)z^(1-i)
(1+i)z^i - 2z
Table 6.2: Test data for polynomial derivatives.
39
Chapter 6. Testing and Evaluation
6.3. Fractals
The examples in Figures 6.1 and 6.2 show that the fractals drawn by the system are
very similar to the existing images. It is therefore possible to verify the method for
drawing fractals is ‘correct’.
Figure 6.1: Comparing Newton fractals for z 3 − 2z + 2 from Wikipedia [9] (left) and
my system (right).
Figure 6.2: Comparing Newton fractals for z 8 + 15z 4 − 16 from Wikipedia [5] (left)
and my system (right).
6.3.2
Panning, zooming etc.
Let A denote a fractal after it has been panned. Let B denote the fractal in the
same position with all the points recalculated. Then the correctness of panning can
be tested simply by comparing A with B.
The same is true for zooming and changing values such as tolerance and maximum iterations.
40
Chapter 6. Testing and Evaluation
6.3.3
6.3. Fractals
Automatic root finding
The Newton fractals with the roots entered manually or found automatically can be
compared to check the latter is correct. Of course, there will be slight differences
between the two fractals because the roots are approximated. Figure 6.3 shows this
slight discrepancy, but the fractals are mostly the same.
Figure 6.3: Comparing Newton fractals for z 3 − 1 with roots entered manually (left)
and found using Newton’s method (right).
41
Chapter 7
Conclusions
7.1
Overview
The project has been largely successful, but not all targets were met. This chapter
summarises the achievements and discusses how the system could be improved.
7.2
Achievements
The system has a number of features which make it a useful tool for exploring
Newton fractals. However, not all features have been implemented and the system
has scope for improvement and further developments.
The first few months of the project were spent trying to find interesting research
ideas from mathematicians in the School of Mathematics. Some members of staff
were away for a period of time, so no progress was made at this time and the project
fell behind. In the end, the ideas suggested required a lot of background reading in
an area I was unfamiliar with, so these ideas were not used. If the aims of the project
had been identified earlier, more time could have been spent on the implementation.
I underestimated the time required to understand the string parsing and, given
the lack of time, was probably a little ambitious with some features in the project
proposal.
7.2.1
Targets met
The system meets the requirements in Section 3.2 except for those indicated. In
particular, the string parser is able to parse a linear combination of (real and complex) monomials, sin z, cos z, tan z, ln z, ez and |z|. This allows users to investigate
the Newton fractals for a wide range of functions.
Many of the features such as panning and changing the maximum iterations
have been optimised. This satisfies the performance (non-functional) requirement
(Section 3.3).
Points on the fractal are coloured according to the root it converges to. The
system is capable of showing the orbit of any point on the fractal. These two features
make it easy to verify both features are working correctly. The orbit feature also
42
Chapter 7. Conclusions
7.2. Achievements
demonstrates an interesting theorem on dynamical systems which has been applied
to the Newton fractal in Theorem 7.2.2.
Theorem 7.2.2. (Non-Wandering Domain Theorem) (Sullivan) [4]
Let F be the Newton fractal for f : C → C, where the Newton iteration is
φ(z) = z − ff0(z)
. Suppose P ⊂ F is a ‘petal’. Then P is eventually periodic under
(z)
iterations of φ.
That is, there exists some S ∈ N such that φS (P ) is a periodic point of φ.
If all points p ∈ P converge to a root, the orbit of P ends with the petal containing
the root, which has period 1.
Figure 7.1 shows the orbits of three distinct points in the same petal. Although
these points do not require the same number of iterations to converge, it is clear
that each point visits the same petals. One can say that the set of points in the
petal behave similarly. Figure 7.2 shows points in a non-convergent petal also share
similar orbits. The difference is that these non-convergent petals eventually settle
into a period 2 orbit.
Figure 7.1: Points in the same petal visit the same petals.
Figure 7.2: Points in non-convergent petals eventually settle into a period 2 orbit.
Orbits with period greater than 2
Figure 7.2 shows a Newton fractal where the non-convergent petals eventually settle
into a period 2 orbit. While testing the system I have not encountered any Newton
fractals with period 3 (or greater) petals.
43
Chapter 7. Conclusions
7.2. Achievements
There is an interesting result by Li and Yorke which states that, in a dynamical
system {X; φ}, a period 3 orbit implies “sensitive dependence on initial conditions”
(SDIC) [2]. This means that under iterations of φ any two points x, x0 ∈ X, no
matter how close they are, will (eventually) behave differently from each other.
This is also a property of a chaotic dynamical system.
From our observations from Theorem 7.2.2 we know that all points in the same
petals behave similarly. So if we have a Newton fractal which has a period 3 orbit
we surely cannot have SDIC at the same time.
The following result provides a little more insight into petals of orbit greater
than 3.
Theorem 7.2.3. (Sharkovskii’s theorem) [3]
Order the natural numbers as follows:
3 ≺ 5 ≺ 7 ≺ 9 ≺ . . . ≺ 2 · 3 ≺ 2 · 5 ≺ . . . ≺ 22 · 3 ≺ 22 · 5 ≺ . . .
. . . ≺ 23 · 3 ≺ 23 · 5 ≺ . . . ≺ 24 · 3 ≺ 24 · 5 ≺ . . . ≺ 23 ≺ 22 ≺ 2 ≺ 1
Suppose φ has a period p orbit. Then p ≺ q implies the existence of a period q orbit.
Sharkovskii’s theorem shows that a period 3 orbit implies orbits of all periods
and thus some kind of chaotic nature. We can see that petals with an orbit of period
22 = 4 may be possible in a Newton fractal, although I have yet to find any such
fractals.
Branches of functions
The ability to change the branch of a multivalued function is a feature not seen
in any other fractal system. This is probably due to restrictions on the family of
functions allowed, such as f (z) = z p − 1, p ∈ N. Ultra Fractal allows p to take
imaginary values, but does not give the option to select a different branch. This is
probably because its main purpose is for creating fractal art, which means viewing
different branches is a low priority feature.
If the bounds of the branch are changed gradually, the system reveals more of a
Newton fractal beyond a branch cut. It is quite a nice way to demonstrate why a
branch cut is needed and how the choice of branch affects the fractal.
Gradually adjusting the roots sometimes introduces a new discontinuity which
is not the branch cut (as in Figure 7.3). This appears to be because multivalued
functions can have multiple roots, so changing the branch may ‘cover’ up a root.
Points will no longer be able to converge to this root. This discontinuity shows that
the same point can behave differently under different branches.
Handling the branches elegantly appears to be a complicated problem. With a
lot more time available, there are some possibilities for improving this feature. More
details are described in Section 7.3.2.
7.2.4
Missing features
Although the system allows the user to conduct some research into Newton fractals,
it does not meet all the requirements set in the Design stage.
44
Chapter 7. Conclusions
7.3. Further work
Figure 7.3: Gradually changing the branch (left to right) may create new discontinuities.
Both Fractal Science Kit and Ultra Fractal could save the settings (the function,
tolerance, maximum iterations and complex plane coordinates) of a fractal to file.
A similar feature was due to be implemented in the last few weeks of the implementation stage, but was deferred because of a lack of time. The fractal animation
feature was also not implemented for similar reasons.
Near the end of the implementation, the branches feature took priority because
it was deemed more interesting. This was a good decision because the two omitted
features already exist in other fractals systems whereas the branches feature does
not.
7.3
Further work
Aside from the missing features, there are some other possible areas where the
system could be improved further.
7.3.1
Function parser
The number of fractals the system can draw is limited by the types of mathematical
functions the system can parse. Although it can parse a linear combination of
trigonometric functions, this is still quite limiting. For example, if we set f (z) =
tan z the system would require the user to set f 0 (z) = sec2 z, which is not a linear
combination of trigonometric terms. The next natural step for the system would be
to improve the function parser to recognise many more kinds of functions.
7.3.2
More multivalued functions
The only multivalued functions the system can handle only handle are polynomials
with complex powers. The complex analogue of functions such as log(z) could be
45
Chapter 7. Conclusions
7.3. Further work
implemented next.
The anomalies observed in Section 7.2.1 regarding the fractals of multivalued
functions also raises a question: If a point converges to different roots under different
branches, how does it behave when all branches are allowed? For example, instead
of drawing the complex plane with branch cuts, could a Newton fractal be drawn
on a Riemann surface such as in Figure 7.4?
Figure 7.4: The Riemann surface for the multivalued function ln z [8]
46
Chapter 8
Appendix A: Project Plan
The original project plans and revisions follow. The first revision was made after the
direction of the project became more clear. The second revision was made after the
Christmas / exam break. This revision includes a lot more detail and was helpful
with checking my progress.
47
Project Plan
Project Plan
Milestone / Deadline
Search for related work
Read related work
Finalise direction of project
Poster
Design
Reading Week
Seminar slides
Seminar period
Implementation (basic)
Testing (basic)
Christmas revision month
Exams
Implementation (flexible)
Testing (flexible)
Testing (final)
Investigate fractals I
Investigation report I
Investigate fractals II
Investigation report II
Presentation of results
Report sample
Easter revision month
Project report
Week Beginning (2009)
Week Beginning (2010)
27/09 04/10 11/10 18/10 25/10 01/11 08/11 15/11 22/11 29/11 06/12 13/12 20/12 27/12 03/01 10/01 17/01 24/01 31/01 07/02 14/02 21/02 28/02 07/03 14/03 21/03 28/03 04/04 11/04 18/04 25/04 02/05
Project Plan - Revision 1
Project Plan
Milestone / Deadline
Search for related work
Read related work
Finalise direction of project
Poster
Design
Reading Week
Seminar slides
Seminar
Implementation (basic)
Testing (basic)
Christmas revision month
Exams
Implementation (flexible)
Testing (flexible)
Testing (final)
Investigate fractals I
Investigation report I
Investigate fractals II
Investigation report II
Presentation of results
Report sample
Easter revision month
Project report
Week Beginning (2009)
Week Beginning (2010)
27/09 04/10 11/10 18/10 25/10 01/11 08/11 15/11 22/11 29/11 06/12 13/12 20/12 27/12 03/01 10/01 17/01 24/01 31/01 07/02 14/02 21/02 28/02 07/03 14/03 21/03 28/03 04/04 11/04 18/04 25/04 02/05
Project Plan - Revision 2
Project Plan
Milestone / Deadline
Search for related work
Read related work
Finalise direction of project
Poster
Design
Reading Week
Seminar slides
Seminar
Implementation (basics)
Imp'tion (poly parser)
Testing (basic)
Christmas revision month
Exams
Imp'tion (incorporate Qt)
Imp'tion (incorporate parser)
Imp'tion (basic tweaking)
Imp'tion (pan, zoom, colours)
Imp'tion (orbits)
Imp'tion (advanced parsing)
Imp'tion (period points)
Imp'tion (auto root finding)
Imp'tion (auto iterations)
Imp'tion (load /save to file)
Testing (final)
Presentation of results
Report sample
Easter revision month
Project report
Week Beginning (2009)
Week Beginning (2010)
27/09 04/10 11/10 18/10 25/10 01/11 08/11 15/11 22/11 29/11 06/12 13/12 20/12 27/12 03/01 10/01 17/01 24/01 31/01 07/02 14/02 21/02 28/02 07/03 14/03 21/03 28/03 04/04 11/04 18/04 25/04 02/05
Bibliography
[1] Kathleen T. Alligood, Tim Sauer, and James A. Yorke. Chaos- An Introduction
to Dynamical Systems, pages 149–150. Springer Science + Business Media, 233
Spring Street, New York City, New York, 10013, United States of America,
1996.
[2] Kathleen T. Alligood, Tim Sauer, and James A. Yorke. Chaos- An Introduction
to Dynamical Systems, page 32. Springer Science + Business Media, 233 Spring
Street, New York City, New York, 10013, United States of America, 1996.
[3] Kathleen T. Alligood, Tim Sauer, and James A. Yorke. Chaos- An Introduction
to Dynamical Systems, page 135. Springer Science + Business Media, 233 Spring
Street, New York City, New York, 10013, United States of America, 1996.
[4] Michael Barnsley. Fractals Everywhere, page 278. Academic Press Limited,
24-28 Oval Road, London, NW1 7DX, United Kingdom, 1993.
[5] ‘Bhappynick’. File:Timelapse34.jpg. http://en.wikipedia.org/wiki/File:
Timelapse34.jpg, May 2006.
[6] Timo Bingmann. Flex Bison C++ Template/Example (released under the Do
What The Fuck You Want To Public License (WTFPL)). http://idlebox.
net/2007/flex-bison-cpp-example/, April 2010.
[7] Ross Hilbert.
Fractal Science Kit - Fractal Generator.
fractalsciencekit.com/, March 2010.
http://www.
[8] Jan Homann. File:Riemann surface log.jpg. http://en.wikipedia.org/wiki/
File:Riemann_surface_log.jpg, August 2007.
[9] Henning Makholm. File:newton z3-2z+2.png. http://en.wikipedia.org/
wiki/File:Newton_z3-2z%2B2.png, August 2007.
[10] James Montaldi and David Broomhead. Math34042: Discrete time dynamical
systems lecture notes. http://www.maths.manchester.ac.uk/ pag/dynsyst/3fractals.pdf, 2009.
[11] Refsnes Data. W3Schools Browser Display Statistics. http://w3schools.com/
browsers/browsers_display.asp, November 2009.
[12] Frederik Slijkerman. Ultra Fractal: Advanced Fractal Animation Software.
http://www.ultrafractal.com/, March 2010.
51
Bibliography
Bibliography
[13] Eric W. Weisstein. “Horner’s Rule.” From MathWorld–A Wolfram Web Resource. http://mathworld.wolfram.com/HornersRule.html, April 2010.
[14] Eric W. Weisstein. “Newton’s Method.” From MathWorld–A Wolfram Web Resource. http://mathworld.wolfram.com/NewtonsMethod.html, April 2010.
52
Was this manual useful for you? yes no
Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Download PDF

advertisement