Chapter 9: Numerical Differentiation

Similar documents
Math 1314 Lesson 16 Area and Riemann Sums and Lesson 17 Riemann Sums Using GeoGebra; Definite Integrals

The picture in figure 1.1 helps us to see that the area represents the distance traveled. Figure 1: Area represents distance travelled

18.01 Calculus Jason Starr Fall 2005

Chapter 4. Fourier Series

CHAPTER 10 INFINITE SEQUENCES AND SERIES

We are mainly going to be concerned with power series in x, such as. (x)} converges - that is, lims N n

For example suppose we divide the interval [0,2] into 5 equal subintervals of length

Math 113, Calculus II Winter 2007 Final Exam Solutions

ENGI Series Page 6-01

INTRODUCTORY MATHEMATICAL ANALYSIS

MIDTERM 3 CALCULUS 2. Monday, December 3, :15 PM to 6:45 PM. Name PRACTICE EXAM SOLUTIONS

Monte Carlo Integration

Section 13.3 Area and the Definite Integral

Math 176 Calculus Sec. 5.1: Areas and Distances (Using Finite Sums)

Lesson 10: Limits and Continuity

For example suppose we divide the interval [0,2] into 5 equal subintervals of length

6.3 Testing Series With Positive Terms

1 Approximating Integrals using Taylor Polynomials

Areas and Distances. We can easily find areas of certain geometric figures using well-known formulas:

Numerical Methods in Fourier Series Applications

INFINITE SEQUENCES AND SERIES

FIR Filter Design: Part II

Riemann Sums y = f (x)

ECE-S352 Introduction to Digital Signal Processing Lecture 3A Direct Solution of Difference Equations

Løsningsførslag i 4M

Machine Learning Brett Bernstein

Sigma notation. 2.1 Introduction

4.1 Sigma Notation and Riemann Sums

x x x 2x x N ( ) p NUMERICAL METHODS UNIT-I-SOLUTION OF EQUATIONS AND EIGENVALUE PROBLEMS By Newton-Raphson formula

Numerical Methods for Ordinary Differential Equations

Math 257: Finite difference methods

September 2012 C1 Note. C1 Notes (Edexcel) Copyright - For AS, A2 notes and IGCSE / GCSE worksheets 1

10-701/ Machine Learning Mid-term Exam Solution

Recursive Algorithms. Recurrences. Recursive Algorithms Analysis

SNAP Centre Workshop. Basic Algebraic Manipulation

Math 21B-B - Homework Set 2

NANYANG TECHNOLOGICAL UNIVERSITY SYLLABUS FOR ENTRANCE EXAMINATION FOR INTERNATIONAL STUDENTS AO-LEVEL MATHEMATICS

Numerical Integration Formulas

4.1 SIGMA NOTATION AND RIEMANN SUMS

Section A assesses the Units Numerical Analysis 1 and 2 Section B assesses the Unit Mathematics for Applied Mathematics

MATH 10550, EXAM 3 SOLUTIONS

Name: Math 10550, Final Exam: December 15, 2007

Ma 4121: Introduction to Lebesgue Integration Solutions to Homework Assignment 5

Math 10A final exam, December 16, 2016

NUMERICAL METHODS FOR SOLVING EQUATIONS

A) is empty. B) is a finite set. C) can be a countably infinite set. D) can be an uncountable set.

MAT1026 Calculus II Basic Convergence Tests for Series

It is always the case that unions, intersections, complements, and set differences are preserved by the inverse image of a function.

UNIVERSITY OF CALIFORNIA - SANTA CRUZ DEPARTMENT OF PHYSICS PHYS 116C. Problem Set 4. Benjamin Stahl. November 6, 2014

THE SOLUTION OF NONLINEAR EQUATIONS f( x ) = 0.

Sequences, Mathematical Induction, and Recursion. CSE 2353 Discrete Computational Structures Spring 2018

