Numerical Differentiation and Quadrature (Integration)

Slides:



Advertisements
Similar presentations
Boundary Value Problems and Partial Differential Equations (PDEs)
Advertisements

Numerical Integration
Fixed point iterations and solution of non-linear functions
ES 240: Scientific and Engineering Computation. Chapter 17: Numerical IntegrationIntegration  Definition –Total area within a region –In mathematical.
Partial Differential Equations (PDEs) 1Daniel Baur / Numerical Methods for Chemical Engineers / BVP and PDE Daniel Baur ETH Zurich, Institut für Chemie-
Numerical Differentiation and Quadrature (Integration) 1Daniel Baur / Numerical Methods for Chemical Engineers / Numerical Quadrature Daniel Baur ETH Zurich,
Asymptotic error expansion Example 1: Numerical differentiation –Truncation error via Taylor expansion.
Numerical Integration of Functions
Chapter 7 Numerical Differentiation and Integration
Today’s class Romberg integration Gauss quadrature Numerical Methods
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
MANE 4240 & CIVL 4240 Introduction to Finite Elements Numerical Integration in 1D Prof. Suvranu De.
Numerical Integration
Ordinary Differential Equations (ODEs) 1Daniel Baur / Numerical Methods for Chemical Engineers / Implicit ODE Solvers Daniel Baur ETH Zurich, Institut.
Ordinary Differential Equations (ODEs)
6&7-2 Dynamics, two examples of the use of ode45. Numeric Integration using trapz and quad/quadl functions. Readings: Matlab by Pratap Chapter 5.4,5.5.
Ordinary Differential Equations (ODEs) 1Daniel Baur / Numerical Methods for Chemical Engineers / Explicit ODE Solvers Daniel Baur ETH Zurich, Institut.
Ordinary Differential Equations (ODEs) 1Daniel Baur / Numerical Methods for Chemical Engineers / Implicit ODE Solvers Daniel Baur ETH Zurich, Institut.
Ordinary Differential Equations (ODEs) 1Daniel Baur / Numerical Methods for Chemical Engineers / Explicit ODE Solvers Daniel Baur ETH Zurich, Institut.
Quadrature Greg Beckham. Quadrature Numerical Integration Goal is to obtain the integral with as few computations of the integrand as possible.
Numerical Integration UC Berkeley Fall 2004, E77 Copyright 2005, Andy Packard. This work is licensed under the.
Simpson’s 1/3 rd Rule of Integration. What is Integration? Integration The process of measuring the area under a.
1 NUMERICAL INTEGRATION Motivation: Most such integrals cannot be evaluated explicitly. Many others it is often faster to integrate them numerically rather.
3. Numerical integration (Numerical quadrature) .
Numerical Integration Pertemuan 7 Matakuliah: S0262-Analisis Numerik Tahun: 2010.
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.
ACSL, POSTECH1 MATLAB 입문 CHAPTER 8 Numerical calculus and differential equations.
CMPS1371 Introduction to Computing for Engineers NUMERICAL METHODS.
1 Simpson’s 1/3 rd Rule of Integration. 2 What is Integration? Integration The process of measuring the area under a curve. Where: f(x) is the integrand.
Chapters 5 and 6: Numerical Integration
4.6 Numerical Integration. The Trapezoidal Rule One method to approximate a definite integral is to use n trapezoids.
1 Trapezoidal Rule of Integration. What is Integration Integration: The process of measuring the area under a function.
MA2213 Lecture 4 Numerical Integration. Introduction Definition is the limit of Riemann sums I(f)
Boundary Value Problems and Least Squares Minimization
Integration Copyright © Cengage Learning. All rights reserved.
6. Introduction to Spectral method. Finite difference method – approximate a function locally using lower order interpolating polynomials. Spectral method.
Scientific Computing General Least Squares. Polynomial Least Squares Polynomial Least Squares: We assume that the class of functions is the class of all.
Quadrature rules 1Michael Sokolov / Numerical Methods for Chemical Engineers / Numerical Quadrature Michael Sokolov ETH Zurich, Institut für Chemie- und.
Solution of Nonlinear Functions
12/1/ Trapezoidal Rule of Integration Civil Engineering Majors Authors: Autar Kaw, Charlie Barker
Chap. 11 Numerical Differentiation and Integration
CHAPTER 3 NUMERICAL METHODS
4.1 ANTIDERIVATIVES & INDEFINITE INTEGRATION. Definition of Antiderivative  A function is an antiderivative of f on an interval I if F’(x) = f(x) for.
Ordinary Differential Equations (ODEs) 1Michael Sokolov / Numerical Methods for Chemical Engineers / Explicit ODE Solvers Michael Sokolov ETH Zurich, Institut.
ACSL, POSTECH1 MATLAB 입문 CHAPTER 8 Numerical calculus and differential equations.
Antiderivatives and Indefinite Integration
Techniques for Numerical Integration
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Part 5 Integration and Differentiation.
Chapters 5 and 6: Numerical Integration Code development trapezoid rule Simpson’s rule Gauss quadrature Laguerre quadrature Analysis changing the variable.
3/12/ Trapezoidal Rule of Integration Computer Engineering Majors Authors: Autar Kaw, Charlie Barker
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
Air Force Admin College, Coimbatore
NUMERICAL DIFFERENTIATION Forward Difference Formula
Chapter 7 Numerical Differentiation and Integration
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=
Chapter 22.
The Area Question and the Integral
Copyright © Cengage Learning. All rights reserved.
Numerical Integration:
Numerical Analysis Lecture 26.
Copyright © Cengage Learning. All rights reserved.
Numerical Computation and Optimization
SKTN 2393 Numerical Methods for Nuclear Engineers
Numerical Integration
Numerical Computation and Optimization
Air Force Admin College, Coimbatore
Presentation transcript:

Numerical Differentiation and Quadrature (Integration) Michael Sokolov ETH Zurich, Institut für Chemie- und Bioingenieurwissenschaften ETH Hönggerberg / HCI F123 – Zürich E-Mail: michael.sokolov@chem.ethz.ch http://www.morbidelli-group.ethz.ch/education/index Michael Sokolov / Numerical Methods for Chemical Engineers / Numerical Quadrature

Numerical Differentiation Problem: Though an analytical derivative can be found for all differentiable functions, it is often impractical to calculate it Solution: Approximate the derivative numerically Method of forward finite differences: Remember that: Therefore: for small h Michael Sokolov / Numerical Methods for Chemical Engineers / Numerical Quadrature

Numerical Quadrature (Integration) Problem: Generally, it is not possible to find the antiderivative (Stammfunktion) of a function f(x) in order to solve a definite integral in the interval [a,b] Solution: Approximate the area under the curve numerically Trapezoidal rule: Divide the interval into sub-intervals and approximate the integral by the sum of the areas of the resulting trapezoids Michael Sokolov / Numerical Methods for Chemical Engineers / Numerical Quadrature

Trapezoidal rule a x1 x2 xn-1 b Michael Sokolov / Numerical Methods for Chemical Engineers / Numerical Quadrature

Simpson rule The interval is split up and the areas are integrals of quadratic functions Parabola through f(a), f(x1), f(x2) a x1 x2 xn-1 b Michael Sokolov / Numerical Methods for Chemical Engineers / Numerical Quadrature

Degree of exactness Trapezoids are areas under linear functions  Linear functions are approximated exactly; q = 1 Simpson uses the area under quadratic functions  Polynomials up to order three are approximated exactly! q = 3 Even degree interpolation polynomials get one degree of exactness for free Example Michael Sokolov / Numerical Methods for Chemical Engineers / Numerical Quadrature

Degree of exactness vs. order of accuracy When a non-exact result is obtained, the error is proportional to the step size to a certain power s, the order of accuracy It can be shown that s = q + 1 for sufficiently smooth f Michael Sokolov / Numerical Methods for Chemical Engineers / Numerical Quadrature

How does Matlab do it? quad: Low accuracy, non-smooth integrands, uses adaptive recursive Simpson rule quadl: High accuracy, smooth integrands, uses adaptive Gauss/Lobatto rule (degree of integration routine related to number of points) quadgk: High accuracy, oscillatory integrands, can handle infinite intervals and singularities at the end points, uses Gauss/Konrod rule (re-uses lower degree results for higher degree approximations) Degree q of an integration rule = Polynomials up to order q can be integrated accurately (assuming there is no numerical error) Michael Sokolov / Numerical Methods for Chemical Engineers / Numerical Quadrature

Matlab Syntax Hints All the integrators use the syntax result = quadl(int_fun, a, b, ...); int_fun is a function handle to a function that takes one input x and returns the function value at x; it must be vectorized Use parametrizing functions to pass more arguments to int_fun if needed f_new = @(x)int_fun(x, K); f_new is now a function that takes only x as input and returns the value that int_fun would return when K is used as second input Note that K must be defined in this command This can be done directly in the integrator call: result = quadl(@(x)int_fun(x, K), a, b); Matlab 2012a and newer: integral(...) Michael Sokolov / Numerical Methods for Chemical Engineers / Numerical Quadrature

Assignment 1 Consider the function Use the method of forward finite differences to approximate the derivative of f(x) at x = 1. Vary h between 10-15 and 10-1 using logspace(-15, -1, 200), and calculate the error of the finite differences approximation compared to the analytical solution for each h. Plot the error vs. h using loglog. What do you observe? What could be the cause for this behavior? Repeat the calculations of 1. and 2. using the method of centered finite differences. Compare the two loglog plots. Michael Sokolov / Numerical Methods for Chemical Engineers / Numerical Quadrature

Exercise Mass Transfer into Semi-Infinite Slab c(z, t) Consider a liquid diffusing into a solid material The liquid concentration at the interface is constant The material block is considered to be infinitely long, the concentration at infinity is therefore constant and equal to the starting concentration inside the block c(z, t) z c0 = const. c∞ = const. Michael Sokolov / Numerical Methods for Chemical Engineers / Numerical Quadrature

Exercise (continued) Using a local mass balance, we can formulate an ODE where j is the diffusive flux in [kg m-2 s-1] With Δz  0, we arrive at a PDE in two variables z z+Δz jin jout Michael Sokolov / Numerical Methods for Chemical Engineers / Numerical Quadrature

Exercise (continued) By combining this local mass balance with Fick’s law, a PDE in one variable is found: The analytical solution of this equation (found by combination of variables) reads: Michael Sokolov / Numerical Methods for Chemical Engineers / Numerical Quadrature

Assignment 2 Write a Matlab program to calculate and plot the concentration profile in the slab Use the following values: c∞ = 0; c0 = 1 Create a vector zeta = linspace(1e-6, 3), calculate the value of c for each zeta, then plot c vs. zeta Use integral or quadl for the integration Create a function which calculates an integral with the trapezoidal rule Use the form: function F = trapInt(f, n, a, b) Where f is a function handle to the function that is to be integrated, n is the number of points and a and b denote the interval Provide the mean error of the two methods (1. and 2.) using fprintf Michael Sokolov / Numerical Methods for Chemical Engineers / Numerical Quadrature

Assignment 2 (continued) Improve your function by adding a convergence check: In addition to computing the integral with n points, simultaneously calculate it with 2n points while the results differ by more than 10-6, double n and iterate the calculation Terminate the calculation and issue a warning if n exceeds 106 Michael Sokolov / Numerical Methods for Chemical Engineers / Numerical Quadrature