Gaussian quadrature is a method for approximating integrals using nodes \(x_1, \ldots, x_n\) that are not equally spaced, and also using specially chosen weights \(w_1, \ldots, w_n\) so that \[\int_{-1}^1 f(x) \, dx \approx w_1 f(x_1) + \ldots + w_n f(x_n).\] The simplest case is when \(n = 2\), then \[\int_{-1}^{1} f(x) \,dx \approx f\left(\tfrac{\sqrt{3}}{3}\right) + f \left( \tfrac{\sqrt{3}}{3} \right).\] When \(n = 3\), the formula is \[\int_{-1}^1 f(x) \, dx \approx \tfrac{5}{9} f \left( -\sqrt{\tfrac{3}{5}} \right) + \tfrac{8}{9} f(0) +\tfrac{5}{9} f \left( \sqrt{\tfrac{3}{5}} \right).\] We derived these formulas in class today. Gaussian quadrature with n nodes has degree of precesion \(2n-1\). Gaussian quadrature gives the best possible degree of precision for a given number of nodes.
The nodes for Gaussian quadrature are the roots of the Legendre polynomials (which we haven’t talked about). Gaussian quadrature has the potential to be more accurate than composite Simpson’s rule, but it is also more complicated.
We used Gaussian quadrature with n=3 nodes to estimate the following integrals.
\(\displaystyle\int_{-1}^1 \frac{1}{\sqrt{2\pi}} e^{-x^2/2} \, dx.\)
\(\displaystyle\int_1^2 \frac{\ln x}{x} \, dx\).
Do do the last integral, you need to do a change of variables first so you can integrate on the interval \([-1,1]\) instead. You can use this formula which follows from a quick u-substitution: \[\int_a^b f(u)\, du = \int_{-1}^{1} h f(m + hx) \, dx\] where \(m = \frac{1}{2}(a+b)\) and \(h = \frac{1}{2}(b-a)\).
Today we talked about improper integrals and double integrals. An improper integral is an integral involving infinity. When an improper integral is too complicated to calculate exactly, you can often get an upper bound for the error on the tail of the integral.
Idea. Approximate \(\displaystyle\int_a^\infty f(x) \,dx\) using \(\displaystyle\int_a^N f(x) \,dx\) with a large \(N\), and then choose \(N\) big so that the missing part \(\displaystyle\int_N^{\infty} f(x) \, dx\) is small. We did two examples in class:
\(\displaystyle\int_0^{\infty} e^{-x^2} \, dx\). Estimate the error using \(N = 10\). In this case, we estimated \(e^{-x^2} \le e^{-Nx}\) on \([N, \infty)\) and \[\int_N^{\infty} e^{-x^2} \, dx \le \int_N^\infty e^{-Nx} \,dx = \frac{1}{N}e^{-N^2}.\] When \(N = 10\), this is less than \(3.72 \times 10^{-45}\).
Choose \(N\) so that \(\displaystyle\int_1^\infty \frac{\ln x}{x^4} \, dx\) can be approximated by \(\displaystyle\int_1^N \frac{\ln x}{x^4} \, dx\) with an error less than \(10^{-12}\). Hint: You can replace \(\ln x\) by \(x\) to get a larger simpler formula in your estimate.
We spent the last ten minutes giving a very brief explanation of how you can use numerical integration methods to approximate double integrals. This is Section 4.4 in the book. We did one example:
Today we looked a numerical approximations of the derivative. These can be useful in engineering if you have a function that doesn’t have a formula (like if you are measuring the speed of a car at discrete instants in time). We did this lab in class:
In the lab we saw the numerical differentiation is numerically unstable, that is you don’t get better approximations just by choosing a smaller \(h\) (or \(\Delta x\)).