Comp 208 Computers in Engineering Yi Lin Winter, 2007

Slides:



Advertisements
Similar presentations
6. 4 Integration with tables and computer algebra systems 6
Advertisements

Numerical Integration
ES 240: Scientific and Engineering Computation. Chapter 17: Numerical IntegrationIntegration  Definition –Total area within a region –In mathematical.
Computational Methods in Physics PHYS 3437
A Riemann sum is a method for approximating the total area underneath a curve on a graph. This method is also known as taking an integral. There are 3.
Mathematics1 Mathematics 1 Applied Informatics Štefan BEREŽNÝ.
Riemann Sums Jim Wang Mr. Brose Period 6. Approximate the Area under y = x² on [ 0,4 ] a)4 rectangles whose height is given using the left endpoint b)4.
Newton-Cotes Integration Formula
Lecture 3: Integration. Integration of discrete functions
MANE 4240 & CIVL 4240 Introduction to Finite Elements Numerical Integration in 1D Prof. Suvranu De.
CHAPTER 4 THE DEFINITE INTEGRAL.
16 MULTIPLE INTEGRALS.
8 TECHNIQUES OF INTEGRATION. There are two situations in which it is impossible to find the exact value of a definite integral. TECHNIQUES OF INTEGRATION.
NUMERICAL DIFFERENTIATION The derivative of f (x) at x 0 is: An approximation to this is: for small values of h. Forward Difference Formula.
Quadrature Greg Beckham. Quadrature Numerical Integration Goal is to obtain the integral with as few computations of the integrand as possible.
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Numerical Differentiation and Integration Part 6 Calculus.
Ch 8.1 Numerical Methods: The Euler or Tangent Line Method
19.5 Numeric Integration and Differentiation
The Islamic University of Gaza Faculty of Engineering Civil Engineering Department Numerical Analysis ECIV 3306 Chapter 21 Newton-Cotes Integration Formula.
Numerical Integration In general, a numerical integration is the approximation of a definite integration by a “weighted” sum of function values at discretized.
Integrals 5.
Numerical Integration Approximating Definite Integral.
Automatic Integration
MECN 3500 Inter - Bayamon Lecture Numerical Methods for Engineering MECN 3500 Professor: Dr. Omar E. Meza Castillo
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.
Integration. Indefinite Integral Suppose we know that a graph has gradient –2, what is the equation of the graph? There are many possible equations for.
D MANCHE Finding the area under curves:  There are many mathematical applications which require finding the area under a curve.  The area “under”
Lecture 19 – Numerical Integration 1 Area under curve led to Riemann sum which led to FTC. But not every function has a closed-form antiderivative.
Chapter 7 – Techniques of Integration
Wicomico High School Mrs. J. A. Austin AP Calculus 1 AB Third Marking Term.
 Finding area of polygonal regions can be accomplished using area formulas for rectangles and triangles.  Finding area bounded by a curve is more challenging.