SOLUTIONS TO EXAM 3. Solution: Note that this defines two convergent geometric series with respective radii r 1 = 2/5 < 1 and r 2 = 1/5 < 1.

Calculus 2 - D. Yuen Final Exam Review (Version 11/22/2017. Please report any possible typos.)

5 3B Numerical Methods for estimating the area of an enclosed region. The Trapezoidal Rule for Approximating the Area Under a Closed Curve

Analysis of Algorithms. Introduction. Contents

Lecture 8: Solving the Heat, Laplace and Wave equations using finite difference methods

The Definite Integral. Day 3 Riemann Sums

6 Integers Modulo n. integer k can be written as k = qn + r, with q,r, 0 r b. So any integer.

Chapter 10: Power Series

Math 113 Exam 3 Practice

y = f(x), below by y = -1 and on the sides by x = 1/2n and x = 1. This area n~x

Markov Decision Processes

Lecture 6 Chi Square Distribution (χ 2 ) and Least Squares Fitting

AP Calculus Chapter 9: Infinite Series

Time-Domain Representations of LTI Systems

Math 113 Exam 3 Practice

1. (25 points) Use the limit definition of the definite integral and the sum formulas 1 to compute

Advanced Analysis. Min Yan Department of Mathematics Hong Kong University of Science and Technology

PAPER : IIT-JAM 2010

3. Z Transform. Recall that the Fourier transform (FT) of a DT signal xn [ ] is ( ) [ ] = In order for the FT to exist in the finite magnitude sense,

f(x) dx as we do. 2x dx x also diverges. Solution: We compute 2x dx lim

IP Reference guide for integer programming formulations.

PC5215 Numerical Recipes with Applications - Review Problems

ME NUMERICAL METHODS Fall 2007

Section 11.8: Power Series

Lecture 6 Chi Square Distribution (χ 2 ) and Least Squares Fitting

Sequences A sequence of numbers is a function whose domain is the positive integers. We can see that the sequence

(c) Write, but do not evaluate, an integral expression for the volume of the solid generated when R is

Carleton College, Winter 2017 Math 121, Practice Final Prof. Jones. Note: the exam will have a section of true-false questions, like the one below.

Chapter 7: The z-transform. Chih-Wei Liu

Solutions to Final Exam Review Problems

Integrable Functions. { f n } is called a determining sequence for f. If f is integrable with respect to, then f d does exist as a finite real number

Math 113 Exam 4 Practice

Subject: Differential Equations & Mathematical Modeling-III

Archimedes - numbers for counting, otherwise lengths, areas, etc. Kepler - geometry for planetary motion

MATH 31B: MIDTERM 2 REVIEW

ECE Spring Prof. David R. Jackson ECE Dept. Notes 20

(b) What is the probability that a particle reaches the upper boundary n before the lower boundary m?

Chapter 6 Infinite Series

10.6 ALTERNATING SERIES

Infinite Series and Improper Integrals

Chapter 2 The Monte Carlo Method

Sequences and Series of Functions

Chapter 5.4 Practice Problems

62. Power series Definition 16. (Power series) Given a sequence {c n }, the series. c n x n = c 0 + c 1 x + c 2 x 2 + c 3 x 3 +

The Growth of Functions. Theoretical Supplement

Find quadratic function which pass through the following points (0,1),(1,1),(2, 3)... 11

Chapter 7 z-transform

CHAPTER 1 SEQUENCES AND INFINITE SERIES

Transcription:

178 Chapter 9: Numerical Differetiatio Numerical Differetiatio Formulatio of equatios for physical problems ofte ivolve derivatives (rate-of-chage quatities, such as velocity ad acceleratio). Numerical solutio of such problems ivolves umerical evaluatio of the derivatives. Oe method for umerically evaluatig derivatives is to use Fiite DIffereces: From the defiitio of a first derivative dy ----- = y' ( x) dx we ca take a fiite approximatio as y' ( x) which is called Forward DIfferece Approximatio. Similarly, we could use the Backward Differece Approximatio: ( yx + ) y( x) lim ---------------------------------------- 0 y( x + ) y( x) ---------------------------------------- y( x) y( x ) y' ( x) --------------------------------------- Ad, i either case, we ca reduce a roudoff errors i the computatios by choosig to be a small value that ca be exactly represeted i biary (for example ot 0.1).

179 Also, i additio to a x differece that ca be exactly represeted i biary, we ca get a somewhat better approximatio to the first derivative with a Cetral Fiite Differece: y' ( x) y( x + ) y( x ) ---------------------------------------------------- 2 Example: Give a expressio for the fuctio f(x, y) i the equatio: dy ----- = f ( x, y) dx we ca umerically approximate y values over the rage of x, with the differece equatio: y( x + ) y( x) = f ( x, y) Assumig we kow the iitial value y 0 ad we subdivide the x rage from x 0 to x ito equal itervals, we ca solve for each successive y value as y k = y k 1 + f ( x k 1, y k 1 ), k = 1, 2,, I geeral, such problems ca be solved with ouiform x subitervals ad with kow iitial or boudary coditos.

180 Usig similar methods, we ca evaluate equatios ivolvig partial derivatives, ad we ca set up fiite differece approximatios for higher order derivatives. For istace, for secod derivatives, we ca use the approximatio y' ( x) y( x + ) 2y( x ) -------------------------------------------------------- 2 Derivative Fuctios i Mathematica Numerical evaluatio of differet equatios accomplished with NDSolve[ eqs, y, {x, ymi, xmax]} - umerically solves eqs (which iclude iitial or boudary equatios) for y with idepedet variable x i the rage xmi to xmax. NDSolve[ eqs, {y1, y2,...}, {x, xmi, xmax}] - solves the set of eqs for values y1, y2, etc. Example: NDSolve[{y [x]==exp[x],y[0]==1},y,{x,0,5}] {{y -> IterpolatigFuctio[{0., 5.}, <>]}} Solutio the stored as a iterpolatio table, ad we retrieve values with statemets such as y[1.0 /. % {2.71829}

