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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

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

which is <strong>in</strong> good agreement <strong>with</strong> the optimal value 10 −6 of Arya’s numerical results.<br />

Exercise 4.6-2: F<strong>in</strong>d the optimal value for h that will m<strong>in</strong>imize the error for the<br />

formula<br />

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

− h h 2 f ′′ (ξ)<br />

<strong>in</strong> the presence of roundoff error, us<strong>in</strong>g the approach of Section 4.6.<br />

a) Consider estimat<strong>in</strong>g f ′ (1) where f(x) =x 2 us<strong>in</strong>g the above formula. What is the<br />

optimal value for h for estimat<strong>in</strong>g f ′ (1), assum<strong>in</strong>g that the roundoff error is bounded by<br />

ɛ =10 −16 (which is the mach<strong>in</strong>e epsilon 2 −53 <strong>in</strong> the 64-bit float<strong>in</strong>g po<strong>in</strong>t representation).<br />

b) Use <strong>Julia</strong> to compute<br />

f n(1) ′ = f(1+10−n ) − f(1)<br />

,<br />

10 −n<br />

for n =1, 2, ..., 20, and describe what happens.<br />

c) Discuss your f<strong>in</strong>d<strong>in</strong>gs <strong>in</strong> parts (a) and (b) and how they relate to each other.<br />

Exercise 4.6-3: The function ∫ x<br />

√1<br />

0 2π<br />

e −t2 /2 dt is related to the distribution function<br />

of the standard normal random variable; a very important distribution <strong>in</strong> probability and<br />

statistics. Often times we want to solve equations like<br />

∫ x<br />

0<br />

1<br />

√<br />

2π<br />

e −t2 /2 dt = z (4.14)<br />

for x, where z is some real number between 0 and 1. This can be done by us<strong>in</strong>g Newton’s<br />

method to solve the equation f(x) =0where<br />

f(x) =<br />

∫ x<br />

0<br />

1<br />

√<br />

2π<br />

e −t2 /2 dt − z.<br />

Note that from Fundamental Theorem of Calculus, f ′ (x) = 1 √<br />

2π<br />

e −x2 /2 . Newton’s method will<br />

require the calculation of<br />

∫ pk<br />

0<br />

1<br />

√<br />

2π<br />

e −t2 /2 dt (4.15)<br />

where p k is a Newton iterate. This <strong>in</strong>tegral can be computed us<strong>in</strong>g numerical quadrature.<br />

Write a <strong>Julia</strong> code that takes z as its <strong>in</strong>put, and outputs x, such that Equation (4.14) holds.<br />

In your code, use the <strong>Julia</strong> codes for Newton’s method and the composite Simpson’s rule<br />

you were given <strong>in</strong> class. For Newton’s method set tolerance to 10 −5 and p 0 =0.5, and for

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

Saved successfully!

Ooh no, something went wrong!