Numerical Integration and Numerical Differentiation. Hsiao-Lung Chan Dept Electrical Engineering Chang Gung University, Taiwan

Similar documents
PowerPoints organized by Dr. Michael R. Gustafson II, Duke University

PowerPoints organized by Dr. Michael R. Gustafson II, Duke University

Numerical Methods School of Mechanical Engineering Chung-Ang University

Chapter 5: Numerical Integration and Differentiation

Chap. 19: Numerical Differentiation

PowerPoints organized by Dr. Michael R. Gustafson II, Duke University

Gauss Elimination. Hsiao-Lung Chan Dept Electrical Engineering Chang Gung University, Taiwan

Integration. Topic: Trapezoidal Rule. Major: General Engineering. Author: Autar Kaw, Charlie Barker.

What are Numerical Methods? (1/3)

Numerical Integra/on

Then, Lagrange s interpolation formula is. 2. What is the Lagrange s interpolation formula to find, if three sets of values. are given.

n = 4: 0 2( ) (4 0) ( t 2.67%) 8

Numerical Methods School of Mechanical Engineering Chung-Ang University

Numerical Methods. King Saud University

Engg. Math. II (Unit-IV) Numerical Analysis

Numerical Methods School of Mechanical Engineering Chung-Ang University

Lecture 8: Calculus and Differential Equations

Lecture 8: Calculus and Differential Equations

Numerical Integration of Functions

SKMM 3023 Applied Numerical Methods

GENG2140, S2, 2012 Week 7: Curve fitting

ECE257 Numerical Methods and Scientific Computing. Ordinary Differential Equations

Bindel, Spring 2012 Intro to Scientific Computing (CS 3220) Week 12: Monday, Apr 16. f(x) dx,

2D Plotting with Matlab

Chapter 5 Roots of Equations: Bracketing Models. Gab-Byung Chae

Numerical integration and differentiation. Unit IV. Numerical Integration and Differentiation. Plan of attack. Numerical integration.

Numerical Integration

Integration, differentiation, and root finding. Phys 420/580 Lecture 7

USHA RAMA COLLEGE OF ENGINEERING & TECHNOLOGY

MA6452 STATISTICS AND NUMERICAL METHODS UNIT IV NUMERICAL DIFFERENTIATION AND INTEGRATION

Jim Lambers MAT 460/560 Fall Semester Practice Final Exam

MA 3021: Numerical Analysis I Numerical Differentiation and Integration

Numerical Integra/on

ENGINEERING MATHEMATICS 4 (BDA34003)

Extrapolation in Numerical Integration. Romberg Integration

Numerical Analysis Solution of Algebraic Equation (non-linear equation) 1- Trial and Error. 2- Fixed point

Rectilinear Motion. Velocity

Engineering Mathematics through Applications

Numerical and Statistical Methods

Second Order ODEs. CSCC51H- Numerical Approx, Int and ODEs p.130/177

At right: Closeups of the graphs of. with WINDOW settings Xmin=-1, Xmax=1, Xscl=0.1, Ymin=-1, Ymax=1, Yscl=0.1

Numerical and Statistical Methods

SOLUTIONS to Exercises from Optimization

Review. Numerical Methods Lecture 22. Prof. Jinbo Bi CSE, UConn

Numerical Integration (Quadrature) Another application for our interpolation tools!

Variational Methods & Optimal Control

BSM510 Numerical Analysis

Virtual University of Pakistan

Numerical Solution of f(x) = 0

Input: A set (x i -yy i ) data. Output: Function value at arbitrary point x. What for x = 1.2?

TABLE OF CONTENTS INTRODUCTION, APPROXIMATION & ERRORS 1. Chapter Introduction to numerical methods 1 Multiple-choice test 7 Problem set 9

Notation Nodes are data points at which functional values are available or at which you wish to compute functional values At the nodes fx i

Week 10 TENTATIVE SCHEDULE NUMERICAL APPROXIMATION LECTURE # 10

INSTITUTE OF AERONAUTICAL ENGINEERING (Autonomous) Dundigal, Hyderabad

INSTITUTE OF AERONAUTICAL ENGINEERING Dundigal, Hyderabad MECHANICAL ENGINEERING TUTORIAL QUESTION BANK

SBAME CALCULUS OF FINITE DIFFERENCES AND NUMERICAL ANLAYSIS-I Units : I-V

FINITE DIFFERENCES. Lecture 1: (a) Operators (b) Forward Differences and their calculations. (c) Backward Differences and their calculations.

Section 6.6 Gaussian Quadrature

Digital Elevation Models. Using elevation data in raster format in a GIS

PowerPoints organized by Dr. Michael R. Gustafson II, Duke University

MATH 10550, EXAM 2 SOLUTIONS. 1. Find an equation for the tangent line to. f(x) = sin x cos x. 2 which is the slope of the tangent line at

Research Computing with Python, Lecture 7, Numerical Integration and Solving Ordinary Differential Equations