Integration Copyright © Cengage Learning. All rights reserved.
Maybe add in chad’s idea of the area of polygons limiting to the area of a circle. Nice animation to link to online At
In this section, we will investigate how to estimate the value of a definite integral when geometry fails us. We will also construct the formal definition.
Section 5.9 Approximate Integration Practice HW from Stewart Textbook (not to hand in) p. 421 # 3 – 15 odd.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Part 6 - Chapter 21.
Integral calculation. Indefinite integral. Differentiation Rules If f(x) = x 6 +4x 2 – 18x + 90 f’(x) = 6x 5 + 8x – 18 *multiply by the power, than subtract.
5.1 Approximating and Computing Area Thurs Jan 29 Evaluate each summation 1) 2)
5.1 Approximating and Computing Area Fri Jan 15
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Part 5 Integration and Differentiation.
Clicker Question 1 What is ? (Hint: u-sub) – A. ln(x – 2) + C – B. x – x 2 + C – C. x + ln(x – 2) + C – D. x + 2 ln(x – 2) + C – E. 1 / (x – 2) 2 + C.
Definite Integrals & Riemann Sums
Copyright © Cengage Learning. All rights reserved. 7 Techniques of Integration.
Approximating Antiderivatives. Can we integrate all continuous functions? Most of the functions that we have been dealing with are what are called elementary.
Numerical Integration using Trapezoidal Rule
INTEGRALS 5. INTEGRALS In Chapter 3, we used the tangent and velocity problems to introduce the derivative—the central idea in differential calculus.
Algorithms and Programming
NUMERICAL DIFFERENTIATION Forward Difference Formula
5.5 The Trapezoid Rule.
Lecture 19 – Numerical Integration
Part 6 - Chapter 21.
Clicker Question 1 What is ? A. x tan(x2) + C
Midpoint and Trapezoidal Rules
More Approximations Left-hand sum: use rectangles, left endpoint used for height Right-hand sum: use rectangles, right endpoint used for height Midpoint.
NUMERICAL INTEGRATION
The Trapezoid Rule! Created by mr. herron.
MTH1170 Numeric Integration
Copyright © Cengage Learning. All rights reserved.
Class Notes 18: Numerical Methods (1/2)
TECHNIQUES OF INTEGRATION
CSE Differentiation Roger Crawfis.
Elements of Numerical Integration
Summation Formulas Constant Series.
Copyright © Cengage Learning. All rights reserved.
SKTN 2393 Numerical Methods for Nuclear Engineers
Numerical Integration
5.1 Areas and Distances Approximating the area under a curve with rectangles or trapezoids, and then trying to improve our approximation by taking.
Jim Wang Mr. Brose Period 6
Presentation transcript:

Comp 208 Computers in Engineering Yi Lin Winter, 2007 Lecture 21 Integration Comp 208 Computers in Engineering Yi Lin Winter, 2007 2019/5/13 Comp208 Computers in Engineering

Lecture 22 Learning goals Integration Rectangular midpoint rule Trapezoidal rule Simpson’s rule Monte Carlo 2019/5/13 Comp208 Computers in Engineering

Comp208 Computers in Engineering Integration Recall the definition of the integral As with differentiation, let’s experiment with small but finite deltas 2019/5/13 Comp208 Computers in Engineering

Meet our function for today 2019/5/13 Comp208 Computers in Engineering

‘Dumb’ integrals, Left-point rule Again, applying the definition directly Obtain the left-point rectangular rule 2019/5/13 Comp208 Computers in Engineering

Left-point rectangular rule Note how this scheme will always underestimate an increasing function and overestimate a decreasing function This maps well to the definition but we can very easily make it much better so we won’t even bother to write code for this. 2019/5/13 Comp208 Computers in Engineering

Comp208 Computers in Engineering Right-point rule Using the right point as height, it will overestimate the ascending functions but underestimate the descending functions 2019/5/13 Comp208 Computers in Engineering

Comp208 Computers in Engineering Midpoint rule Each rectangular band which makes up the integral is evaluated at the midpoint Hopefully the overestimation and underestimation effects cancel out on each panel 2019/5/13 Comp208 Computers in Engineering

