Engineering Analysis ENG 3420 Fall 2009 Dan C. Marinescu Office: HEC 439 B Office hours: Tu-Th 11:00-12:00.

Slides:



Advertisements
Similar presentations
Splines and Piecewise Interpolation
Advertisements

Numerical Integration
ES 240: Scientific and Engineering Computation. Chapter 17: Numerical IntegrationIntegration  Definition –Total area within a region –In mathematical.
Quick Sort, Shell Sort, Counting Sort, Radix Sort AND Bucket Sort
NUMERICAL DIFFERENTIATION AND INTEGRATION
Engineering Analysis ENG 3420 Fall 2009 Dan C. Marinescu Office: HEC 439 B Office hours: Tu-Th 11:00-12:00.
Chapter 7 Numerical Differentiation and Integration
Today’s class Romberg integration Gauss quadrature Numerical Methods
Numerical Integration
Chapter 18 Interpolation The Islamic University of Gaza
CITS2401 Computer Analysis & Visualisation
Curve Fitting: Splines
Computational Methods in Physics PHYS 3437
EARS1160 – Numerical Methods notes by G. Houseman
ES 240: Scientific and Engineering Computation. InterpolationPolynomial  Definition –a function f(x) that can be written as a finite series of power functions.
Numerical Integration Lecture (II)1
Curve-Fitting Interpolation
Newton-Cotes Integration Formula
Chapter 11 Sorting and Searching. Copyright © 2005 Pearson Addison-Wesley. All rights reserved Chapter Objectives Examine the linear search and.
Lecture 3: Integration. Integration of discrete functions
Engineering Computation Curve Fitting: Interpolation 1
ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 29 Numerical Integration.
ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW III.
ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 23 CURVE FITTING Chapter 18 Function Interpolation and Approximation.
ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.
Chapter 17 Objectives Recognizing that Newton-Cotes integration formulas are based on the strategy of replacing a complicated function or tabulated data.
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Interpolation Chapter 18.
Chapter 6 Numerical Interpolation
ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 21 CURVE FITTING Chapter 18 Function Interpolation and Approximation.
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 ~ Numerical Differentiation and Integration ~ Newton-Cotes.
NUMERICAL DIFFERENTIATION The derivative of f (x) at x 0 is: An approximation to this is: for small values of h. Forward Difference Formula.
Numerical Integration Formulas
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Numerical Differentiation and Integration Part 6 Calculus.
The Islamic University of Gaza Faculty of Engineering Civil Engineering Department Numerical Analysis ECIV 3306 Chapter 21 Newton-Cotes Integration Formula.
Engineering Analysis ENG 3420 Fall 2009
Chapter 4 Numerical Differentiation and Integration 1/16 Given x 0, approximate f ’(x 0 ). h xfhxf xf h )()( lim)('    x0x0 x1x1 h x1x1 x0x0.
Today’s class Numerical Integration Newton-Cotes Numerical Methods
MECN 3500 Inter - Bayamon Lecture Numerical Methods for Engineering MECN 3500 Professor: Dr. Omar E. Meza Castillo
Lecture 19 - Numerical Integration CVEN 302 July 22, 2002.
Integration Integration: is the total value, or summation, of f(x) dx over the range from a to b:
1 Chapter 7 NUMERICAL INTEGRATION. 2 PRELIMINARIES We use numerical integration when the function f(x) may not be integrable in closed form or even in.
CMPS1371 Introduction to Computing for Engineers NUMERICAL METHODS.
Simpson Rule For Integration.
Review Taylor Series and Error Analysis Roots of Equations
Engineering Analysis ENG 3420 Fall 2009 Dan C. Marinescu Office: HEC 439 B Office hours: Tu-Th 11:00-12:00.
Numerical Methods Part: Simpson Rule For Integration.
Today’s class Spline Interpolation Quadratic Spline Cubic Spline Fourier Approximation Numerical Methods Lecture 21 Prof. Jinbo Bi CSE, UConn 1.
Polynomial Interpolation You will frequently have occasions to estimate intermediate values between precise data points. The function you use to interpolate.
Engineering Analysis ENG 3420 Fall 2009 Dan C. Marinescu Office: HEC 439 B Office hours: Tu-Th 11:00-12:00.
Computers in Civil Engineering 53:081 Spring 2003 Lecture #15 Spline Interpolation.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Part 6 - Chapter 21.
Numerical Integration
Mohiuddin Ahmad SUNG-BONG JANG Interpolation II (8.4 SPLINE INTERPOLATION) (8.5 MATLAB’s INTERPOLATION Functions)
Engineering Analysis ENG 3420 Fall 2009 Dan C. Marinescu Office: HEC 439 B Office hours: Tu-Th 11:00-12:00.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Part 5 Integration and Differentiation.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Part 4 Chapter 17 and 18 Interpolation.
INTRO2CS Tirgul 8 1. Searching and Sorting  Tips for debugging  Binary search  Sorting algorithms:  Bogo sort  Bubble sort  Quick sort and maybe.
Interpolation - Introduction
NUMERICAL DIFFERENTIATION Forward Difference Formula
Interpolation Methods
Chapter 15 Curve Fitting : Splines
Numerical Integration Formulas
NUMERICAL DIFFERENTIATION AND INTEGRATION
Chapter 7 Numerical Differentiation and Integration
Splines and Piecewise Interpolation
Interpolation Methods
SKTN 2393 Numerical Methods for Nuclear Engineers
SKTN 2393 Numerical Methods for Nuclear Engineers
Numerical Integration
Presentation transcript:

Engineering Analysis ENG 3420 Fall 2009 Dan C. Marinescu Office: HEC 439 B Office hours: Tu-Th 11:00-12:00

2 22 Lecture 24 Attention: The last homework HW5 and the last project are due on Tuesday November 24!! Last time:  Lagrange interpolating polynomials  Splines Today  Cubic splines  Searching and sorting  Numerical integration (chapter 17) Next Time  Numerical integration

3 Cubic splines Cubic splines  the simplest representation with the appearance of smoothness and without the problems of higher order polynomials.  Linear splines have discontinuous first derivatives  Quadratic splines have discontinuous second derivatives and require setting the second derivative at some point to a pre-determined value  Quartic or higher-order splines tend to exhibit ill-conditioning or oscillations. The cubic spline function for the i th interval can be written as: For n data points, there are (n-1) intervals and thus 4(n-1) unknowns to evaluate to solve all the spline function coefficients.

4 Conditions to determine the spline coefficients The first condition  the spline function goes through the first and last point of the interval; this leads to 2(n-1) equations: The second condition  the first derivative should be continuous at each interior point; this leads to (n-2) equations: The third condition  the second derivative should be continuous at each interior point; this leads to (n-2) equations: So far we have (4n-6) equations; we need (4n-4) equations!

5 Two additional equations There are several options for the final two equations:  Natural end conditions  the second derivative at the end knots are zero.  Clamped end conditions  the first derivatives at the first and last knots are known.  “Not-a-knot” end conditions  force continuity of the third derivative at the second and penultimate points (results in the first two intervals having the same spline function and the last two intervals having the same spline function)

6 Built-in functions for piecewise interpolation MATLAB has several built-in functions to implement piecewise interpolation. spline  yy=spline(x, y, xx)  Performs cubic spline interpolation, generally using not-a-knot conditions.  If y contains two more values than x has entries, then the first and last value in y are used as the derivatives at the end points (i.e. clamped) Example:  Generate data: x = linspace(-1, 1, 9); y = 1./(1+25*x.^2);  Calculate 100 model points and determine not-a-knot interpolation xx = linspace(-1, 1); yy = spline(x, y, xx);  Calculate actual function values at model points and data points, the 9-point not-a-knot interpolation (solid), and the actual function (dashed), yr = 1./(1+25*xx.^2) plot(x, y, ‘o’, xx, yy, ‘-’, xx, yr, ‘--’)

7 Clamped example Generate data w/ first derivative information: x = linspace(-1, 1, 9); y = 1./(1+25*x.^2); yc = [1 y -4] Calculate 100 model points and determine not-a-knot interpolation xx = linspace(-1, 1); yyc = spline(x, yc, xx); Calculate actual function values at model points and data points, the 9-point clamped interpolation (solid), and the actual function (dashed), yr = 1./(1+25*xx.^2) plot(x, y, ‘o’, xx, yyc, ‘-’, xx, yr, ‘--’)

8 interp1 built-in function interp1 function performs several different kinds of interpolation: yi = interp1(x, y, xi, ‘method’)  x & y contain the original data  xi contains the points at which to interpolate  ‘method’ is a string containing the desired method: ‘nearest’ - nearest neighbor interpolation ‘linear’ - connects the points with straight lines ‘spline’ - not-a-knot cubic spline interpolation ‘pchip’ or ‘cubic’ - piecewise cubic Hermite interpolation

9 Piecewise Polynomial Comparisons

10 Multidimensional Interpolation The interpolation methods for one- dimensional problems can be extended to multidimensional interpolation. Example - bilinear interpolation using Lagrange-form equations:

11 Built-in functions for two- and three-dimensional piecewise interpolation 2-D interpolation: the inputs are vectors or same-size matrices. zi = interp2(x, y, z, xi, yi, ‘method’) 3-D interpolation: the inputs are vectors or same-size 3-D arrays. vi = interp3(x, y, z, v, xi, yi, zi, ‘method’) ‘method’ is a string containing the desired method: ‘nearest’, ‘linear’, ‘spline’, ‘pchip’, ‘cubic’

12 Search algorithms Find an element of a set based upon some search criteria. Linear search:  Compare each element of the set with the “target”  Requires O(n) operations if the set of n elements is not sorted Binary search:  Can be done only when the list is sorted.  Requires O(log(n)) comparisons.  Algorithm: Check the middle element. If the middle element is equal to the sought value, then the position has been found; Otherwise, the upper half or lower half is chosen for search based on whether the element is greater than or less than the middle element.

13 Sorting algorithms Algorithms that puts elements of a list in a certain order, e.g., numerical order and lexicographical order.  Input: a list of n unsorted elements.  Output: the list sorted in increasing order. Bubble sort  complexity: average O(n 2 ); )); worst case O(n 2 ).  Compare each pair of elements; swap them if they are in the wrong order.  Go again through the list until no swaps are necessary. Quick sort  complexity: average O(n log(n)); worst case O(n 2 ).  Pick an element, called a pivot, from the list.  Reorder the list so that all elements which are less than the pivot come before the pivot and all elements greater than the pivot come after it (equal values can go either way). After this partitioning, the pivot is in its final position.  Recursively sort the sub-list of lesser elements and the sub-list of greater elements.

