Class Notes (839,096)
Canada (511,185)
CH E374 (5)
Lecture

module5_filled1.pdf

15 Pages
52 Views

Department
Chemical Engineering
Course Code
CH E374
Professor
Joe Mmbaga

This preview shows pages 1,2,3. Sign up to view the full 15 pages of the document.
Description
CHE 374 Computational Methods in Engineering MODULE 5: Numerical Differentiation & Integration Differentiation basics Definition of the derivative of a function f of x at x = x : 0 df   f   lim f  f x  0 (1.1) dx 0 xx0 x x 0 xx0 . In numerical analysis, the difference x  x x stays finite (does not really go to 0 zero). Derivatives are therefore approximated by differences: f    f  f  0 (1.2) 0 x . An important theoretical result (known as mean-value theorem): in the interval f   f x 0 x0,x there is a point  for which exactly f   with  generally x x0 unknown. Finite difference approximations Suppose we know the function f at positions xi1 ix i 1hat are spaced by a distance h We distinguish three approximations to the derivative at x  x : i e Forward difference: riat f( ) xrede df  fi1 fi T dx i x x x x x 1 i- i i1 1 Backward difference: tie df  fi fi1 f( ) x era dx i x Tre d x x 1 xi- x i i1 iatie Central difference: f( ) x e der Tr df  fi1 fi1 dx 2x i x 1 xi- x i x i1 From Figure 1c, we get the impression that the central difference approximation is the most accurate. This we can ‘prove’ by means of Taylor expansions: x2 x 3 fi1 f ixf i fi fiO x  4 (1.3) 2 6 2 3 f  f xf  x f  x f O x 4 (1.4) i1 i i 2 i 6 i   The O x 4 indicates that the leading order of the terms left out of the expansion is   4. Equation (1.3) can be rewritten such that i1 fi x x2 3 fi  fi i O x  (1.5) x 2 6 2 Thus  fi1 fi i  x O   (1.6) This means that the forward difference approximation of the first derivative has an error proportional to x . In numerical jargon: the forward difference approximation of the first derivative is first-order accurate (accurate to x to the first power). This is an equation similar to the one obtained in Module 1, when we dv approximated the acceleration . dt Equation (1.4) can similarly be rewritten as 2 f  fi fi1 x f  x f O x 3 (1.7) i x 2 i 6 i   thus  fi fi1 i  O   (1.8) x The backward difference approximation of the first derivative also has first-order accuracy. Subtracting Eq. (1.4) from Eq. (1.3) gives: 3 f  f  2xf  2 x f O x 4 (1.9) i1 i1 i 6 i   This can be rewritten as 2  i1 fi1 x  4 fi 2x  6 f iO x   (1.10) thus i1 fi1 2 fi O   (1.11) 2x 2 Apparently, the central approximation of the first derivative has second-order (h ) accuracy. For small x (which virtually always is the case), second-order accuracy is much more accurate than first-order accuracy. Central difference being more accurate than forward or backward difference could already be anticipated from the figure. 3 The second derivative (and its accuracy) follows from adding up Equations (1.3) and(1.4): (central derivative) f  f  2f h f O x 4 (1.12) i1 i1 i i   thus f 2f  f fi i1 i2 i O   2 (1.13) x The expressions given above for first and second-order derivatives and their level of accuracy will largely cover your needs. Extensions can be made towards higher derivatives, and higher-order accuracy. Partial derivatives Let f (x,y)be a function with two variables. If we keep y constant and differentiate f (assuming f is differentiable) with respect to the variable , we obtain what is called the partial derivative of f with respect to x which is denoted by f or fx x Similarly If we keep x constant and differentiate f (assuming f is differentiable) with respect to the variable y, we obtain what is called the partial derivative of f with respect to y which is denoted by f or fy y We might also define partial derivatives of function f as follows: f fx x,y f x,   x0 O( ) (1.14) x x And with respect to y f  lim f ,y y f x y  O( x) (1.15) y y0 y The above are forward differences. Similar expressions may be made for backward and central approximations. The representation and calculation methods follow similar approach as ordinary differential equations, but keeping in mind that we have more than one dependent variable. 4 Second partial derivatives Forward difference of the second partial derivative at a point i,j: O(x) 2  f f  i2x,y 2fjxx,yif x ,y j  i j  x 2 2 (1.16) i, j   2 f  ,y 2y 2f  ,y y  f x ,y     f i j i j i j (1.17) y 2 i, j   2 Backward difference of the second partial derivative at a point i,j: O(x) 2 f  ,y 2 x xy  f x 2x,y   f i j i j i j (1.18) x 2 i, j   2  f f  iy j x ,y i jf x ,y y i j  2 2 (1.19) y i, j   2 Central-difference approximation of the second partial derivative: O(x ) 2  f f  ix,y 2fj ,y   i j  i j  (1.20) x2 x 2 i, j    f f  ,y y 2fx ,y f x , y  2 i j i 2j i j (1.21) y i, j   5 Error propagation through differentiation The figure below demonstrates a danger when numerically differentiating. Smooth data noisy data If the data contain noise, this noise is amplified when differentiating. Remember cancellation errors introduced when two nearly equal numbers that contain small errors are subtracted (subtractive cancellation). 6 Integration basics There are two main reasons for you to need to do numerical integration: analytical integration may be impossible or infeasible, or one may wish to integrate tabulated data rather than known functions. The problem of numerical integration is equivalent to evaluating the general integral: b I(f )   f (x)d x (1.22) a In some cases we only know f (x)as a collection of points f  f (x ). In other cases i i we know a closed expression for f (x) but the integral cannot be evaluated analytically. In such cases we also base our numerical estimate of the integral on a number of function evaluations i  f (xi). 7 Let us define P (x) as a polynomial that satisfies f (x)at some k points x 0 x1, x2...x k. We then let: I(f )  I(k ) (1.23) We assume: I(Pk)  w0f (x0)  w1f (1 )  ... k w k (x ) (1.24) where the w aie weights. It can be shown that for equally spaced grid points, and the weights being set equal to the Lagrange polynomials, that the common integration formulas can be derived. Specifically, it can be shown that for: 1 k 1 I(P k  ba f (a) f (b)  Trapazoidal rule 2 1  ab  k  2 I(P )  a  f (a)  4f    f (b) Simpson's rule k 6  2    Newton-Cotes First approach (midpoint rule). The interval   is divided in equal pieces of width h  i1x i The integral is estimated as the sum of all pieces: I  fxi1 i h (1.25)  2  8 Second approach (trapezoidal rule). Inst
More Less
Unlock Document

Only pages 1,2,3 are available for preview. Some parts have been intentionally blurred.

Unlock Document
You're Reading a Preview

Unlock to view full version

Unlock Document

Log In


OR

Join OneClass

Access over 10 million pages of study
documents for 1.3 million courses.

Sign up

Join to view


OR

By registering, I agree to the Terms and Privacy Policies
Already have an account?
Just a few more details

So we can recommend you notes for your school.

Reset Password

Please enter below the email address you registered with and we will send you a link to reset your password.

Add your courses

Get notes from the top students in your class.


Submit