Computational Physics Numerical Integration Dr. Guy Tel-Zur Tulips by Anna Cervova, publicdomainpictures.net.

Slides:



Advertisements
Similar presentations
M. Dumbser 1 / 18 Analisi Numerica Università degli Studi di Trento Dipartimento dIngegneria Civile ed Ambientale Dr.-Ing. Michael Dumbser Lecture on Numerical.
Advertisements

Numerical Integration
ES 240: Scientific and Engineering Computation. Chapter 17: Numerical IntegrationIntegration  Definition –Total area within a region –In mathematical.
Quadrature. 二阶 : 中点公式 : 梯形公式 : 四阶公式 : Simpson’s 1/3 rd Rule.
Lecture 26: Numerical Integration Trapezoid rule Simpson's rule Simpson's 3/8 rule Boole’s rule Newton-Cotes Formulas.
1 Chapter 5 Numerical Integration. 2 A Review of the Definite Integral.
Computational Methods in Physics PHYS 3437
Lecture 18 - Numerical Differentiation
Numerical Integration
Computational Physics Numerical Integration Dr. Guy Tel-Zur Tulips by Anna Cervova, publicdomainpictures.net Version :00.
Newton-Cotes Integration Formula
Computational Physics Lecture 3 - Admin Dr. Guy Tel-Zur Coral. Picture by Anna Cervova, publicdomainpictures.net.
MANE 4240 & CIVL 4240 Introduction to Finite Elements Numerical Integration in 1D Prof. Suvranu De.
MECH300H Introduction to Finite Element Methods Lecture 2 Review.
Numerical 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.
CISE301_Topic7KFUPM1 SE301: Numerical Methods Topic 7 Numerical Integration Lecture KFUPM Read Chapter 21, Section 1 Read Chapter 22, Sections 2-3.
Quadrature Greg Beckham. Quadrature Numerical Integration Goal is to obtain the integral with as few computations of the integrand as possible.
Chapter 4, Integration of Functions. Open and Closed Formulas x 1 =a x 2 x 3 x 4 x 5 =b Closed formula uses end points, e.g., Open formulas - use interior.
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.
1 Chapter 5 Numerical Integration. 2 A Review of the Definite Integral.
1 Numerical Integration Dr. Asaf Varol
1.00 Lecture 20 More on root finding Numerical lntegration.
3. Numerical integration (Numerical quadrature) .
Lecture 19 - Numerical Integration CVEN 302 July 22, 2002.
Numerical Computation
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.
1 Numerical Analysis Lecture 12 Numerical Integration Dr. Nader Okasha.
4.6 Numerical Integration Trapezoid and Simpson’s Rules.
Dr. Mubashir Alam King Saud University. Outline Numerical Integration Trapezoidal and Simpson’s Rules (5.1)
Integration Copyright © Cengage Learning. All rights reserved.
MECH345 Introduction to Finite Element Methods Chapter 1 Numerical Methods - Introduction.
Section 5.9 Approximate Integration Practice HW from Stewart Textbook (not to hand in) p. 421 # 3 – 15 odd.
Chap. 11 Numerical Differentiation and Integration
1/7  4.6 Adaptive Quadrature Methods Chapter 4 Numerical Differentiation and Integration -- Adaptive Quadrature Methods   /2  /4  /8 Predict the.
The purpose of Chapter 5 is to develop the basic principles of numerical integration Usefule Words integrate, integral 积分(的), integration 积分(法), quadrature.
SE301_Topic 6Al-Amer20051 SE301:Numerical Methods Topic 6 Numerical Integration Dr. Samir Al-Amer Term 053.
Quadrature – Concepts (numerical integration) Don Allen.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Chapter 20 Numerical Integration of Functions.
CHAPTER 3 NUMERICAL METHODS
Numerical Integration
Air Force Admin College, Coimbatore
Chapter 4, Integration of Functions
NUMERICAL DIFFERENTIATION Forward Difference Formula
Part 6 - Chapter 21.
Approximate Integration
Numerical Analysis Lecture 42.
1. 2 What is Integration? Integration The process of measuring the area under a curve. Where: f(x) is the integrand a= lower limit of integration b=
Numerical Integration Formulas
Chapter 22.
Integration with Unequal Segments
Numerical Analysis Lecture 27.
NUMERICAL INTEGRATION
Chapter 7 Numerical Differentiation and Integration
MATH 2140 Numerical Methods
NUMERICAL INTEGRATION
Composite Numerical Integration
4.3 Elements of Numerical Integration
Elements of Numerical Integration
Copyright © Cengage Learning. All rights reserved.
SKTN 2393 Numerical Methods for Nuclear Engineers
Numerical Integration
Numerical Computation and Optimization
Objectives Approximate a definite integral using the Trapezoidal Rule.
Numerical Integration
Air Force Admin College, Coimbatore
Chapter 4, Integration of Functions
Elements of Numerical Integration
Presentation transcript:

Computational Physics Numerical Integration Dr. Guy Tel-Zur Tulips by Anna Cervova, publicdomainpictures.net

MHJ- Chap. 7 – Numerical Integration Agenda – 1D integration (Trapezoidal and Simpson rules) – Gaussian quadrature (when the abscissas are not equally spaced) – Singular integrals – Physics case study – Parallel Computing (part 1)

Newton-Cotes quadrature: equal step methods Step size:

The strategy then is to find a reliable Taylor expansion for f(x) in the smaller sub intervals Let’s define x0 = a + h and use x0 as the midpoint. The general form for the Taylor expansion around x0 goes like: 7.2

Let us now suppose that we split the integral in Eq. (7.2) in two parts, one from x0−h to x0 and the other from x0 to x0 + h, that is, our integral is rewritten as: Next we assume that we can use the two-point formula for the derivative, meaning that we approximate f(x) in these two regions by a straight line, as indicated in the figure. This means that every small element under the function f(x) looks like a trapezoid. we are trying to approximate our function f(x) with a first order polynomial, that is f(x) = a + bx. The constant b is the slope given by the first derivative at x = x0:

The Trapezoidal Rule:

Trapezoidal Rule A worked out example in “C”. We will learn how to Integrate a general form of a function? The code is under: lecture02/code_ch_07/trapez.c

// Computational Physics // Guy Tel-Zur, August 2010 // Trapezoidal Rule // Based on MHJ Page 129, Chapter 7, 2009 Fall Edition // Usage: standard gcc -o fn fn.c -lm #include int main() { // functions declarations: double TrapezoidalRule(double a, double b, int n, double(*func )(double)); double MyFunction(double x); // variables declarations: double a = 0.0; double b = 10.0; int n = 1000; double s; s = TrapezoidalRule(a, b, n, &MyFunction); printf("Trapezoidal Rule Integral=%Lf\n",s); return 0; } // end of main // Computational Physics // Guy Tel-Zur, August 2010 // Trapezoidal Rule // Based on MHJ Page 129, Chapter 7, 2009 Fall Edition // Usage: standard gcc -o fn fn.c -lm #include int main() { // functions declarations: double TrapezoidalRule(double a, double b, int n, double(*func )(double)); double MyFunction(double x); // variables declarations: double a = 0.0; double b = 10.0; int n = 1000; double s; s = TrapezoidalRule(a, b, n, &MyFunction); printf("Trapezoidal Rule Integral=%Lf\n",s); return 0; } // end of main

