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 149<br />

Exercise 4.2-1: Show that the quadrature rule <strong>in</strong> Example 74 corresponds to tak<strong>in</strong>g<br />

n =4<strong>in</strong> the composite Simpson’s formula (4.4).<br />

Exercise 4.2-2: Show that the absolute error for the composite trapezoidal rule decays<br />

at the rate of 1/n 2 , and the absolute error for the composite Simpson’s rule decays at the<br />

rate of 1/n 4 , where n is the number of sub<strong>in</strong>tervals.<br />

Example 75. Determ<strong>in</strong>e n that ensures the composite Simpson’s rule approximates<br />

∫ 2<br />

1 x log xdx <strong>with</strong> an absolute error of at most 10−6 .<br />

Solution. The error term for the composite Simpson’s rule is b−a<br />

180 h4 f (4) (ξ) where ξ is some<br />

number between a =1and b =2,andh =(b − a)/n. Differentiate to get f (4) (x) = 2 x 3 . Then<br />

b − a<br />

180 h4 f (4) (ξ) = 1<br />

180 h4 2 ξ 3 ≤ h4<br />

90<br />

where we used the fact that 2<br />

ξ 3<br />

than 10 −6 , that is,<br />

≤ 2 1<br />

=2when ξ ∈ (1, 2). Now make the upper bound less<br />

h 4<br />

90 ≤ 10−6 ⇒ 1<br />

n 4 (90) ≤ 10−6 ⇒ n 4 ≥ 106<br />

90 ≈ 11111.11<br />

which implies n ≥ 10.27. S<strong>in</strong>ce n must be even for Simpson’s rule, this means the smallest<br />

value of n to ensure an error of at most 10 −6 is 12.<br />

Us<strong>in</strong>g the <strong>Julia</strong> code for the composite Simpson’s rule that will be <strong>in</strong>troduced next,<br />

we get 0.6362945608 as the estimate, us<strong>in</strong>g 10 digits. The correct <strong>in</strong>tegral to 10 digits is<br />

0.6362943611, which means an absolute error of 2 × 10 −7 , better than the expected 10 −6 .<br />

<strong>Julia</strong> codes for Newton-Cotes formulas<br />

We write codes for the trapezoidal and Simpson’s rules, and the composite Simpson’s rule.<br />

Cod<strong>in</strong>g trapezoidal and Simpson’s rule is straightforward.

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

Saved successfully!

Ooh no, something went wrong!