SOLUTION OF EQUATION AND EIGENVALUE PROBLEMS PART A( 2 MARKS)

8.3 Numerical Quadrature, Continued

Topic 6a Numerical Integration

Differential Lengths, Surfaces and Volumes

Ch. 03 Numerical Quadrature. Andrea Mignone Physics Department, University of Torino AA

I II III IV V VI VII VIII IX X Total

2.29 Numerical Fluid Mechanics Spring 2015 Lecture 9

Computational Methods for Engineers Programming in Engineering Problem Solving

Integration of Ordinary Differential Equations

Interpolation Theory

Curve Fitting and Interpolation

KINGS COLLEGE OF ENGINEERING DEPARTMENT OF MATHEMATICS ACADEMIC YEAR / EVEN SEMESTER QUESTION BANK

Review for Exam 2 Ben Wang and Mark Styczynski

(0, 0), (1, ), (2, ), (3, ), (4, ), (5, ), (6, ).

AM205: Assignment 3 (due 5 PM, October 20)

SECTION 7: CURVE FITTING. MAE 4020/5020 Numerical Methods with MATLAB

Scientific Computing. Roots of Equations

Numerical Methods for Engineers

MA 8019: Numerical Analysis I Solution of Nonlinear Equations

BACHELOR OF COMPUTER APPLICATIONS (BCA) (Revised) Term-End Examination December, 2015 BCS-054 : COMPUTER ORIENTED NUMERICAL TECHNIQUES

M.SC. PHYSICS - II YEAR

Optimization using Calculus. Optimization of Functions of Multiple Variables subject to Equality Constraints

MA 114 Worksheet # 17: Integration by trig substitution

MATH 200 WEEK 5 - WEDNESDAY DIRECTIONAL DERIVATIVE

Interpolation and Approximation

INTERPOLATION Background Polynomial Approximation Problem:

EAD 115. Numerical Solution of Engineering and Scientific Problems. David M. Rocke Department of Applied Science

Simulation on Magnetic Field Characteristics of Permanent-Magnet Seed-Metering Device

INTERPOLATION. and y i = cos x i, i = 0, 1, 2 This gives us the three points. Now find a quadratic polynomial. p(x) = a 0 + a 1 x + a 2 x 2.

Lecture 8. Root finding II

Solution of Nonlinear Equations

CS 450 Numerical Analysis. Chapter 8: Numerical Integration and Differentiation

MA1023-Methods of Mathematics-15S2 Tutorial 1

The polar coordinates

Finding Roots of Equations

UNIT-II INTERPOLATION & APPROXIMATION

MTH4101 CALCULUS II REVISION NOTES. 1. COMPLEX NUMBERS (Thomas Appendix 7 + lecture notes) ax 2 + bx + c = 0. x = b ± b 2 4ac 2a. i = 1.

Finding the Roots of f(x) = 0. Gerald W. Recktenwald Department of Mechanical Engineering Portland State University

Transcription:

Numerical Integration and Numerical Differentiation Hsiao-Lung Chan Dept Electrical Engineering Chang Gung University, Taiwan chanhl@mail.cgu.edu.tw

Integration 2

Mean for discrete and continuous data Discrete data Continuous data 3

Numerical integration, also referred to as quadrature The integral may be evaluated over a line, an area, or a volume Determine the net force due to a non-uniform wind blowing against the side of a skyscraper Areal integral: Compute the total rate of energy transfer across a plane where the flux is a function of position Volume integral: the total mass of chemical contained in a reactor is given as the product of the concentration of chemical and the reactor volume. 4

Newton-Cotes formulas The strategy of replacing a complicated function or tabulated data with a polynomial that is easy to integrate I b f x dx f n x dx a b a The approximation of an integral by the area under a straight line and a parabola 5

Trapezoidal rule The first of the Newton-Cotes closed integration formulas b I f n x dx I a b f (a) f b f a x a dx a b a I b a f a f b 2 6

Composite trapezoidal rule x n x 1 x 2 x n I f n x dx f n x dx f n x dx f n x dx x 0 I x 1 x 0 f x 0 f x 1 2 I h n 1 2 f x 0 2 f x i f x n i 1 x 0 x 1 x 2 x 1 f x 1 f x 2 2 x n 1 x n x n 1 f x n 1 f x n 2 7

M-file to implement the composite trapezoidal rule function I = trap(func,a,b,n,varargin) % a, b = integration limits, n = number of segments if nargin<3, error('at least 3 input arguments required'), end if ~(b>a), error('upper bound must be greater than lower'), end if nargin<4 isempty(n), n=100; end x = a; h = (b - a)/n; s=func(a,varargin{:}); for i = 1 : n-1 x = x + h; s = s + 2*func(x,varargin{:}); end s = s + func(b,varargin{:}); I = (b - a) * s/(2*n); 8

Example: Determine the distance fallen by the free-falling bungee jumper Falling velocity v t gm c d tanh gc m d t If g = 9.81 m/s2,m = 68.1 kg, cd = 0.25 kg/m, determine falling distance in the first 3 s v=@(t) sqrt(9.81*68.1/0.25)*tanh(sqrt(9.81*0.25/68.1)*t) falldist=trap(v,0,3,5); 9