double TrapezoidalRule (double a, double b, int n, double(*func )(double)) { double TrapezSum; double fa,fb,x,step ; int j; step =(b-a)/((double)n ); fa =(*func)(a)/2.; fb =(*func)(b)/2.; TrapezSum= 0.; for(j=1;j<=n-1;j++) { x=j*step+a; TrapezSum+=(*func)(x); } TrapezSum=(TrapezSum+fb+fa)*step; return TrapezSum; } // end TrapezoidalRule double MyFunction(double x) { // write below the mathematical expression of the // function to be integrated return x*x; } double TrapezoidalRule (double a, double b, int n, double(*func )(double)) { double TrapezSum; double fa,fb,x,step ; int j; step =(b-a)/((double)n ); fa =(*func)(a)/2.; fb =(*func)(b)/2.; TrapezSum= 0.; for(j=1;j<=n-1;j++) { x=j*step+a; TrapezSum+=(*func)(x); } TrapezSum=(TrapezSum+fb+fa)*step; return TrapezSum; } // end TrapezoidalRule double MyFunction(double x) { // write below the mathematical expression of the // function to be integrated return x*x; }

Section 7.5 – Rectangle Rule Another very simple approach is the so-called midpoint or rectangle method. In this case the integration area is split in a given number of rectangles with length h and height given by the mid-point value of the function. This gives the following simple rule for approximating an integral Demo: ch7 code folder. Program: rectangle_trapez.c double RectangleRule (double a, double b, int n, double(*func )(double)) { double RectangleSum; double fa,fb,x,step ; int j; step =(b-a)/((double)n ); RectangleSum= 0.; for(j=0;j<=n;j++) { x=(j+0.5)*step+a; RectangleSum+=(*func)(x); } RectangleSum *= step; return RectangleSum; } // end Rectangle Rule double RectangleRule (double a, double b, int n, double(*func )(double)) { double RectangleSum; double fa,fb,x,step ; int j; step =(b-a)/((double)n ); RectangleSum= 0.; for(j=0;j<=n;j++) { x=(j+0.5)*step+a; RectangleSum+=(*func)(x); } RectangleSum *= step; return RectangleSum; } // end Rectangle Rule

Error analysis Trapezoidal & Rectangle rules: – Local error: α h^3 – Global error: α h^2 – Global error: α (b-a)

Can’t we do better? So far: Linear two-points approximations for f Now (Simpson’s): three-points formula (a parabola): Recall from Chapter 3, the 1 st and the 2 nd derivatives approximations: f’= f’’=

With the latter two expressions we can now approximate the function f as: I gave up using Equation Editor – Sorry… Next Slide… I gave up using Equation Editor – Sorry… Next Slide…

Simpson’s Rule

Note that the improved accuracy in the evaluation of the derivatives gives a better error approximation, O(h 5 ) vs. O(h 3 ). - This is the local error. The global error goes like: O(h 4 ). The full integral is therefore: Note that the improved accuracy in the evaluation of the derivatives gives a better error approximation, O(h 5 ) vs. O(h 3 ). - This is the local error. The global error goes like: O(h 4 ). The full integral is therefore:

Simpson’s Rule

7.3 Adaptive Integration Naïve approach, for example, two parts of Trapezoidal Integration with a different step size

Recursive Adaptive Integration

7.4 Gaussian Quadrature (GQ) We could fit a polynomial of order N with N equally spaced points, but Gauss, who was a genius, suggested to fit a polynomial of order 2N-1 with N points!!!

Recommended online video:

Speaking about references, you can always check Google Books G=Search+Books

Another recommended reference: Computational Physics By Steven E. Koonin So far – equally spaced points: Our derivation is exact if f is polynomial 4.9 Note: This is a set of N linear equations (for each p) !!!

Legendre Polynomials:

Guy: Scaling of the weights: ω n ’=(b-a)/2* ω n

Sage demo Upload: “Gaussian Quadrature Demo.sws” Reference:

Let’s sum what we did so far 2 points integration: Trapezoidal Rule (+Rectangle Rule),fit straight line 3 points integration: Simpson’s Rule, fit a parabola Quadrature Formula: Gauss Quadrature:

More Orthogonal Functions

The program1.cpp is a ready for comparing the 3 integrations methods mentioned. The Trapezoidal, Simpson’s and GQ function are to be written. >> Explain this program (open DevC++ IDE) The program1.cpp is a ready for comparing the 3 integrations methods mentioned. The Trapezoidal, Simpson’s and GQ function are to be written. >> Explain this program (open DevC++ IDE)