Chapters 4, 5 and 6
Lecture Notes
Dr. John Travis
 

Chapter 4 - NUMERICAL DIFFERENTIATION AND INTEGRATION

Remark: In many real-life mathematical models, one must utilize the integral or the derivative of a given function. Sometimes, these functions are easily differentiable or integrable. Many times they are not or doing so would be difficult. The question becomes determining how we can find good approximations to derivatives evaluated at given points and to definite integrals.
 

One idea: For any given function (or set of data points), determine a set of n+1 data points (x,y) and use the concepts from Chapter 3 to find a polynomial approximation to the original function. Usually, this polynomial approximation is very easy to differentiate and integrate. (Actually, this is not quite as true when using the Newton-type forms of the polynomial.) Use the resulting values from the polynomial as approximate values for the exact values.
 

Computing Assignment: Determine the Lagrange interpolating polynomial to f(x)=1/(1+x2) on the interval [-3,3] of degree n for various n. (Use the matrix approach by setting up the Vandermonde matrix, etc) Then, differentiate and integrate this polynomial exactly using formulas and compare with the exact values. Experiment with at least two other nontrivial functions for f(x) for which you can get an exact answer via calculus.
 

Remark: In the following, we will only consider determining derivatives at given points and definite integrals since each ot these is an actual number. If an interval approximation to the derivative function is desired or the indefinite integral is needed, the ideas which follow will need to be implemented over and over, once for each new value desired.
 

Derivatives over [a,b]:

  1. Partition the interval [a,b] into x0, x1, ... ,xn.
  2. Use one of the following methods to determine an approximation mk to the derivative for each xk.
  3. Connect these points (xk,mk ) with some interpolant from chapter 3.
Derivative Methods:
  1. Forward-Difference formula - page 140. (Difference quotient when h>0.) Has error O(h).
  2. Backward-Difference formula - page 140. (Difference quotient when h<0.) Has error O(h).
  3. Centered-Difference (Midpoint) formula - page 142. (Difference quotient centered around a.) Has error O(h2).
  4. See various formulas on page 142, etc.
  5. Second Derivative formula - page 146
Remark: If one wants the derivative at several points xk over an interval, use a difference formula recursively. However, numerical differentiation should be avoided as much as possible since the process is not stable over large intervals.

Homework: page 146, #5, 6
 

Integrals over [a,b]:

  1. Partition the interval [a,b] into x0, x1, ... ,xn.
  2. Use one of the following methods to determine an approximation Ik for the definite integral from x0 to xk .
  3. Connect these points (xk,Ik ) with some interpolant from chapter 3.
  4. Note that the answer might be off by an arbitrary constant.
Defn: Suppose A is an approximation to E. We say A is an order O(hp) approximation to the exact value E if, by using Taylor's expansions, we have E - A = O(hp), where h=a constant difference in x values. That is, if you take the difference of E and A, you get terms which only have powers of h bigger than or equal to p.

Numerical Integration Methods:

From the definition of integration (Limits of Reimann sums), one perhaps would think that an approximation to the value of the definite integral could be found by replacing the infinite sum with a finite one. In general, numerical quadrature is approximating the definite integral with the finite sum:
S ak f(xk),
where the xk are a reasonably fine finite partition of the interval [a,b].
Methods:  To find an approximate value for the definite integral from a to b, first break up the interval into several smaller intervals (most often of uniform width h). Then, add up approximate values of the integral on each. The order of the method is the degree of the highest polynomial for which the method will obtain the exact integral.
  1. Midpoint Rule: If the number of subintervals is even, on each pair of subintervals approximate the original function with a constant having the value of the function at the center of the subinterval (ie. a constant interpolant). Notice, this method does not require the function to be evaluated at either endpoint and so is a good choice to use if the integrand is singular at an endpoint.
  2. Trapezoidal Rule: On each subinterval, approximate the "area under the curve" by using trapezoids. This is equivalent to approximating the actual function with a piecewise linear one connecting the function values at the endpoints of the little intervals. Lagrange gives the formula for linear interpolant.
  3. Simpson's Rule: If the number of subintervals is even, on each pair of subintervals approximate the original function with a quadratic and find the area using this piecewise quadratic. Lagrange gives the formula for quadratic interpolant.
  4. Gaussian Quadrature: Most accurate. Allow both coeffiecients ak and xk to be variable. Use table on page 110 for [a,b]=[-1,1].
