• Aucun résultat trouvé

Newton’s Method in C

Dans le document Undergraduate Topics in Computer Science (Page 128-134)

Fractals and L-Systems

Definition 9.10 The set M =

9.4 Newton’s Method in C

Since the arithmetic inCis an extension of that inR, many concepts of real analysis can be transferred directly toC. For example, a functionf:C→C:zf (z)is called complex differentiable if the difference quotient

f (z+z)f (z) z

has a limit asz→0. This limit is again denoted by f(z)= lim

z0

f (z+z)f (z) z

and called complex derivative off at the pointz. Since differentiation inCis de-fined in the same way as differentiation inR, the same differentiation rules hold. In particular, any polynomial

f (z)=anzn+ · · · +a1z+a0

is complex differentiable and has the derivative f(z)=nanzn1+ · · · +a1.

Like the real derivative (see Chap. 7.3), the complex derivative has an interpretation as a linear approximation

f (z)f (z0)+f(z0)(zz0) forzclose toz0.

9.4 Newton’s Method inC 121 Fig. 9.11 Possible regions of

attraction of Newton’s iteration for finding the roots ofz31

Letf:C→C:zf (z)be a complex differentiable function withf (ζ )=0 andf(ζ ) =0. In order to compute the zeroζ of the functionf, one first computes the linear approximation starting from the initial valuez0, so

z1=z0f (z0) f(z0).

Subsequentlyz1is used as the new initial value and the procedure is iterated. In this way, one obtains Newton’s method inC:

zn+1=znf (zn) f(zn).

For initial values z0 close to ζ the procedure converges (as in R) quadratically.

Otherwise, however, the situation can become very complicated.

In 1983 Eckmann [9] investigated Newton’s method for the function f (z)=z3−1=(z−1)

z2+z+1 . This function has three roots inC

ζ1=1, ζ2,3= −1 2±i

√3 2 .

Naively one could think that the complex planeCis split into three equally large sectors where the iteration with initial values in sectorS1converges toζ1, the ones inS2toζ2, etc.; see Fig.9.11.

A numerical experiment, however, shows that it is not that way. If one colours the initial values according to their convergence, one obtains a very complex picture.

One can prove (however, not easily imagine) that at every point where two colours meet, the third colour is also present. The boundaries of the regions of attraction are dominated by pincer-like motifs which reappear again and again when enlarging the scale; see Fig.9.12. The boundaries of the regions of attraction are Julia sets. Again we have found fractals.

Experiment 9.14 Using the MATLABprogrammat09_4.mcarry out an experi-ment. Ascertain yourself of the self-similarity of the appearing Julia sets by produc-ing suitable enlargements of the boundaries of the region of attraction.

9.5 L-Systems 123 then one obtains a new word. Applying the substitution rules on that again gives a new word, and so on. Each of these words can be interpreted as a polygon by assigning the following meaning to the individual letters:

fmeans forward by one unit;

pstands for a rotation ofαradians (plus);

mstands for a rotation of−αradians (minus).

Thereby 0≤απ is a chosen angle. One plots the polygon by choosing an arbi-trary initial point and an arbiarbi-trary initial direction. Then one sequentially processes the letters of the word to be displayed according to the rules above.

Inmaplelists and the substitution commandsubslend themselves to the im-plementation of L-systems. In the example above the axiom would hence be defined by

a := [f,p,f,p,f,p,f]

and the substitution rules would be

a -> subs(f=(f,p,f,m,f,m,f,f,p,f,p,f,m,f),a).

The letterspandmdo not change in the example, they are fixed points in the con-struction. For the purpose of visualisation one can use polygons inmaple, given by lists of points (in the plane). These lists can be plotted easily using the command plot.

Construction of Fractals With the graphical interpretation above andα=π/2, the axiom fpfpfpf is a square which is passed through in a counterclockwise direction. The substitution rule converts a straight line segment into a zig-zag line.

By an iterative application of the substitution rule the axiom develops into a fractal.

Experiment 9.17 Using themapleworksheetmp09_1.mwscreate different frac-tals. Further, try to understand the procedurefractalin detail.

