fractal generation · fractal generation slide 8/18 ecology example2 we want to model the size of a...

18
Fractal Generation Slide 1/18 Fractal Generation Fall Semester Parallel Computing TJHSST

Upload: others

Post on 10-Aug-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Fractal Generation · Fractal Generation Slide 8/18 Ecology Example2 We want to model the size of a population over time. Let x represent a percentage of the maximum size so that

Fractal Generation Slide 1/18

Fractal Generation

Fall Semester

Parallel Computing TJHSST

Page 2: Fractal Generation · Fractal Generation Slide 8/18 Ecology Example2 We want to model the size of a population over time. Let x represent a percentage of the maximum size so that

Fractal Generation Slide 2/18

Topic Outline

• Fixed Point Iteration

– Square roots

– Cobweb diagram

– Attracting or repelling

• Ecology Example

– Logistic map

– Asymptotic behavior

– Bifurcations

• Chaos

• Complex Numbers

– Quadratic equations

– Rectangular form

– Polar form

•Orbits

– Converging or diverging

– Mandelbrot set

– Many Julia sets

•Up Next: DLA

Parallel Computing TJHSST

Page 3: Fractal Generation · Fractal Generation Slide 8/18 Ecology Example2 We want to model the size of a population over time. Let x represent a percentage of the maximum size so that

Fractal Generation Slide 3/18

Netwon’s Iteration1

• The positive solution of x2 − c = 0 is x =√c.

•Add c to both sides, divide by x, add x, then divide by 2:

x =1

2

x +c

x

•Newton’s Method. Given x = g(x) and an initial guess x0 wefind a sequence of approximations xn+1 = g (xn) that convergesto the solution if

∣∣∣∣∣g′ (√c)

∣∣∣∣∣ < 1 and x0 is “close enough” to√c.

•Using the power rule we find g′(x) = 0.5(1− c/x2

)which

means that g′ (√c) = 0 and En+1 = k (En)2 is the error.

1Weisstein, Eric W. “Newton’s Iteration.” From MathWorld–A Wolfram Web Resource. http://mathworld.wolfram.com/NewtonsIteration.html

Parallel Computing TJHSST

Page 4: Fractal Generation · Fractal Generation Slide 8/18 Ecology Example2 We want to model the size of a population over time. Let x represent a percentage of the maximum size so that

Fractal Generation Slide 4/18

Cobweb Diagram (1)

• Plot the iteration to our fixed point g (√c) =

√c.

• For c = 2 and x0 = 1, quadratic convergence doubles the num-ber of correct digits at each step, up to machine precision:

Step Approximation Error1 1.5000000000000000 8.6e-022 1.4166666666666665 2.5e-033 1.4142156862745097 2.1e-064 1.4142135623746899 1.6e-125 1.4142135623730949 2.2e-16

• See also, Yale Babylonian Collection 7289.

• See also, Metrica by Heron of Alexandria.

Parallel Computing TJHSST

Page 5: Fractal Generation · Fractal Generation Slide 8/18 Ecology Example2 We want to model the size of a population over time. Let x represent a percentage of the maximum size so that

Fractal Generation Slide 5/18

Cobweb Diagram (2)

• To make the plot of our iteration more dramatic we start witha really bad guess of x0 = 5. The root is called an “attracting”fixed point and, in fact, the graph becomes completely flat.

0

1

2

3

4

5

6

0 1 2 3 4 5 6

Parallel Computing TJHSST

Page 6: Fractal Generation · Fractal Generation Slide 8/18 Ecology Example2 We want to model the size of a population over time. Let x represent a percentage of the maximum size so that

Fractal Generation Slide 6/18

Attracting or Repelling Fixed Points

• If x0 = 3.7 and xn+1 = 1/ (4− xn) then we can tell the itera-tion converges to 2−

√3 ≈ 0.268 rather than the nearer root at

2 +√

3 ≈ 3.732 because of the slope of g(x) near those points.

0

0.5

1

1.5

2

2.5

3

3.5

4

0 0.5 1 1.5 2 2.5 3 3.5 4

Parallel Computing TJHSST

Page 7: Fractal Generation · Fractal Generation Slide 8/18 Ecology Example2 We want to model the size of a population over time. Let x represent a percentage of the maximum size so that

Fractal Generation Slide 7/18

Periodic Behavior

• If x0 = 0.25 and xn+1 = 3.21xn · (1− xn) then the iterationdoes not converge but rather oscillates between x ≈ 0.509 andx ≈ 0.802; this function was not chosen at random.

0

0.2

0.4

0.6

0.8

1

0 0.2 0.4 0.6 0.8 1

Parallel Computing TJHSST

Page 8: Fractal Generation · Fractal Generation Slide 8/18 Ecology Example2 We want to model the size of a population over time. Let x represent a percentage of the maximum size so that

Fractal Generation Slide 8/18

Ecology Example2

•We want to model the size of a population over time. Let xrepresent a percentage of the maximum size so that x = 1.0means we are at the carrying capacity.

•A logistic function, often studied in calculus, results from themodel dx/dt = rx(1 − x) or x = 1/(1 + e−rt), with initialexponential-like growth followed by a stable levelling off.

•Another model is the logistic map xn+1 = rxn(1−xn) which wewill consider. In this case if x ≈ 1.0 the population is not stablebut instead decreases rapidly, perhaps from a food shortage.

2Devaney, Robert. Chaos, Fractals, and Dynamics: Computer Experiments in Mathematics. Menlo Park, CA: Addison-Wesley, 1990. 19-21.

Parallel Computing TJHSST

Page 9: Fractal Generation · Fractal Generation Slide 8/18 Ecology Example2 We want to model the size of a population over time. Let x represent a percentage of the maximum size so that