Homework: page98, #7, 9, 11 (a,c;g only) page 105, #7, page 111, #1, 2 (a,c,g only)

Computing Assignments: Implement as separate functions the forward difference, backward difference and central difference methods for determining the derivative as well as the trapezoidal rule, Simpson's rule and the midpoint rule for determining the definite integral. Approximate the deriviative and integral of f(x) = 1/(1+x2) for several different values. Compare your answers with the known exact derivative f'(x) = -2x/(1+x 2)2 and the (indefinite) integral tan-1(x). Consider other functions also and compare your approximation with the exact value via calculus.


Chapter 5 - SOLVING INITIAL VALUE PROBLEMS



Ex: Solving y'=4y gives y(t)=Ce4t , where C is any constant. To eliminate the arbitrary constant C, we would need an initial condition for y(a) given. For example, y(0)=3 implies y(t)=3e 4t.
 

General Problem: Solve for y(t) on the interval a < t < b,

(IVP) y'=f(t,y(t))

y(a) = y0 , given.
 

Remark: Elementary Ordinary Differential Equation (ODE) theory gives mathematical discussions on the existence and uniqueness of exact solutions to (IVP). (See Well-Posed Condition on page 151.) We will always assume that we are given problems for which solutions exist and are unique.
 

Remark: If (IVP) cannot be solved by analytical methods, we will need to find a discrete solution by finding an approximation to the solution at a finite number of points. Once we have these points, we can use approximation theory from Chapter 3 to find an approximate continuous solution.
 

Notation: Given interval endpoints a and b; number of data points desired n+1; and the function f(t,y) from the D.E....

Let h=(b-a)/n, be the mesh size with equally spaced mesh points given by tj=a+j h; wj= algorithm generated approximation for y(tj); and set fj=f(t j,wj), for j=0,1,2,...,n.
 

Euler's Method:

w0 = y 0,

wj+1 = fwj+h*fj , for j=0,1,2,...n.

Derivations of Euler's Method:

(1) Take y'(tj) = f(tj,y(t j)) and replace y(tj) by a forward difference formula.

(2) Use Taylor's theorem to expand y(tj+1 ) about tj and throw away nonlinear terms. Easily gives local error. Global Error, pg 154.

(3) Integrate from tj to tj+1 and approximate f(u,y(u)) under the integral by a constant evaluated at u=t j.

(4) Graphically, find the equation of the tangent line at t=tj and evaluate it at t=tj+1 to approximate y(tj+1).

But m=y'=f(tj,y(tj)) gives y-wj = fj(t - tj). Plugging in t=tj+1 gives the method.
 

Assignment: Program Euler's Method in for solving the Differential Equations above. Represent the numerical solution graphically and compare it graphically with the known exact solutions. Give output corresponding to several different values for the step size h.

Remark: We would like to compare methods for solving (IVP) to see which are "better" to use. To do this, consider the difference equation written in the form wk+1 = wj + h*f(tk,wk), where f is "all the rest" of the method. Define the local truncation error of a method to be t(h) = (y(t k+1) - y(tk))/h + f(tk,yk). The order of the method is the lowest power of h remaining in t(h) after expanding all terms about t=tk and simplifying.
 

Result: Euler's method is order 1.
 

Taylor's Methods: page 156