14 Sorting algorithms (cont’d) Merge sort – invented by John von Neumann: 1. Complexity: average O(n log(n)); worst case O(n log(n)); 2. If the list is of length 0 or 1, then it is already sorted. Otherwise: 3. Divide the unsorted list into two sublists of about half the size. 4. Sort each sublist recursively by re-applying merge sort. 5. Merge the two sublists back into one sorted list.  Tournament sort:  Complexity: average O(n log(n)); worst case O(n log(n));  It imitates conducting a tournament in which two players play with each other.  Compare numbers in pairs, then form a temporary array with the winning elements.  Repeat this process until you get the greatest or smallest element based on your choice.

15 Integration Integration: is the total value, or summation, of f(x) dx over the range from a to b:

16 Newton-Cotes formulas The most common numerical integration schemes. Based on replacing a complicated function or tabulated data with a polynomial that is easy to integrate: where f n (x) is an n th order interpolating polynomial.

17 Newton-Cotes Examples The integrating function can be polynomials for any order - for example, (a) straight lines or (b) parabolas. The integral can be approximated in one step or in a series of steps to improve accuracy.

18 The trapezoidal rule The trapezoidal rule is the first of the Newton-Cotes closed integration formulas; it uses a straight-line approximation for the function:

19 Error of the trapezoidal rule An estimate for the local truncation error of a single application of the trapezoidal rule is: where  is somewhere between a and b. This formula indicates that the error is dependent upon the curvature of the actual function as well as the distance between the points. Error can thus be reduced by breaking the curve into parts.

