Lecture 2: Numerical Differentiation. Derivative as a gradient

Slides:



Advertisements
Similar presentations
Example Project and Numerical Integration Computational Neuroscience 03 Lecture 11.
Advertisements

Formal Computational Skills
Roundoff and truncation errors
2009 Spring Errors & Source of Errors SpringBIL108E Errors in Computing Several causes for malfunction in computer systems. –Hardware fails –Critical.
Optimization of thermal processes
Numerical Analysis 1 EE, NCKU Tien-Hao Chang (Darby Chang)
Computational Methods in Physics PHYS 3437
CSE Differentiation Roger Crawfis. May 19, 2015OSU/CIS 5412 Numerical Differentiation The mathematical definition: Can also be thought of as the.
Numerical Computation
2. Numerical differentiation. Approximate a derivative of a given function. Approximate a derivative of a function defined by discrete data at the discrete.
Lecture 18 - Numerical Differentiation
CE33500 – Computational Methods in Civil Engineering Differentiation Provided by : Shahab Afshari
EARS1160 – Numerical Methods notes by G. Houseman
ECIV 201 Computational Methods for Civil Engineers Richard P. Ray, Ph.D., P.E. Error Analysis.
Round-Off and Truncation Errors
Computer-Aided Analysis on Energy and Thermofluid Sciences Y.C. Shih Fall 2011 Chapter 6: Basics of Finite Difference Chapter 6 Basics of Finite Difference.
Lecture 3: Integration. Integration of discrete functions
The Islamic University of Gaza Faculty of Engineering Civil Engineering Department Numerical Analysis ECIV 3306 Chapter 3 Approximations and Errors.
Revision.
ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 5 Approximations, Errors and The Taylor Series.
Lecture 1: Numerical Solution of Non-linear equations.
1 Error Analysis Part 1 The Basics. 2 Key Concepts Analytical vs. numerical Methods Representation of floating-point numbers Concept of significant digits.
Chapter 6 Numerical Interpolation
CISE-301: Numerical Methods Topic 1: Introduction to Numerical Methods and Taylor Series Lectures 1-4: KFUPM.
NUMERICAL DIFFERENTIATION The derivative of f (x) at x 0 is: An approximation to this is: for small values of h. Forward Difference Formula.
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Numerical Differentiation and Integration Part 6 Calculus.
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. by Lale Yurttas, Texas A&M University Chapter 31.
Ch 8.1 Numerical Methods: The Euler or Tangent Line Method
Interpolation. Interpolation is important concept in numerical analysis. Quite often functions may not be available explicitly but only the values of.
Lecture 2 Number Representation and accuracy
CISE-301: Numerical Methods Topic 1: Introduction to Numerical Methods and Taylor Series Lectures 1-4: KFUPM CISE301_Topic1.
Math 3120 Differential Equations with Boundary Value Problems Chapter 2: First-Order Differential Equations Section 2-6: A Numerical Method.
CISE301_Topic11 CISE-301: Numerical Methods Topic 1: Introduction to Numerical Methods and Taylor Series Lectures 1-4:
ES 240: Scientific and Engineering Computation. Chapter 4 Chapter 4: Errors Uchechukwu Ofoegbu Temple University.
Block 4 Nonlinear Systems Lesson 14 – The Methods of Differential Calculus The world is not only nonlinear but is changing as well 1 Narrator: Charles.
Round-off Errors.
Introduction to error analysis Class II "The purpose of computing is insight, not numbers", R. H. Hamming.
1 EEE 431 Computational Methods in Electrodynamics Lecture 4 By Dr. Rasime Uyguroglu
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Chapter.
MECN 3500 Inter - Bayamon Lecture 3 Numerical Methods for Engineering MECN 3500 Professor: Dr. Omar E. Meza Castillo
CSE Differentiation Roger Crawfis Prepaid by:
In section 11.9, we were able to find power series representations for a certain restricted class of functions. Here, we investigate more general problems.
Problems with Floating-Point Representations Douglas Wilhelm Harder Department of Electrical and Computer Engineering University of Waterloo Copyright.
Numerical Methods.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Chapter 3.
Chap. 11 Numerical Differentiation and Integration
In this section we develop general methods for finding power series representations. Suppose that f (x) is represented by a power series centered at.
Lecture 4 - Numerical Errors CVEN 302 June 10, 2002.
This is an example of an infinite series. 1 1 Start with a square one unit by one unit: This series converges (approaches a limiting value.) Many series.
Komputasi Numerik: Integrasi dan Differensiasi Numerik Agus Naba Physics Dept., FMIPA-UB.
Numerical Analysis CC413 Propagation of Errors.
Linearization, Newton’s Method
Maclaurin and Taylor Polynomials Objective: Improve on the local linear approximation for higher order polynomials.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Part 6 - Chapters 22 and 23.
Introduction to error analysis Class II "The purpose of computing is insight, not numbers", R. H. Hamming.
NUMERICAL ANALYSIS I. Introduction Numerical analysis is concerned with the process by which mathematical problems are solved by the operations.
1 Week 11 Numerical methods for ODEs 1.The basics: finite differences, meshes 2.The Euler method.
Machine arithmetic and associated errors Introduction to error analysis Class II.
NUMERICAL DIFFERENTIATION Forward Difference Formula
Chapter 6 Floating Point
Taylor series in numerical computations (review)
Chapter 2 ERROR ANALYSIS
Interpolation.
Class Notes 18: Numerical Methods (1/2)
CSE Differentiation Roger Crawfis.
Chapter 23.
CSE Differentiation Roger Crawfis.
SKTN 2393 Numerical Methods for Nuclear Engineers
Chapter 1 / Error in Numerical Method
CISE-301: Numerical Methods Topic 1: Introduction to Numerical Methods and Taylor Series Lectures 1-4: KFUPM CISE301_Topic1.
Presentation transcript:

Numerical Methods notes by G. Houseman for EARS1160, ENVI2240, CCFD1160 Lecture 2: Numerical Differentiation. Derivative as a gradient Taylor Series The forward difference: 1st order accurate Discretisation error Round-off error The centered difference: 2nd order accurate Convergence 2nd and higher derivatives The Laplacian

Numerical Differentiation In this lecture we focus on numerical differentiation: Given a means of evaluating the function f(x), how do we compute the first derivative f'(x) [and, if necessary, higher derivatives f''(x), f'''(x), etc]. Differentiation may be required in order to locate function zeroes for example, or to evaluate a derived quantity such as electric field strength from electric potential. Recall that a derivative of a function is just the slope of the tangent line at that point. [f(x+h)-f(x)]/h gives an approximate value for the slope. x f(x) h

Taylor Series The basis of numerical differentiation is the Taylor series. In the vicinity of x0, we can write: This is an infinite series of course, but if the derivatives are well behaved, then the factor hn present in each term of the series causes the higher order terms to rapidly diminish in magnitude, provided h is sufficiently small. Exercises: (i) evaluate the Taylor series for cos(x), sin(x), tan(x), and sin(x) - tan(x), in the vicinity of x = 0. (ii) evaluate the Taylor series for exp(x) and ln(x) in the vicinity of x = 1. (iii) in each case, how large is the error if h = 0.1 and we truncate the series at n = 2.

The Forward Difference The Taylor Series formula suggests a simple way to compute the first derivative at the point x0 In the representation of the discrete function, h is just the sampling interval. If we neglect those terms that contain the 2nd and higher order derivatives, then we get though we see that there is an error whose largest component is proportional to h. We say that this formula for the forward difference is accurate to first order in h.

Discretisation Error The difference between the actual value of the derivative, and the finite difference representation of it is referred to as the discretisation error. We usually just worry about the leading term of those that have been neglected. For the forward difference: If the discretisation error is too large, we will not get a very accurate estimate for the derivative. One way to decrease this source of error is to decrease h. Here we see that the discretisation error should decrease proportionally to h. The disadvantage of this technique is that as we decrease h, we (i) require more memory to represent the function, and more processor time to carry out operations (ii) run the risk of increasing computer round-off error in taking the difference of two near equal numbers.