Example 9.18 The substitution rule for Koch’s curve is a -> subs(f=(f,p,f,m,m,f,p,f),a).

Depending on which axiom one uses, one can build fractal curves or snowflakes from this; see themapleworksheetmp09_1.mws.

Simulation of Plant Growth As a new element branchings (ramifications) are added here. Mathematically one can describe this using two new symbols:

vstands for a ramification;

estands for the end of the branch.

124 9 Fractals and L-Systems

Fig. 9.13 Plants created using themapleworksheetmp09_2.mws

Let us look, for example, at the word

[f,p,f,v,p,p,f,p,f,e,v,m,f,m,f,e,f,p,f,v,p,f,p,f,e,f, m,f].

If one removes all branchings that start withvand end withefrom the list, then one obtains the stem of the plant

stem := [f,p,f,f,p,f,f,m,f].

After the secondfin the stem obviously a double branching is taking place and the branches sprout:

branch1 := [p,p,f,p,f] and branch2 := [m,f,m,f].

Further up the stem branches again with the branch[p,f,p,f].

For more realistic modelling one can introduce additional parameters. For ex-ample, asymmetry can be build in by rotating by the positive angleαatpand by the negative angle −β at m. In the program mp09_2.mws,this was done; see Fig.9.13.

Experiment 9.19 Using themapleworksheetmp09_2.mwscreate different arti-ficial plants. Further, try to understand the proceduregrowin detail.

To visualise the created plants one can use lists of polygons inmaple, i.e., lists of lists of points (in the plane). To implement the branchings one conveniently uses a recursive stack. Whenever one comes across the commandvfor a branching, one saves the current state as the topmost value in the stack. A state is described by three numbers(x, y, t )wherex andydenote the position in the(x, y)-plane andt the angle enclosed the with the positivex-axis. Conversely one removes the topmost state from the stack if one comes across the end of a brancheand returns to this state in order to continue the plot. At the beginning the stack is empty (at the end it should be as well).

9.6 Exercises 125 Extensions In the context of L-systems many generalisations are possible which can make the emerging structures more realistic. For example one could:

(a) Represent the letterfby shorter segments as one moves further away from the root of the plant. For that, one has to save the distance from the root as a further state parameter in the stack.

(b) Introduce randomness by using different substitution rules for one and the same letter and in each step choosing one at random. For example, the substitution rules for random weeds could be such:

f -> (f,v,p,f,e,f,v,m,f,e,f) with probability 1/3; f -> (f,v,p,f,e,f) with probability 1/3; f -> (f,v,m,f,e,f) with probability 1/3.

Using random numbers, one selects the according rule in each step.

Experiment 9.20 Using themapleworksheetmp09_3.mwscreate random plants.

Further, try to understand the implemented substitution rule in detail.

9.6 Exercises

1. Determine experimentally the fractal dimension of the coastline of Great Britain.

In order to do so, take a map of Great Britain (for example a copy from an atlas) and raster the map using different mesh sizes (for example with 1/64th, 1/32th, 1/16th, 1/8th and 1/4th of the North–South expansion). Count the boxes which contain parts of the coastline and display this number as a function of the mesh size in a double-logarithmic diagram. Fit the best line through these points and determine the fractal dimension in question from the slope of the straight line.

2. Using the programmat09_3.mwsvisualise the Julia sets ofzn+1=z2n+cfor c= −1.25 andc=0.365−0.3i. Search for interesting details.

3. Letf (z)=z3−1 withz=x+iy. Use Newton’s method to solvef (z)=0 and separate the real part and the imaginary part, i.e., find the functionsg1 andg2

with

xn+1=g1(xn, yn), yn+1=g2(xn, yn).

4. Modify the proceduregrowin the programmp09_2.mwsby representing the letterfby shorter segments depending on how far it is away from the root. With the result, plot the umbel from Experiment9.19again.

5. Modify the programmp09_3.mwsby attributing new probabilities to the ex-isting substitution rules (or invent new substitution rules). Use your modified program to plot some plants.

Dans le document Undergraduate Topics in Computer Science (Page 128-134)

Documents relatifs