20 Composite Trapezoidal Rule Assuming n+1 data points are evenly spaced, there will be n intervals over which to integrate. The total integral can be calculated by integrating each subinterval and then adding them together:

21 MATLAB Program

22 Simpson’s Rules One drawback of the trapezoidal rule is that the error is related to the second derivative of the function. More complicated approximation formulas can improve the accuracy for curves - these include using (a) 2nd and (b) 3rd order polynomials. The formulas that result from taking the integrals under these polynomials are called Simpson’s rules.

23 Simpson’s 1/3 Rule Simpson’s 1/3 rule corresponds to using second-order polynomials. Using the Lagrange form for a quadratic fit of three points: Integration over the three points simplifies to:

24 Error of Simpson’s 1/3 Rule An estimate for the local truncation error of a single application of Simpson’s 1/3 rule is: where again  is somewhere between a and b. This formula indicates that the error is dependent upon the fourth-derivative of the actual function as well as the distance between the points. Note that the error is dependent on the fifth power of the step size (rather than the third for the trapezoidal rule). Error can thus be reduced by breaking the curve into parts.

25 Composite Simpson’s 1/3 rule Simpson’s 1/3 rule can be used on a set of subintervals in much the same way the trapezoidal rule was, except there must be an odd number of points. Because of the heavy weighting of the internal points, the formula is a little more complicated than for the trapezoidal rule:

26 Simpson’s 3/8 rule Simpson’s 3/8 rule corresponds to using third-order polynomials to fit four points. Integration over the four points simplifies to: Simpson’s 3/8 rule is generally used in concert with Simpson’s 1/3 rule when the number of segments is odd.

27 Higher-order formulas Higher-order Newton-Cotes formulas may also be used - in general, the higher the order of the polynomial used, the higher the derivative of the function in the error estimate and the higher the power of the step size. As in Simpson’s 1/3 and 3/8 rule, the even-segment-odd-point formulas have truncation errors that are the same order as formulas adding one more point. For this reason, the even-segment-odd- point formulas are usually the methods of preference.

28 Integration with unequal segments The trapezoidal rule with data containing unequal segments:

29 Integration with unequal segments

30 Built-in functions MATLAB has built-in functions to evaluate integrals based on the trapezoidal rule z = trapz(y) z = trapz(x, y) produces the integral of y with respect to x. If x is omitted, the program assumes h=1. z = cumtrapz(y) z = cumtrapz(x, y) produces the cumulative integral of y with respect to x. If x is omitted, the program assumes h=1.

31 Multiple Integrals Multiple integrals can be determined numerically by first integrating in one dimension, then a second, and so on for all dimensions of the problem.