Section 3.11 Review of Chapter 3
Subsection 3.11.1 Methods and Formulas
Subsubsection 3.11.1.1 Polynomial Interpolation:
An exact fit to the data. For \(n\) data points it is a \(n-1\) degree polynomial. Only good for very few, accurate data points. The coefficients are found by solving a linear system of equations.
Subsubsection 3.11.1.2 Spline Interpolation:
Fit a simple function between each pair of points. Joining points by line segments is the most simple spline. Cubic is by far the most common and important. Cubic matches derivatives and second derivatives at data points. Simply supported and clamped ends are available. Good for more, but accurate points. The coefficients are found by solving a linear system of equations.
Subsubsection 3.11.1.3 Least Squares:
Makes a “close fit” of a simple function to all the data. Minimizes the sum of the squares of the errors. Good for noisy data. The coefficients are found by solving a linear system of equations.
Subsubsection 3.11.1.4 Interpolation vs. Extrapolation:
Polynomials, Splines and Least Squares are generally used for Interpolation, fitting between the data. Extrapolation, i.e. making fits beyond the data, is much more tricky. To make predictions beyond the data, you must have knowledge of the underlying process, i.e. what the function should be.
Subsubsection 3.11.1.5 Numerical Integration:
Left Endpoint:
\begin{equation*}
L_{n} = \sum_{i=1}^{n} f(x_{i-1}) \Delta x_{i}
\end{equation*}
Right Endpoint:
\begin{equation*}
R_{n} = \sum_{i=1}^{n} f(x_{i}) \Delta x_{i} \text{.}
\end{equation*}
Trapezoid Rule:
\begin{equation*}
T_{n} = \sum_{i=1}^{n} \frac{f(x_{i-1}) + f(x_{i})}{2}\Delta x_{i} \text{.}
\end{equation*}
Midpoint Rule:
\begin{equation*}
M_{n} = \sum_{i=1}^{n} f(\bar{x}_{i}) \Delta x_{i} \qquad \textrm{where}\qquad \bar{x}_{i} = \frac{ x_{i-1}+ x_{i}}{2}\text{.}
\end{equation*}
Subsubsection 3.11.1.6 Numerical Integration Rules with Even Spacing:
For even spacing: \(\Delta x = \frac{b-a}{n}\) where \(n\) is the number of subintervals, then:
\begin{equation*}
L_{n} = \Delta x \sum_{i=0}^{n-1}y_{i} = \frac{b-a}{n}\sum_{i=0}^{n-1}f(x_{i})
\end{equation*}
\begin{equation*}
R_{n} = \Delta x \sum_{i=1}^{n}y_{i} = \frac{b-a}{n}\sum_{i=1}^{n} f(x_{i})
\end{equation*}
\begin{equation*}
T_{n} = \Delta x \bigl( y_{0} + 2y_{1} + \ldots + 2y_{n-1}+ y_{n} \bigr) = \frac{b-a}{2n}\bigl( f(x_{0}) + 2f(x_{1}) + \ldots + 2f(x_{n-1}) + f(x_{n}) \bigr)
\end{equation*}
\begin{equation*}
M_{n} = \Delta x \sum_{i=1}^{n}\bar{y}_{i} = \frac{b-a}{n}\sum_{i=1}^{n}f(\bar{x}_{i})
\end{equation*}
Subsubsection 3.11.1.7 Simpson’s rule:
\begin{align*}
S_{n} \amp = \Delta x \bigl( y_{0} + 4y_{1} + 2y_{2} + 4y_{3} + \ldots + 2y_{n-2}+ 4y_{n-1}+ y_{n} \bigr)\\
\amp = \frac{b-a}{3n}\left( f(x_{0}) + 4f(x_{1}) + 2f(x_{2}) + 4f(x_{3}) + \ldots + 2f(x_{n-2}) + 4f(x_{n-1}) + f(x_{n}) \right)
\end{align*}
Subsubsection 3.11.1.8 Area of a region:
\begin{equation*}
A = - \oint_{C}y \, dx\text{,}
\end{equation*}
where \(C\) is the counter-clockwise curve around the boundary of the region. We can represent such a curve, by consecutive points on it, i.e. \(\bar{x}= (x_{0}, x_{1}, x_{2}, \ldots, x_{n-1}, x_{n})\text{,}\) and \(\bar{y}= (y_{0}, y_{1}, y_{2}, \ldots, y_{n-1}, y_{n})\) with \((x_{n},y_{n}) = (x_{0},y_{0})\text{.}\) Applying the trapezoid method to the integral (3.3.4):
\begin{equation*}
A = - \sum_{i=1}^{n} \frac{y_{i-1}+ y_{i}}{2}\, (x_{i} -x_{i-1})
\end{equation*}
Subsubsection 3.11.1.9 Accuracy of integration rules:
Right and Left endpoint are \(O(\Delta x)\) Trapezoid and Midpoint are \(O(\Delta x^{2})\) Simpson is \(O(\Delta x^{4})\)
Subsubsection 3.11.1.10 Double Integrals on Rectangles:
Centerpoint:
\begin{equation*}
C_{mn}= \sum_{i,j=1,1}^{m,n}f(c_{ij}) A_{ij}\text{,}
\end{equation*}
where
\begin{equation*}
c_{ij}= \left( \frac{x_{i-1}+ x_{i}}{2}, \frac{y_{i-1}+ y_{i}}{2}\right).
\end{equation*}
Centerpoint – Evenly spaced:
\begin{equation*}
C_{mn}= \Delta x \Delta y \sum_{i,j=1,1}^{m,n}z_{ij}= \frac{(b-a)(d-c)}{mn}\sum_{i,j=1,1}^{m,n}f(c_{ij})
\end{equation*}
Four corners:
\begin{equation*}
F_{mn}= \sum_{i,j=1,1}^{m,n}\frac{1}{4}\left( f(x_{i},y_{j}) + f(x_{i},y_{j+1}) + f(x_{i+1},y_{i}) + f(x_{i+1},y_{j+1}) \right) A_{ij}
\end{equation*}
Four Corners – Evenly spaced:
\begin{equation*}
\begin{split}F_{mn}&= \frac{A}{4}\left( \sum_{\text{corners}}f(x_{i},y_{j}) + 2 \sum_{\text{edges}}f(x_{i},y_{j}) + 4 \sum_{\text{interior}}f(x_{i},y_{j}) \right)\\&= \frac{(b-a)(d-c)}{4mn}\sum_{i,j = 1,1}^{m,n}W_{ij}f(x_{i},y_{j})\end{split}
\end{equation*}
where
\begin{equation*}
W = \left( \begin{array}{cccccccc}1 & 2 & 2 & 2 & \cdots & 2 & 2 & 1 \\ 2 & 4 & 4 & 4 & \cdots & 4 & 4 & 2 \\ 2 & 4 & 4 & 4 & \cdots & 4 & 4 & 2 \\ \vdots & \vdots & \vdots & \vdots & \cdots & \vdots & \vdots & \vdots \\ 2 & 4 & 4 & 4 & \cdots & 4 & 4 & 2 \\ 1 & 2 & 2 & 2 & \cdots & 2 & 2 & 1 \\\end{array} \right)\text{.}
\end{equation*}
Double Simpson:
\begin{equation*}
S_{mn}= \frac{(b-a)(d-c)}{9mn}\sum_{i,j = 1,1}^{m,n}W_{ij}f(x_{i},y_{j})\text{,}
\end{equation*}
where
\begin{equation*}
W = \left( \begin{array}{cccccccc}1 & 4 & 2 & 4 & \cdots & 2 & 4 & 1 \\ 4 & 16 & 8 & 16 & \cdots & 8 & 16 & 4 \\ 2 & 8 & 4 & 8 & \cdots & 4 & 8 & 2 \\ 4 & 16 & 8 & 16 & \cdots & 8 & 16 & 4 \\ \vdots & \vdots & \vdots & \vdots & \cdots & \vdots & \vdots & \vdots \\ 2 & 8 & 4 & 8 & \cdots & 4 & 8 & 2 \\ 4 & 16 & 8 & 16 & \cdots & 8 & 16 & 4 \\ 1 & 4 & 2 & 4 & \cdots & 2 & 4 & 1 \\\end{array} \right)\text{.}
\end{equation*}
Subsubsection 3.11.1.11 Integration based on triangles:
-
Triangulation: Dividing a region up into triangles.
-
Triangles are suitable for odd-shaped regions.
-
A triangulation is better if the triangles are nearly equilateral.
Three corners:
\begin{equation*}
T_{n} = \sum_{i=1}^{n} \bar{f}_{i} A_{i}
\end{equation*}
where \(\bar{f}\) is the average of \(f\) at the corners of the \(i\)-th triangle. Area of a triangle with corners \((x_{1},y_{1})\text{,}\) \((x_{2},y_{2})\text{,}\) \((x_{3},y_{3})\text{:}\)
\begin{equation*}
A = \frac{1}{2}\left| \text{det}\left( \begin{array}{ccc}x_1 &x_2 &x_3\\ y_1 &y_2 &y_3\\ 1 &1 &1\\\end{array} \right) \right|
\end{equation*}
Centerpoint:
\begin{equation*}
C = \sum_{i=1}^{n} f(\bar{x}_{i},\bar{y}_{i}) A_{i}, \quad\text{with}
\end{equation*}
\begin{equation*}
\bar{x}= \frac{x_{1} + x_{2} + x_{3}}{3}\quad\text{and}\quad \bar{y}= \frac{y_{1} + y_{2} + y_{3}}{3}\,.
\end{equation*}
Subsubsection 3.11.1.12 Finite Differences
Forward Difference:
\begin{equation*}
f'(x_{i}) = y'_{i} \approx \frac{y_{i+1}- y_{i}}{x_{i+1}-x_{i}}
\end{equation*}
Backward Difference:
\begin{equation*}
f'(x_{i}) \approx \frac{y_{i} - y_{i-1}}{x_{i}-x_{i-1}}
\end{equation*}
Central Difference:
\begin{equation*}
f'(x_{i}) = y'_{i} \approx \frac{y_{i+1}- y_{i-1}}{2h}
\end{equation*}
Higher order central differences:
\begin{align*}
f''(x_{i})\amp= y''_{i} \approx \frac{y_{i+1}- 2 y_{i} + y_{i-1}}{h^{2}}\\
f'''(x_{i})\amp= y'''_{i} \approx \frac{1}{2 h^{3}}\left[y_{i+2}- 2y_{i+1}+ 2y_{i-1}- y_{i-2}\right] \\
f^{(4)}(x_{i})\amp= y^{(4)}_{i} \approx \frac{1}{h^{4}}\left[y_{i+2}- 4y_{i+1}+ 6y_{i} - 4y_{i-1}+ y_{i-2}\right]
\end{align*}
Partial Derivatives: Denote \(u_{i,j}= u(x_{i},y_{j})\text{.}\)
\begin{align*}
u_{x}(x_{i},y_{j})\amp\approx \frac{1}{2h}\left( u_{i+1,j}- u_{i-1,j}\right)\\
u_{y}(x_{i},y_{j})\amp\approx \frac{1}{2k}\left( u_{i,j+1}- u_{i,j-1}\right)\\
u_{xx}(x_{i},y_{j})\amp\approx \frac{1}{h^{2}}\left( u_{i+1,j}-2u_{i,j}+ u_{i-1,j}\right)\\
u_{yy}(x_{i},y_{j})\amp\approx \frac{1}{k^{2}}\left( u_{i,j+1}-2u_{i,j}+ u_{i,j-1}\right)\\
u_{xy}(x_{i},y_{j})\amp\approx \frac{1}{4hk}\left( u_{i+1,j+1}- u_{i+1,j-1}- u_{i-1,j+1}+ u_{i-1,j-1}\right)
\end{align*}
Subsubsection 3.11.1.13 Sources of error:
- Truncation
-
the method is an approximation.
- Roundoff
-
double precision arithmetic uses \(\approx 15\) significant digits.
- Loss of precision
-
an amplification of roundoff error due to cancellations.
- Bad conditioning
-
the problem is sensitive to input errors.
Error can build up after multiple calculations.
See Table 3.10.1.
Subsection 3.11.2 MATLAB
Subsubsection 3.11.2.1 Data Interpolation:
Use the plot command
plot(x,y,'*') to plot the data. Use the Basic Fitting tool to make an interpolation or spline. If you choose an \(n-1\) degree polynomial with \(n\) data points the result will be the exact polynomial interpolation. If you select a polynomial degree less than \(n-1\text{,}\) then MATLAB will produce a least squares approximation.
Subsubsection 3.11.2.2 Functions of 2 Variables and Meshgrids:
-
f= @(x,y) sin(x.*y)./sqrt(x+y) -
[X Y]=meshgrid(-1:.01:2, 0:.01:3) -
make a 2-d grid of points.
-
Z = f(X,Y) -
evaluate the function at all points on the grid.
-
mesh(X,Y,Z)orsurf(X,Y,Z) -
plot the function on the grid.
Subsubsection 3.11.2.3 Integration:
-
integral(f,a,b) -
integral2(f,a,b,c,d)
Example: MATLAB uses an advanced form of Simpson’s method.
>> f = @(x,y) sin(x.*y)/sqrt(x+y) >> I = integral2(f,0,1,0,2)
Subsubsection 3.11.2.4 Integration over non-rectangles:
Redefine the function to be zero outside the region. For example: Integrates \(f(x,y) = \sin^{3}(xy)\) on the triangle with corners \((0,0)\text{,}\) \((0,2)\text{,}\) and \((1,0)\text{.}\)
>> f = @(x,y) sin(x.*y).^3.*(2*x + y <= 2) >> I = integral2(f,0,1,0,2)
Triangles: MATLAB stores triangulations as a matrix of vertices
V and triangles T.-
T = delaunay(V)(ordelaunay(x,y)) -
Produces triangles from vertices.
-
trimesh(T,x,y) -
trimesh(T,x,y,z) -
trisurf(T,x,y) -
trisurf(T,x,y,z)
Subsubsection 3.11.2.5 Logical expressions
(2*x + y <= 2), (x.^2+y.^2<=1) are examples of logical expressions. If a logical expression is true it is given the value \(1\text{.}\) If false, then it is assigned the value \(0\text{.}\)