Round-off Error Single precision in Fortran means 32 bits to store a real number: 23 bits for mantissa, 1 for sign, 7 for exponent and 1 to register overflow:about 7 places in decimal precision. The round-off error is the difference between the actual number and that stored in the computer. If you have two numbers that are the same to 5 significant figures and you subtract one from the other, the result is only accurate to two significant figures and round-off error is now at the level of 1% in the answer. At some point, if h is small enough f(x+h) = f(x) in the computer. Thus h in f(x+h)-f(x) should not be too small, or round-off error may cause unacceptable loss of accuracy. Alternative: Double precision: 64 bits, comprising 52 for mantissa, 10 for exponent, 1 for sign, 1 for overflow:15 places in decimal precision.

The Centred Difference The other approach to decreasing discretisation error is to obtain a higher order approximation from the Taylor Series. By using another point from the discrete function we can eliminate the largest term in the error. Substituting -h for h in the expression for the Taylor Series gives: The sign of each odd-order term is changed. Subtracting this expression from the original Taylor Series:

2nd Order Accuracy This expression for the first derivative: is second order accurate, because the leading term in the discretisation error is proportional to h2. If h is halved for example, the error is reduced by a factor of 4. Second order accurate approximations are preferred because they have better convergence behaviour for little cost in algorithm complexity.

Higher order approximations If we can evaluate a 2nd order accurate expression for the first derivative from 3 points (central and one either side), can we do better and evaluate a 3rd or 4th order accurate expression ? Exercise: Using the Taylor Series expression for f(x+2h), and f(x-2h), together with the expressions for f(x+h) and f(x-h), derive an expression for the first derivative, which is 4th order accurate. The disadvantage of using these higher order expressions is that they start to get a little complicated for derivation and evaluation, and special treatment is required at either end of the discrete function to deal with those points outside the range in which the function is defined. E.g., assume function is symmetric, or antisymmetric

Convergence We introduced the term "convergence" last week in the context of getting a better and better approximation to the zero of a function. In numerical evaluation of derivatives, the same idea applies: As we decrease h, our estimate of the derivative should converge to the actual value of the derivative. In practice we don't know exactly how large the errors are, so we evaluate them empirically Plotting the estimated values of derivative, versus the discretisation interval h, we expect to see that the derivative values approach the axis along a quadratic curve (for a 2nd order approximation). By extrapolating to the axis we should get an accurate estimate of the derivative. h f'(x)

2nd Derivatives One approach to evaluating higher derivatives is build on the expressions at the previous level. Another approach is simply to go back to the Taylor Series. add these two expressions and thus: which is also evidently accurate to second order.

The Laplacian in 2D In two or more dimensions the expression for the Laplacian operator is obtained by simply generalising the expression for the 1D second derivative In diagrammatic form, we can represent the Laplacian operator by the spatial coefficients to be applied to the discretised function:

Discrete Functions f(x) x f(x) is an arbitrary function of x, represented in the computer by a sequence of values at constant offset Dx This representation is not ideal because: (i) round-off error means that the point values are not exact, and (ii) even if each of the discretised points is located on the precise value of the function, we have discarded the information about the function between the points x f(x) Dx

Discrete Function Operations The disadvantages of working with discrete functions are easily outweighed when we consider the powerful advantages that computer processing gives. Working with these functions requires, however, procedures for the standard mathematical operations (i) function evaluation (interpolation) (ii) differentiation (iii) integration In this lecture we focus on differentiation: Given a discrete representation of f(x), how do we compute the first derivative f'(x), and higher derivatives f''(x), f'''(x), etc, and extensions to higher dimensional problems. Differentiation may be required in order to locate function zeroes for example, or to evaluate a derived quantity such as electric field strength, given electric potential.