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

For each sample size, we compute the relative error, and then plot the results.<br />

In [6]: error=[relerror(n) for n <strong>in</strong> samples];<br />

In [7]: plot(samples,error)<br />

xlabel("Sample size (n)")<br />

ylabel("Relative error");<br />

Figure 4.4: Monte Carlo relative error for the <strong>in</strong>tegral (4.9)<br />

4.5 Improper <strong>in</strong>tegrals<br />

The quadrature rules we have learned so far cannot be applied (or applied <strong>with</strong> a poor performance)<br />

to <strong>in</strong>tegrals such as ∫ b<br />

f(x)dx if a, b = ±∞ or if a, b are f<strong>in</strong>ite but f is not cont<strong>in</strong>uous<br />

a<br />

at one or both of the endpo<strong>in</strong>ts: recall that both Newton-Cotes and Gauss-Legendre error<br />

bound theorems require the <strong>in</strong>tegrand to have a number of cont<strong>in</strong>uous derivatives on the<br />

closed <strong>in</strong>terval [a, b]. For example, an <strong>in</strong>tegral <strong>in</strong> the form<br />

∫ 1<br />

−1<br />

f(x)<br />

√<br />

1 − x<br />

2 dx<br />

clearly cannot be approximated us<strong>in</strong>g the trapezoidal or Simpson’s rule <strong>with</strong>out any modifications,<br />

s<strong>in</strong>ce both rules require the values of the <strong>in</strong>tegrand at the end po<strong>in</strong>ts which do not<br />

exist. One could try us<strong>in</strong>g the Gauss-Legendre rule, but the fact that the <strong>in</strong>tegrand does

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

Saved successfully!

Ooh no, something went wrong!