06.09.2021 Views

First Semester in Numerical Analysis with Julia, 2020a

First Semester in Numerical Analysis with Julia, 2020a

First Semester in Numerical Analysis with Julia, 2020a

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

CHAPTER 4. NUMERICAL QUADRATURE AND DIFFERENTIATION 175<br />

She tells her classmates about the cancellation of lead<strong>in</strong>g digits phenomenon, and<br />

to make her po<strong>in</strong>t more conv<strong>in</strong>c<strong>in</strong>g, she makes the follow<strong>in</strong>g experiment: let f(x) =e x ,<br />

and suppose we want to compute f ′ (2) which is e 2 . Arya uses the three-po<strong>in</strong>t midpo<strong>in</strong>t<br />

formula above to estimate f ′ (2), for various values of h, and for each case she computes<br />

the absolute value of the difference between the three-po<strong>in</strong>t midpo<strong>in</strong>t estimate and the<br />

exact solution e 2 . She tabulates her results <strong>in</strong> the table below. Clearly, smaller h does<br />

not result <strong>in</strong> smaller error. In this experiment, h =10 −6 gives the smallest error.<br />

h 10 −4 10 −5 10 −6 10 −7 10 −8<br />

Abs. error 1.2 × 10 −8 1.9 × 10 −10 5.2 × 10 −11 7.5 × 10 −9 2.1 × 10 −8<br />

Theoretical analysis<br />

<strong>Numerical</strong> differentiation is a numerically unstable problem. To reduce the truncation error,<br />

we need to decrease h, which <strong>in</strong> turn <strong>in</strong>creases the roundoff error due to cancellation of<br />

significant digits <strong>in</strong> the function difference calculation. Let e(x) denote the roundoff error <strong>in</strong><br />

comput<strong>in</strong>g f(x) so that f(x) = ˜f(x)+e(x), where ˜f is the value computed by the computer.<br />

Consider the three-po<strong>in</strong>t midpo<strong>in</strong>t formula:<br />

∣ f ′ (x 0 ) − ˜f(x 0 + h) − ˜f(x 0 − h)<br />

2h ∣<br />

=<br />

∣ f ′ (x 0 ) − f(x 0 + h) − e(x 0 + h) − f(x 0 − h)+e(x 0 − h)<br />

2h<br />

∣<br />

=<br />

∣ f ′ (x 0 ) − f(x 0 + h) − f(x 0 − h)<br />

+ e(x 0 − h) − e(x 0 + h)<br />

2h<br />

2h ∣<br />

=<br />

∣ −h2 6 f (3) (ξ)+ e(x 0 − h) − e(x 0 + h)<br />

2h ∣ ≤ h2<br />

6 M + ɛ h<br />

where we assumed |f (3) (ξ)| ≤M and |e(x)| ≤ɛ. To reduce the truncation error h 2 M/6 one<br />

would decrease h, which would then result <strong>in</strong> an <strong>in</strong>crease <strong>in</strong> the roundoff error ɛ/h. An<br />

optimal value for h can be found <strong>with</strong> these assumptions us<strong>in</strong>g Calculus: f<strong>in</strong>d the value for<br />

h that m<strong>in</strong>imizes the function s(h) = Mh2 + ɛ . Theanswerish = 3√ 3ɛ/M.<br />

6 h<br />

Let’s revisit the table Arya presented where 10 −6 was found to be the optimal value for<br />

h. The calculations were done us<strong>in</strong>g <strong>Julia</strong>, which reports 15 digits when asked for e 2 . Let’s<br />

assume all these digits are correct, and thus let ɛ =10 −16 . S<strong>in</strong>ce f (3) (x) =e x and e 2 ≈ 7.4,<br />

let’s take M =7.4. Then<br />

h = 3√ 3ɛ/M = 3√ 3 × 10 −16 /7.4 ≈ 3.4 × 10 −6

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

Saved successfully!

Ooh no, something went wrong!