Fractal Generation Slide 9/18

Orbit Diagram (1)

•We call r an ecological constant and we are interested in theasymptotic (i.e., long-term) behavior of the system as we varythis parameter. Typical values are on the range 0 to 4.

• For each value of r we perform a fixed point iteration. Does thesequence converge? Or is it periodic? Or something else?

• To visualize the effect of this parameter we first run a numberof iterations to let the sequence settle down, then we plot moreiterations in order to see what’s happening.

•Note. Our model is only a rough first-approximation for whatreally happens to a population over time.

Parallel Computing TJHSST

Page 10: Fractal Generation · Fractal Generation Slide 8/18 Ecology Example2 We want to model the size of a population over time. Let x represent a percentage of the maximum size so that

Fractal Generation Slide 10/18

Orbit Diagram (2)

• Let x0 = 0.25 and note particularly the behavior when r = 3.21;a bifurcation is a period-doubling of the asymptotic oscillation.

Parallel Computing TJHSST

Page 11: Fractal Generation · Fractal Generation Slide 8/18 Ecology Example2 We want to model the size of a population over time. Let x represent a percentage of the maximum size so that

Fractal Generation Slide 11/18

Chaos

• If x0 = 0.25 and xn+1 = 3.99xn · (1− xn) then the iterationdoes not converge or even oscillate with any obvious periodicity,and if x0 = 0.249999 then we get a totally different chaos.

0

0.2

0.4

0.6

0.8

1

0 0.2 0.4 0.6 0.8 1

Parallel Computing TJHSST

Page 12: Fractal Generation · Fractal Generation Slide 8/18 Ecology Example2 We want to model the size of a population over time. Let x represent a percentage of the maximum size so that

Fractal Generation Slide 12/18

Complex Numbers (1)

•What happens if we do a fixed point iteration with a quadraticequation using complex numbers instead of real numbers?

• Let z = a + bi where i =√−1 and consider zn+1 = z2

n + c,calling c = x + yi, so that:

an+1 = a2n − b2n + x

bn+1 = 2 · anbn + y

•We’re interested in whether or not the orbit of z0 = 0 will di-verge for a given c and, if it does, how quickly is that divergenceobvious. Any non-divergent behavior (convergence, periodic os-cillations, or chaos) is considered well-behaved.

Parallel Computing TJHSST

Page 13: Fractal Generation · Fractal Generation Slide 8/18 Ecology Example2 We want to model the size of a population over time. Let x represent a percentage of the maximum size so that

Fractal Generation Slide 13/18

Complex Numbers (2)

• Euler’s formula:eiθ = cos θ + i sin θ

•As an aside, this gives the beautiful result:

eiπ + 1 = 0

•Wow!

• So we can write z = a + bi = reiθ = r (cos θ + i sin θ).

•Also, |z| =√a2 + b2 = r and, it turns out3, if |z| > 2 at any

point in the iteration then the sequence will diverge.3Devaney, Robert. Chaos, Fractals, and Dynamics: Computer Experiments in Mathematics. Menlo Park, CA: Addison-Wesley, 1990. 86-87.

Parallel Computing TJHSST

Page 14: Fractal Generation · Fractal Generation Slide 8/18 Ecology Example2 We want to model the size of a population over time. Let x represent a percentage of the maximum size so that

Fractal Generation Slide 14/18

Mandelbrot Set

• Points c for which z does not diverge form the Mandelbrot set.

Parallel Computing TJHSST

Page 15: Fractal Generation · Fractal Generation Slide 8/18 Ecology Example2 We want to model the size of a population over time. Let x represent a percentage of the maximum size so that

Fractal Generation Slide 15/18

Julia Set (1)

• Fix c ≈ −0.727 + 0.189i and let z0 = x + yi instead of zero.

Parallel Computing TJHSST

Page 16: Fractal Generation · Fractal Generation Slide 8/18 Ecology Example2 We want to model the size of a population over time. Let x represent a percentage of the maximum size so that

Fractal Generation Slide 16/18

Julia Set (2)

• By varying c we get different Julia sets, not all of which are vi-sually interesting. Technically the Julia set is just the boundarybetween those z0 that escape to infinity and those that do not.

Parallel Computing TJHSST

Page 17: Fractal Generation · Fractal Generation Slide 8/18 Ecology Example2 We want to model the size of a population over time. Let x represent a percentage of the maximum size so that

Fractal Generation Slide 17/18

Example Program: Simple Mandelbrot Set, mandel 0.c

•Note the use of OpenGL in 2-D and the Lgcc script.

•We allow a maximum of 255 iterations before deciding whetheror not a particular orbit will diverge.

• The coloring scheme is based on how many of these iterations,up to 255, were required before divergence was achieved. Pointsthat diverge quickly are more red and points that do not divergeat all are completely black. Other schemes are possible.

•Questions:

– What to parallelize?

– How to parallelize?

Parallel Computing TJHSST

Page 18: Fractal Generation · Fractal Generation Slide 8/18 Ecology Example2 We want to model the size of a population over time. Let x represent a percentage of the maximum size so that

Fractal Generation Slide 18/18

Lab Assignment: Fractal Generation

• Set −0.6002735677772947 < x < −0.6002735677700187.

• Set −0.6646192764490847 < y < −0.6646192764436277.

•Allow no more than 65280 iterations per point.

• Plot the runtime to render the Mandelbrot set for:

– Serial code.

– Parallel code with n = 2, 3, 4, 5, 6, 7, 8, 16, 32 Workers.

• Extensions:

– Implement a better coloring scheme.

– Interactive zooming and sharpening.

Parallel Computing TJHSST