181 Also, we ca use statemets such as Plot[Evaluate[y[x] /. %], {x,xmi, xmax}] to plot the umeric solutio. Symbolic differece performed with D[, x] - evaluates first derivative of with respect to x. (Ca also be applied to f(x1, x2,...).) D[, {x, } ] - evaluates th derivative of with respect to x. Examples: (Also ca use D fuctio to obtai partial derivatives.) D[Exp[x],x] E x D[x^3, x] 3 x 2 D[x^3, {x, 2}] 6 x {secod derivative D[x^2 y, x] {partial derivative 2 x y

182 Chapter 9: Numerical Itegratio Numerical Itegratio Most itegrals arisig from solutios of problems i egieerig ad sciece caot be represeted i closed form - they must be evaluated umerically. For fuctio of a sigle variable, we seek a approximatio to the area uder the curve: Area = b a f ( x) dx a b x For fuctio of several variables, we seek approximatio to the size of the volume for the specified itegratio regio. We will cosider oly algorithms for fuctios of a sigle variable:.

183 Numerical evaluatio procedures for a fuctio of a sigle variable ivolve summatio of small subareas, usig simple fuctios to approximate. For example, by defiitio of itegral: b f ( x ) dx = lim f ( x k ) k a a k = 1 with k = x k x k 1 We ca approximate itegral with a fiite umber of subitervals usig a costat value for i each subiterval: f ( x) = f ( x 1 ) x k 1 x x k, k = 1, 2,, x 0 =a x 1 x 2 x 3 x -1 x =b I this case, we approximate itegral by addig the areas of a set of approximatig rectagles.

184 Example: f ( x) = 1 x 2, a = 1, b = 1 A = 1 1 g( x) dx -1 0 1 x Selectig equal width itervals with with = 5, we have b a 2 k = ----------- = -- = 0.4 k 5 The area is the approximated as A k = 1 with x k = x k 1 + k ad x 0 = -1. f ( x k ) k -1 -.6-2.2.6 1 x The A f ( x k ) 0.4( 0.8 + 0.98 + 0.98 + 0.8 + 0.0) k = 1 1.42 Actual size of area: A -------- πr2 1.57 2

185 We ca improve umerical estimate of itegral by Icreasig umber of itervals. Usig a more accurate approximatio of i each iterval. Commo Approximatio Methods: Liear Quadratic or Higher-Order Polyomial Trapezoidal Rule Approximate with liear fuctio over each subiterval. Area is the calculated as the sum of the areas of resultig trapezoids: Takig equal-width itervals: b a = ----------- x 0 = a x 1 x 2 x 3... Thus, or Area of each trapezoid is A k f ( x k 1) + f ( x k ) = -----------------------------------------, 2 k = 1, 2,, b f ( x) dx ----- [ f ( x 2 0 ) + f ( x 1 ) ] + [ f ( x 1 ) + f ( x 2 ) ] + a + [ f ( x 1 ) + f ( x )] } b f ( x) x 1 1 2 -- [ f ( a d ) + f ( b) ] + f ( x k ) a k = 1

186 Example: Trapezoidal Rule to evaluate Width of each iterval is 1 ( 1) = ------------------- = 0.5 5 Itegral is the evaluated as 1 1 x 2 x, = 5 1 x 0 = 1, x k = x k 1 +, k = 1, 2, 3, 4, 5 1 f ( x) x -------------------------------- f ( 1) + f ( 1) 4 d + 2 f ( x ) k 1 k = 1 0.4( 0.80 + 0.98 + 0.98 + 0.80) 1.42 (Same result as obtaied usig rectagular areas. Why?)

187 Simpso s Rule Approximates with a quadratic fuctio. More accurate evaluatio of itegral tha Trapezoidal Rule (a liear approximatio). Simpso s Rule (parabola) Trapezoidal Rule (liear) x k-1 x k 1 + x k ------------------------ 2 x k I this case, the itegral is approximated as x k b f ( x) dx ( α 0 + α 2 x + α 2 x 2 ) dx a k = 1 x k 1 To evaluate the summatio, we eed to determie the parabola coefficiets α 0, α 1, α 2 i each of the subdivisios. We ca accomplish this with three boudary coditios that require the parabola to itersect at the edpoits ad at the midpoit of each subdidivisio.

188 Applyig Simpso s Rule: 1. Divide iterval (a, b) ito equal subitervals, with a multiple of 2. 2. Approximate with parabola across every two subitervals. α 0 + α 1 x + α 2 x 2 x k-1 x k x k+1 Obtai coefficiets α 0, α 1, α 2 by solvig 2 α 0 + α 1 x k 1 + α 2 x k 1 = f ( x k 1 ) 2 α 0 + α 1 x k + α 2 x k = f ( x k ) 2 α 0 + α 1 x k + 1 + α 2 x k + 1 = f ( x k + 1 ) over each of the itervals (x k-1, x k+1 ).

189 We the approximate itegral as x k + 1 f x dx 1 ( α 0 + α 1 x + α 2 x 2 ) dx a k = 1 x k 1 kodd 1 k = 1 kodd α 0 x + a 1 x 2 x 3 ---- + α 2 2 ---- 3 x k + 1 x k 1 Substitutig the solutio for α 0, α 1, α 2 over itervals (x k-1, x k+1 ), we obtai b s 1 1 f ( x) dx -- [ f ( x 3 k 1 ) + 4 f ( x k ) + f ( x k + 1 )] k = 1 kodd where = x k+1 - x k = x k - x k-1 {Note: A easy way to derive this result is to cosider a parabols specified over the iterval (- x, x ). Hece, b f ( x) dx ----- [( f 3 0 + 4 f 1 + f 2 ) + ( f 2 + 4 f 3 + f 4 ) + ] a Collectig terms, we have Simpso s Rule: b a f ( x) dx ----- f ( a) + f b + 3 1 ( ) 4 f ( x) + 2 f ( x k ) k = 1 k = 2 ( odd) ( eve) with each successive x value calculated as x k = x k 1 + ( k = 1, 2,, ) 2

190 Example: Simpso s Rule Evaluatio of 1 1 x 2 d x, = 4 The, Ad 1 1 ( 1) = ------------------- = 0.5 4 x 0 = 1, x k = x k = 1 +, k = 1, 2, 3, 4 1 3 2 f ( x) dx ----- f ( 1) + f ( 1) + 4 f ( x 3 k ) + 2 f ( x k ) 1 k = 1 k = 2 ( odd) ( eve) ----- { 4[ f ( x 3 1 ) + f ( x 3 )] + 2 f ( x 2 )} 1 -- [ 4( 0.87 + 0.87) + 2( 1) ] 6 1 -- ( 8.96) 6 1 1.49 where f ( x) d x 1.57 Thus Simplso with =4 is better tha Trapezoidal with =5. 1

191 Psuedocode Algorithm - Simpso s Rule Iput f, a, b, (* fc, iteger limits, o. of itervals *) dx = (b-a)/ dx2 = dx + dx odds = 0.0; eves = 0.0 x = a Do k=2, -2, 2 x = x + dx2 eves = eves + Edofdo x = a - dx Do k = 1, -1, 2 x = x + dx2 odds = odds + Edofdo simpsoarea=(dx/3.0)*(f(a)+f(b)+4.0*odds+2.0*eves) Summary of Itegratio Methods Approximate = f(x k ) (costat) over each iterval A b a ----------- f ( x ) k k = 1 x 0 = a, x = b x k = x k = 1 + ( b a) Trapezoidal Rule: Liear Approximatio A b ----------- a f ( a) + f ( b) 1 ---------------------------- + 2 f ( x ) k k = 1 Simpso s Rule: Quadratic Approximatio, eve A 1 2 ----- f ( a) + f ( b) + 4 f ( x 3 k ) + 2 f ( x k ) k = 1 k = 2 = (b-a)/ ( odd) ( eve)

192 Numerical Itegratio Errors For small, error is primarily due to approx. of (width of subitervals large). For large, roudoff errors become sigificat; i.e., area of each subiterval small, ad this value ca get lost i precisio of larger accumulated area: accumulated area ext subiterval a b x Error Magitude Plot: error roudoff error approximatio error (due to width of subitervals) ideal umber of subitervals Ideal value for depeds o: Form of Itegratio method used Computer System

193 Numerical Itegratio Improvemets Repeatedly icrease umber of subitervals util area estimate is withi specified tolerace. A method for accomplishig this is to start with large subitervals ad the double the umber of itervals at each step: Iput compute: area oldarea = area = 2 compute: area relerror = (oldarea - area) o relerror < tolerace yes retur Also, could use higher-order polyomials to approximate over each of the subitervals. Ad we could use higher precisio i calculatios to reduce roudoff errors. (Tradeoff: more calculatio time.)

194 Numerical Evaluatio of Ifiite Itegrals Divide itegral ito parts ad apply a umerical itegratio techique to each part util cotributios ted to zero. For example: a f ( x) dx = a 1 a 1 f ( x) dx + a 2 a 1 f ( x) dx + a 1 a 1 f ( x) dx + If itegral is fiite, the we must have f ( x) 0 as x, That is, we ca compute the itegral as a fiite umber of terms: a f ( x) dx = f ( x) dx + ε a a k 1 k = 1 whter the error term is less tha some specified tolerace.

195 Mote Carlo Methods Examples: Use of radom umbers to solve determiistic problems. This approach useful for umerically evaluatig complex itegrals. Multiple Itegratio b 1 b b 1 b f ( x 1, x 2,, x ) x 1 Fuctios with High-Frequecy Oscillatios b b d d x 2 dx a b x Basic Approach: Geerate uiformly distributed radom poits i a area cotaiig ad the iterval (a, b) -- where area is ot too large compared to itegral area. The compute: h a b x b f ( x) dx a ----------------------- h( b a) = lim umber of poits uder ----------------------------------------------------------------- where (b-a) may be positive or egative, ad we might have < 0 over part or all of the iterval (a, b).

196 Algorithm: Mote Carlo Itegratio 1. Geerate two uiformly distributed radom umbers r 1, r 2 i the iterval (0,1). x = a + r 1 ( b a) 2. Assumig 0, calculate coordiate positios (x,y) as: y = r 2 h h f(x,y) a b x Cout poit (x,y) as uder if 0 y f ( x) f ( x) 0 3. If < 0 for a value of x i the iterval (a,b), calculate coordiate positio as h = y max y mi y max x = a + r 1 ( b a) a f(x,y) b y = y mi + r 2 h y mi Cout poit (x,y) as uder if 0 y f ( x) for f ( x) < 0 I this case, we subtract 1 from the poit cout; i.e., ptcout =, - where is the umber of poits below the x axis.

197 Pseudocode Algorithm - Mote Carlo Itegratio Iput f, a, b, h, (* assume > 0; how width = b - a ca this be modified ptcout = 0 for < 0 also? *) Do k = 1, x = a + width * Radom( ) y = h * Radom( ) If (y < ) The ptcout = ptcout + 1 Edofif Edofdo area = h * width * ptcout / 1 Example: 1 x 2 dx 1 y mi = 0, y max = 1 a = 1, b = 1, h = 1, = 10 y -1 0 1 1 x r 1 r 2 x = -1 + 2r 1 y = r 2 = 1 - x 2 ptcout1 1 0.972 0.466 0.944 0.466 0.330 0 2 0.069 0.001-0.862 0.001 0.507 1 3 0.038 0.395-0.924 0.395 0.382 1 4 0.740 0.267 0.480 0.267 0.877 2 5 0.152 0.948-0.696 0.948 0.718 2 6 0.805 0.662 0.610 0.662 0.792 3

198 r 1 r 2 x = -1 + 2r 1 y = r 2 = 1 - x 2 ptcout1 7 0.227 0.034-0.546 0.034 0.838 4 8 0.607 0.835 0.214 0.835 0.977 5 9 0.212 0.463 0.576 0.463 0.817 6 10 0.670 0.624 0.340 0.624 0.940 7 Itegratio Fuctios i Mathematica Itegrate[, x] - idefiite itegral of Itegrate[, {x, xmi, xmax}] - defiite itegral of with itegratio limits xmi ad xmax Itegrate[f(x, y), {x, xmi, xmax}, {y, ymi, ymax}] - multiple itegral of fuctio f(x, y) Nitegrate[... ] - umerically evaluate itegral Examples: Itegrate[x^3,x] x 4 ---- 4 Itegrate[x^3,{x,a,b}] x 4 b 4 -------- + ----- 4 4 Itegrate[x^3,{x,0,1}] 1 -- 4

199 Itegrate[Sqrt[1-x^2],{x,-1,1}] Pi ---- 2 NItegrate[Sqrt[1-x^2],{x,-1,1}] 1.5708 f[x_, y_1] := x y^2 Itegrate[f[x,y], {x,0,a}, {y,0,b}] a 2 b 3 ----------- 6 Itegrate[f[x,y], {x,0,3}, {y,0,2}] 12 NItegrate[f[x,y], {x,0,3}, {y,0,2}] 12.000000000000000001 (roudoff error)