19.09.2015 Views

Prentice.Hall.Introduction.to.Java.Programming,.Brief.Version.9th.(2014).[sharethefiles.com]

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

iteration count (line 28). The method returns COUNT_LIMIT if the sequence is<br />

bounded (line 31).<br />

The loop in lines 8–9 examines each point (x, y) for - ˛2 6 x 6 2 and<br />

- ˛2 6 y 6 2 with interval 0.01 <strong>to</strong> see if its corresponding <strong>com</strong>plex number<br />

c = x + yi is in the Mandelbrot set (line 10). If so, paint the point black (line<br />

12). If not, set a color that is dependent on its iteration count (line 15). Note that<br />

the point is painted in a square with width u and height 1. All the points are<br />

scaled and mapped <strong>to</strong> a grid of 400-by-400 pixels (lines 14–15). Note that the<br />

values 77, 58, and 159 are set arbitrarily. You may set different numbers <strong>to</strong> get<br />

new colors.<br />

Complete the program <strong>to</strong> draw a Mandelbrot image, as shown in Figure<br />

15.13a.<br />

**15.21 (Julia set) The preceding exercise describes Mandelbrot sets. The Mandelbrot<br />

set consists of the <strong>com</strong>plex c value such that the sequence z n + 1 = z 2 n + c is<br />

bounded with z 0 fixed and c varying. If we fix c and vary z 0 (= x + yi), the<br />

point (x, y) is said <strong>to</strong> be in a Julia set for a fixed <strong>com</strong>plex value c, if the function<br />

z n + 1 = z 2 n + c stays bounded. Revise Exercise 15.20 <strong>to</strong> draw a Julia set<br />

as shown in Figure 15.13b. Note that you only need <strong>to</strong> revise the count<br />

method by using a fixed c value (- ˛0.3 + 0.6i).<br />

15.22 (Use the Rational class) Write a program that <strong>com</strong>putes the following summation<br />

series using the Rational class:<br />

1<br />

2 + 2 3 + 3 4 + c + 98<br />

99 + 99<br />

100<br />

You will discover that the output is incorrect because of integer overflow (<strong>to</strong>o<br />

large). To fix this problem, see <strong>Programming</strong> Exercise 15.17.<br />

<strong>Programming</strong> Exercises 597

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!