Simpson s rules A more accurate estimate of an integral Apply the trapezoidal rule with finer segmentation Use higher-order polynomials to connect the points Simpson s 1/3 Rule using a 2 nd -order Lagrange polynomial 10

Composite Simpson s 1/3 rule 11

Simpson s 3/8 rule A third-order Lagrange polynomial is fit to four points and integrated to yield Simpson s 1/3 rule Simpson s 3/8 rule 12

Higher-order newton-cotes formulas 13

Integration with unequal segments Apply the trapezoidal rule M-file for implementing the trapezoidal rule for unequally spaced data x = [0.12.22.32.36.4.44.54.64.7.8]; y = 0.2+25*x-200*x.^2+675*x.^3-900*x.^4+400*x.^5; z= trapuneq(x,y); 14

M-file to implement the trapezoidal rule for unequally spaced data function I = trapuneq(x,y) if nargin<2, error('at least 2 input arguments required'),end if any(diff(x)<0), error('x not monotonically ascending'),end n = length(x); if length(y)~=n, error('x and y must be same length'); end s = 0; for k = 1:n-1 s = s + (x(k+l)-x(k))*(y(k)+y(k+l))/2; end I = s; 15

MATLAB s built-in function for evaluating integrals z = trapz(x, y) x = [0.12.22.32.36.4.44.54.64.7.8]; y = 0.2+25*x-200*x.^2+675*x.^3-900*x.^4+400*x.^5; z = trapz(x,y); z = cumtrapz(x, y) Computes the cumulative integral z = a vector whose elements z(k) hold the integral from x(1) to x(k) Cumulative integral 16

Multiple integrals Double integral 17

MATLAB s built-in function of multiple integral Double (dblquad) and triple (triplequad) integration q = dblquad(fun, xmin, xmax, ymin, ymax, tol); tol: a default tolerance of 1 10 6 is used Example: the temperature of a rectangular heated plate is described by the following function q = dblquad(@(x,y) 2*x*y+2*x-x.^2-2*y.^2+72,0,8,0,6); 18

Definition of a derivative Difference approximation Derivative x approaches zero 19

High-accuracy differentiation formulas Taylor series expansion can be used to generate highaccuracy formulas for derivatives Forward finite-difference Backward finite-difference Centered finite-difference 20

High-accuracy differentiation formulas (cont.) Forward Taylor series expansion Substitute into the above equation Improve the accuracy to O(h 2 ). 21

High-accuracy differentiation formulas (cont.) Forward finite-difference formulas Backward finite-difference formulas Centered finite-difference formulas 22

MATLAB built-in function of derivative: diff f=@(x) 0.2+25*x-200*x.^2+675*x.^3-900*x.^4+400*x.^5; x=0:0.1:0.8; y=f(x); % generate a series of equally spaced values of variables % numerical estimate of differentiation d=diff(y)./diff(x); d=diff(f(x))/0.1; % because of equally spaced values % analytical estimate of differentiation xa=0:.01:.8; ya=25-400*xa+3*675*xa.^2-4*900*xa.^3+5*400*xa.^4; n=length(x); xm=(x(1:n-1)+x(2:n))./2; plot(xm,d,'o',xa,ya) 23

MATLAB built-in function diff (cont.) 24

MATLAB built-in function of derivative: gradient f=@(x) 0.2+25*x-200*x.^2+675*x.^3-900*x.^4+400*x.^5; x=0:0.1:0.8; y=f(x); % generate a series of equally spaced values of variables % numerical estimate of differentiation dy=gradient(y,0.1); % because of equally spaced values % analytical estimate of differentiation xa=0:.01:.8; ya=25-400*xa+3*675*xa.^2-4*900*xa.^3+5*400*xa.^4; n=length(x); xm=(x(1:n-1)+x(2:n))./2; plot(xm,d,'o',xa,ya) 25

MATLAB built-in function gradient (cont.) centered differences for intermediate values forward and backward differences at the ends 26

Partial derivatives Partial first derivatives can be approximated with centered differences 27

Example: gradient of mountain elevation z = f (x, y) where z = elevation, x = distance measured along the eastwest axis, y = distance measured along the north-south axis. The gradient of f(x,y) which represents the steepest Slope with a magnitude and direction 28

Gradient of mountain elevation (cont.) f=@(x,y) y-x-2*x.^2-2.*x.*y-y.^2; [x,y]=meshgrid(-2:.25:0, 1:.25:3); z=f(x,y); [fx,fy]=gradient(z,0.25); cs=contour(x,y,z); clabel(cs); hold on % Resultant of partial derivatives is % superimposed as vectors on contour plot quiver(x,y,-fx,-fy); hold off 29

Reference Steven C. Chapra "Applied Numerical Methods with MATLA B", 3rd ed., McGraw Hill, 2012. 30