Numerical Differentiation and Quadrature (Integration) 1Daniel Baur / Numerical Methods for Chemical Engineers / Numerical Quadrature Daniel Baur ETH Zurich,

Slides:



Advertisements
Similar presentations
Programming Tips: While Loops and Comparisons 1Daniel Baur / Numerical Methods for Chemical Engineerse Daniel Baur ETH Zurich, Institut für Chemie- und.
Advertisements

Boundary Value Problems and Partial Differential Equations (PDEs)
Chapter 6 Differential Equations
Numerical Integration
Fixed point iterations and solution of non-linear functions
Introduction to Matlab 7
Prof. R. Shanthini 05 March CP302 Separation Process Principles Mass Transfer - Set 3.
HW/Tutorial Week #10 WWWR Chapters 27, ID Chapter 14 Tutorial #10 WWWR # 27.6 & To be discussed on March 31, By either volunteer or class list.
Partial Differential Equations (PDEs) 1Daniel Baur / Numerical Methods for Chemical Engineers / BVP and PDE Daniel Baur ETH Zurich, Institut für Chemie-
1 Chapter 5 Numerical Integration. 2 A Review of the Definite Integral.
Systems of Linear Equations
Asymptotic error expansion Example 1: Numerical differentiation –Truncation error via Taylor expansion.
Numerical Integration of Functions
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
Lecture 18 - Numerical Differentiation
Response Surface Method Principle Component Analysis
Linear Systems of Equations Ax = b Marco Lattuada Swiss Federal Institute of Technology - ETH Institut für Chemie und Bioingenieurwissenschaften ETH Hönggerberg/
MANE 4240 & CIVL 4240 Introduction to Finite Elements Numerical Integration in 1D Prof. Suvranu De.
Numerical Integration
Non Linear Regression Y i = f(  x i ) +  i Marco Lattuada Swiss Federal Institute of Technology - ETH Institut für Chemie und Bioingenieurwissenschaften.
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.
Chapter 9 Numerical Integration Numerical Integration Application: Normal Distributions Copyright © The McGraw-Hill Companies, Inc. Permission required.
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.
Numerical Integration UC Berkeley Fall 2004, E77 Copyright 2005, Andy Packard. This work is licensed under the.
1 Chapter 5 Numerical Integration. 2 A Review of the Definite Integral.
3. Numerical integration (Numerical quadrature) .
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.
1 Numerical Analysis Lecture 12 Numerical Integration Dr. Nader Okasha.
CMPS1371 Introduction to Computing for Engineers NUMERICAL METHODS.
Chapters 5 and 6: Numerical Integration
Systems of Linear Equations Iterative Methods
MA2213 Lecture 4 Numerical Integration. Introduction Definition is the limit of Riemann sums I(f)
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Introduction to MATLAB 7 for Engineers William J. Palm.
Boundary Value Problems and Least Squares Minimization
Integration Copyright © Cengage Learning. All rights reserved.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Chapter 22.
Quadrature rules 1Michael Sokolov / Numerical Methods for Chemical Engineers / Numerical Quadrature Michael Sokolov ETH Zurich, Institut für Chemie- und.
Numerical Differentiation and Quadrature (Integration)
Solution of Nonlinear Functions
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.
Techniques for Numerical Integration
Linear Systems of Equations Iterative and Relaxation Methods Ax = b Marco Lattuada Swiss Federal Institute of Technology - ETH Institut für Chemie und.
6. Numerical Integration 6.1 Definition of numerical integration. 6.2 Reasons to use numerical integration. 6.3 Formulas of numerical Integration. 6.4.
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. A Concise Introduction to MATLAB ® William J. Palm III.
Chapters 5 and 6: Numerical Integration Code development trapezoid rule Simpson’s rule Gauss quadrature Laguerre quadrature Analysis changing the variable.
4.1 Antiderivatives 1 Definition: The antiderivative of a function f is a function F such that F’=f. Note: Antiderivative is not unique! Example: Show.
3/12/ Trapezoidal Rule of Integration Computer Engineering Majors Authors: Autar Kaw, Charlie Barker
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Chapter 20 Numerical Integration of Functions.
Chapter 7 Numerical Differentiation and Integration
Chapter 22.
The Area Question and the Integral
Zero of a Nonlinear System of Algebraic Equations f(x) = 0
Copyright © Cengage Learning. All rights reserved.
Numerical Computation and Optimization
Numerical Integration of Functions
SKTN 2393 Numerical Methods for Nuclear Engineers
Assignment 1: due 1/16/19 Estimate all of the zero of x3-x2-2x+1 graphically. Write a MatLab code for Newton’s method. Use your code to refine the graphical.
Numerical Computation and Optimization
Assignment 1: due 1/17/19 Estimate all of the zero of x3-x2-2x+1 graphically. Write a MatLab code for Newton’s method. Use your code to refine the graphical.
Presentation transcript:

Numerical Differentiation and Quadrature (Integration) 1Daniel Baur / Numerical Methods for Chemical Engineers / Numerical Quadrature Daniel Baur ETH Zurich, Institut für Chemie- und Bioingenieurwissenschaften ETH Hönggerberg / HCI F128 – Zürich

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 finite differences:  Remember that:  Therefore:for small h 2Daniel Baur / Numerical Methods for Chemical Engineers / Numerical Quadrature

Numerical Quadrature (Integration) f(x) [a,b]  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 3Daniel Baur / Numerical Methods for Chemical Engineers / Numerical Quadrature

Trapezoidal rule 4Daniel Baur / Numerical Methods for Chemical Engineers / Numerical Quadrature ax1x1 x2x2 x n-1 b

How does Matlab do it?  quad  quad : Low accuracy, non-smooth integrands, uses adaptive recursive Simpson rule  quadl  quadl : High accuracy, smooth integrands, uses adaptive Gauss/Lobatto rule (degree of integration routine related to number of points)  quadgk  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 p of an integration rule = Polynomials up to order p can be integrated accurately (assuming there is no numerical error) 5Daniel Baur / Numerical Methods for Chemical Engineers / Numerical Quadrature

Matlab Syntax Hints result = quadl(int_fun, a, b,...);  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 f_new K);  Use parametrizing functions to pass more arguments to int_fun if needed f_new 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 result = K), a, b);  This can be done directly in the integrator call: result = K), a, b); integral(...)  Matlab 2012a and newer: integral(...) 6Daniel Baur / Numerical Methods for Chemical Engineers / Numerical Quadrature

Assignment 1  Consider the function f(x)x = 1h logspace(-15, -1, 200) h 1.Use the method of finite differences to approximate the derivative of f(x) at x = 1. Vary h between and using logspace(-15, -1, 200), and calculate the error of the finite differences approximation compared to the analytical solution for each h. hloglog 2.Plot the error vs. h using loglog. What do you observe? What could be the cause for this behavior? 7Daniel Baur / Numerical Methods for Chemical Engineers / Numerical Quadrature

Exercise  Mass Transfer into Semi-Infinite Slab  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 8Daniel Baur / Numerical Methods for Chemical Engineers / Numerical Quadrature c(z, t) 0 z c 0 = const.c ∞ = const.

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 9Daniel Baur / Numerical Methods for Chemical Engineers / Numerical Quadrature z z+Δz j in j out

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: 10Daniel Baur / Numerical Methods for Chemical Engineers / Numerical Quadrature

Assignment 2 1.Write a Matlab program to calculate and plot the concentration profile in the slab  Use the following values: c ∞ = 0; c 0 = 1 zeta = linspace(1e-6, 3) czetaczeta  Create a vector zeta = linspace(1e-6, 3), calculate the value of c for each zeta, then plot c vs. zeta integral quadl  Use integral or quadl for the integration 2.Create a function which calculates an integral with the trapezoidal rule function F = trapInt(f, n, a, b)  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 quadlintegral  Use your function to solve the diffusion problem and compare it to the result you obtained with quadl or integral. 11Daniel Baur / Numerical Methods for Chemical Engineers / Numerical Quadrature

Assignment 2 (continued) 3.Improve your function by adding a convergence check:  In addition to computing the integral with n points, simultaneously calculate it with 2n points  while  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 Daniel Baur / Numerical Methods for Chemical Engineers / Numerical Quadrature