Comp208 Computers in Engineering Midpoint algorithm double midpoint_int( DfD foo , double a , double b , int panels ) { int i; double sum = 0; double dx = ( b - a ) / panels; double x = a + dx / 2.0; for( i = 0; i < panels; ++i ) { sum += foo( x ); x += dx; } return sum * dx; 2019/5/13 Comp208 Computers in Engineering

How good is the midpoint rule? Absolutely accurate for constant and linear functions How accurate for parabolas and other non-linear functions? This is a pretty naïve way of doing things. 2019/5/13 Comp208 Computers in Engineering

Trying other geometries The rectangle isn’t the only quadrilateral that we can use to evaluate an integral What about a trapeze? We could try even more sophisticated shapes Fit a parabola through 3 points and integrate that How can we make integration rules that guarantee higher accuracy? 2019/5/13 Comp208 Computers in Engineering

Comp208 Computers in Engineering Trapezoidal rule Approximate curves as sequences of straight lines instead of sequences of constants 2019/5/13 Comp208 Computers in Engineering

Comp208 Computers in Engineering Trapezoidal integral The integral formula comes from the Taylor series The error term has a known order of magnitude which comes from the terms we truncate from the series to make the integration rule 2019/5/13 Comp208 Computers in Engineering

Comp208 Computers in Engineering Summing trapezes Area of a trapeze Remember that all the trapezes share an edge 2019/5/13 Comp208 Computers in Engineering

Comp208 Computers in Engineering Optimizing the sum Because we are adding up all the inner edges twice but dividing all of our sums by two we can reduce the effort Start sum with the outer edges divided by two Then add all the inner edges undivided 2019/5/13 Comp208 Computers in Engineering

Trapezoidal integration double trapezoidal_int( DfD foo , double a , double b , int panels ) { int i; double sum = ( foo( a ) + foo( b ) ) / 2.0; double dx = ( b - a ) / panels; double x = a + dx; for( i = 0; i < ( panels - 1); ++i ) { sum += foo( x ); x += dx; } return sum * dx; 2019/5/13 Comp208 Computers in Engineering

Comp208 Computers in Engineering How good is this? If deltas are small enough then the straight line approximation can be good How does it deal with errors? Is that a good way? How does this method’s accuracy relate to how many points it uses (relate polynomials) 2019/5/13 Comp208 Computers in Engineering

Comp208 Computers in Engineering Guarantees? Midpoint and trapezoidal rules, amazingly enough, offer the same guarantees 100% accurate on constants and linear functions BUT, trapezoidal deals with errors better, on average. 2019/5/13 Comp208 Computers in Engineering

Comp208 Computers in Engineering Using a parabola Simpson’s rule fits a parabola through 3 points and integrates it Definition of what a panel is, is now somewhat up in the air… our old panels had 2 points but now we need three We can subdivide our current panels… …or we can use neighbour panels together. 2019/5/13 Comp208 Computers in Engineering

Comp208 Computers in Engineering Using a parabola As the trapezoidal rule for integration finds the area under the line connecting the endpoints of a panel, Simpson's rule finds the area under the parabola which passes through 3 points (the endpoints and the midpoint) on a curve. Area under parabola: Δx Δx 2019/5/13 Comp208 Computers in Engineering

Comp208 Computers in Engineering Simpson’s formula Again, the formula comes from the taylor series: 2019/5/13 Comp208 Computers in Engineering

Comp208 Computers in Engineering Simpson’s algorithm double simpsons_int( DfD foo , double a , double b , int panels ) { int i; double sum = 0; double dx = ( b - a ) / panels; double x = a; for( i = 0; i < panels; ++i ) { sum += foo( x ) + 4*foo( x + dx/2.0 ) + foo( x + dx ); x += dx; } return sum * dx / 6.0; 2019/5/13 Comp208 Computers in Engineering

Comp208 Computers in Engineering How good is this? Look at the error term… ∆x5!! If ∆x is 0.01, then the precision is already beyond most engineering requirements… Even more methods exist however… Even methods to make methods of arbitrary precision 2019/5/13 Comp208 Computers in Engineering

Monte Carlo Integration double monte_carlo_int(DfD f, double x0, double x1, int n) { double sum = 0; int i; srand(time(NULL)); // Sum n random values of f(x) with x in [x0, x1]. for(i = 0; i < n; ++i) sum += f( (rand() / RAND_MAX) * (x1 - x0) + x0 ); // Divide the sum by n to get the average value of f(x) with x in [x0, x1]. // Multiply by (x1 - x0) to get the area. return (sum / n) * (x1 - x0); } 2019/5/13 Comp208 Computers in Engineering