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

and p(x) =x 2 implies<br />

∫ 1<br />

0<br />

p(x)dx = c 0 p(0) + c 1 p(x 1 ) ⇒ 1 3 = c 1x 2 1.<br />

We have three unknowns and three equations, so we have to stop here. Solv<strong>in</strong>g the three<br />

equations we get: c 0 =1/4,c 1 =3/4,x 1 =2/3. So the quadrature rule is of precision two<br />

and it is: ∫ 1<br />

f(x)dx = 1 4 f(0) + 3 4 f(2 3 ).<br />

0<br />

Exercise 4.1-2: F<strong>in</strong>d c 0 ,c 1 ,c 2 so that the quadrature rule ∫ 1<br />

−1 f(x)dx = c 0f(−1) +<br />

c 1 f(0) + c 2 f(1) has degree of accuracy 2.<br />

4.2 Composite Newton-Cotes formulas<br />

If the <strong>in</strong>terval [a, b] <strong>in</strong> the quadrature is large, then the Newton-Cotes formulas will give poor<br />

approximations. The quadrature error depends on h =(b−a)/n (closed formulas), and if b−a<br />

is large, then so is h, hence error. If we raise n to compensate for large <strong>in</strong>terval, then we face<br />

a problem discussed earlier: error due to the oscillatory behavior of high-degree <strong>in</strong>terpolat<strong>in</strong>g<br />

polynomials that use equally-spaced nodes. A solution is to break up the doma<strong>in</strong> <strong>in</strong>to smaller<br />

<strong>in</strong>tervals and use a Newton-Cotes rule <strong>with</strong> a smaller n on each sub<strong>in</strong>terval: this is known<br />

as a composite rule.<br />

Example 74. Let’s compute ∫ 2<br />

0 ex s<strong>in</strong> xdx. The antiderivative can be computed us<strong>in</strong>g <strong>in</strong>tegration<br />

by parts, and the true value of the <strong>in</strong>tegral to 6 digits is 5.39689. If we apply the<br />

Simpson’s rule we get:<br />

∫ 2<br />

0<br />

e x s<strong>in</strong> xdx ≈ 1 3 (e0 s<strong>in</strong>0+4e s<strong>in</strong> 1 + e 2 s<strong>in</strong> 2) = 5.28942.<br />

If we partition the <strong>in</strong>tegration doma<strong>in</strong> (0, 2) <strong>in</strong>to (0, 1) and (1, 2), and apply Simpson’s rule

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

Saved successfully!

Ooh no, something went wrong!