To develop methods of order higher than one, use the Taylor's exansion for y(tk+h) about tk and note that the derivatives of y can be obtained to arbitrarly high degree by using the D.E. y'=f(t,y), y''=f'(t,y), y'''=f''(t,y), etc, where f(t,y(t)) is a given function.
 

Homework: page 159, #3, 4, 7.
 

Runge Kutta Methods:

Instead of evaluating f(t,y) only at "nodal" points, allow this function to be evaluated at points between nodes. The extra degrees of freedom give higher order methods which don't involve the derivative calculations needed in Taylor's methods.

(a) Midpoint Method - page 163

(b) Modified Euler Method - page 163

(c) Heun's Method - page 163

(d) Classical Runge-Kutta Method - page 164 (This is the method most often used in practice.)
 

Homework: page 166, #4, 11 (Feel free to use Software.)
 

Multi-Step Methods: page 168

Instead of only using information at time t to get the approximation at time t+h, use the computational values from previous time steps also. This enables one to get methods of high accuracy without the complexity of using the Runge-Kutta methods. The tradeoff is that this type of method needs more that one starting value and these must be generated by a single-step method.

-Adam's-Bashforth Methods - page 169, explicitly gives wk+1.

-Adam's-Moulton Methods - page 170, implicitly gives wk+1.

Often, these multi-step methods are used together with an Adam's-Bashforth method used to give a first approximation to w k+1 and then an Adam's-Moulton method used to improve this value.
 

Computing Assignment:

Implement both the Midpoint and Classical Runge-Kutta methods.
 

Optional Programming Assignment:

Implement the Adam's Fourth-Order Predictor-Corrector Algorithm on page 266.


Chapter 6 - SOLVING SYSTEMS OF LINEAR EQUATIONS



Discuss:
 

  1. System of equations
  2. Matrix notation and the operations on matrices.
  3. Solving Diagonal Systems and Triangular Systems.
  4. Gaussian Elimination.
  5. Factorization of Matrices and using this to obtain the determinant in O(n3) time (vs. n! time with cofactor expansion)
  6. Other factorizations: CROUT, DOOLITTLE, CHOLESKY
  7. Triangular Solvers.
Remark: It is generally better to consider solving systems of equations in the matrix factorization context since in many situations this leads to a significant computational savings.

(a) Determination of A-1 using the factorization. Notice, if zk is the kth column of A-1 and ek is the column vector with all zeros except for a one in the kth position, we can write the matrix equation A*A-1 = I as n matrix equations A*zk = ek. Factoring the matrix A into A=LU once, yields LUzk=ek, and notice each of these can be solved in O(n2) time.

(b) Consider a tensor product interpolating surface x(u,v) = S S ci,j Ai(u) Bj(v), where A i(u) and Bj(v) are basis functions. Suppose we are given data points to interpolate xi,j. Plugging these points into the above tensor product yields a system of equations X=ACB, where X, A, C, B are matrices. The formal solution of this is C=A-1XB-1 , which requires O(n6) operations. Using a factorization process carefully yields only O(n4) operations - a significant savings for even small systems.
 
 

PROGRAMMING ASSIGNMENTS FOR MAT/CSC 381
 
 
 
 

NAME _____________________________-



Check for correctness, legibility, test cases, presentation in MathCad, look for programming extra's or extra effort.
 

_____ Bernstein
 
 
 
 
 

_____ Bisection
 
 
 
 
 

_____ Newtons
 
 
 
 
 

_____ Secant
 
 
 
 
 

_____ Newton's Divided Differences
 
 
 
 
 

_____ MathCad Splines
 
 
 
 
 

_____ Lagrange Polynomial Derivatives and Integrals
 
 
 
 
 

_____ Difference Formulas
 
 
 
 
 

_____ Quadrature Formulas
 
 
 
 
 

_____ Euler's Method
 
 
 
 
 

_____ 2nd Order Taylor's Method
 
 
 
 
 

_____ Midpoint Runge Kutta
 
 
 
 
 

_____ Classical Runge Kutta