/8/8 Course Instructor Dr. Rymond C. Rump Oice: A 7 Pone: (95) 747 6958 E Mil: rcrump@utep.edu Topic 6b Finite Dierence Approximtions EE 486/5 Computtionl Metods in EE Outline Wt re inite dierence pproximtions? Overview o deriving inite dierence pproximtions Algoritm or clculting inite dierence pproximtions Exmples Clculting inite dierence coeicients using MATLAB Exmples
/8/8 Wt re Finite Dierence Approximtions? Wt re Finite Dierence Approximtions? ( o ) Very oten in science nd engineering we must clculte derivtive. Wen we re processing dt rom mesurements or simultions, tere my not be n nlyticl eqution to work wit symboliclly. Typiclly, we only know te unction t discrete points. x x x Slide 4
/8/8 Wt re Finite Dierence Approximtions? ( o ) Suppose we wis to numericlly clculte te irst order derivtive t x. Te irst order derivtive is slope. We cn estimte te slope s riserun using inormtion rom surrounding points. rise run x x x run = x rise = x x x Slide 5 Wt re Finite Dierence Approximtions? ( o ) We cn estimte te derivtive t te midpoint between dt points. x x.5 x.5 x Te second order derivtive is te slope o te slope. x.5 x.5 x x x x x x.5.5 x x x Slide 6
/8/8 Generl Concept o Finite Dierence Approximtions ( o ) t x, y t x, y t x, y 5 5 5 t x, y t x, y 4 4 4 t x, y 6 6 6 x i i or t xi, y i y t x, y 7 7 7 Suppose we wis to estimte te unction (x) or one o its derivtives t loction (x i,y i ). x i or y i 4 4 5 5 6 6 7 7 It is lwys possible to estimte tis rom liner sum o te unction vlues t surrounding points. Slide 7 Generl Concept o Finite Dierence Approximtions ( o ) Te trick is, ow do we clculte te coeicients n? Tese re unction o te positions o te points. x, y x y x, y,,,, 4, 5, 6, 7 x, y x, y x, y x, y Finite dierence coeicients depend only on te reltive position o te points. Tey do not depend on te bsolute positions. Sme coeicients Dierent coeicients Dierent coeicients Slide 8 4
/8/8 Types o Finite Dierences d x x Forwrd Finite Dierence Reces ed to use dt in te orwrd direction. d x.5 d x x x Centrl Finite Dierence Reces symmetriclly to use dt in bot directions or igest ccurcy. Bckwrd Finite Dierence Reces beind to use dt in te bckwrd direction. Slide 9 Continuum o Finite Dierence Approximtions Slide 5
/8/8 Two Key Considertions. Te position o te points rom wic te inite dierence pproximtion is clculted. More closely spced points improves ccurcy, but typiclly leds to more computtions.. Te loction o te point were te inite dierence is being evluted. We typiclly wnt to be s centered s possible or best ccurcy. Slide Overview o Deriving Finite Dierence Approximtions 6
/8/8 Concept o Using Polynomils We cn it n t order polynomil given + points. x x x x Ater we ve done te curve it, we cn interpolte te unction or ny o its derivtives rom tis polynomil. 4 4 4 4 6 4 6 4 x x x x x x x x x x x x x x x x 4x x Slide Fitting te Polynomil We write our polynomil t ec o our discrete points. Since our t order polynomil contins + coeicients n, we need t lest + discrete points to determine ll o tem. Tis lst point sows tt more points in te pproximtion will give better ccurcy in te inite dierence pproximtion. x xx x x x x x x x x x Slide 4 7
/8/8 Esiest Point or Evluting (x) Recll te equtions we will use to evlute (x) or one o its derivtives: 4 x xx x 4x x xxx 44x x x 6 x x x 4 Tese re most esily evluted t x = becuse te bove equtions reduce to 6 Slide 5 How to Mke Any Point Esy ow suppose we wis to evlute (x) or one o its derivtives t te generl point x = x d. To do tis, we sit our x xis by x d beore itting te polynomil. Recll tt te inite dierence coeicients depend only on te reltive position o te points. An oset will not ect teir vlues. ow we write our polynomil t ec sited point. x x x x x x x x x x x x x x x n n d In our sited coordinte system, our inite dierence is being evluted t x. 6 Slide 6 8
/8/8 Mtrix Form o Curve Fit Given our sited coordinte system, we write te polynomil t ec discrete point nd put tis lrge set o equtions in mtrix orm. 4 x xx x 4x x xxx 44x x x 6x4x x x x x x x x xx xx x x x x x x x x Slide 7 Algoritm or Clculting Finite Dierence Approximtions 8 9
/8/8 Step Coose x Coordintes Identiy te x coordintes o te points rom wic you wis to pproximte derivte. T x x x x 9 Step Sit x Axis Sit te unction cross te x xis until x = corresponds to te point were you wis to pproximte te derivtive. d x x d x x x x x x x x x x T
/8/8 Step Build [X] Mtrix Use te column vector x to build [X]. X x x x x x x x x x x x x x x x x x x x xx Insert s insted o x. Step 4 Invert X Clculte te inverse o X. y y y, y y y, Y X y, y, y,
/8/8 Step 5 Extrct Polynomil Coeicients X Y y y y y, y y y y, y y y y, y, y, y, y, y y y y, y y y y, y y y y, y y y y,,,, Step 6 Write Finite Dierence Approximtion x d x d x y y y y, y y y y, y y y y, y y y y,,,, 4
/8/8 Exmples 5 Exmple # Derive irst order nd second order inite dierence pproximtions tt spn cross tree points. Te pproximtions sould be evluted t te midpoint. x X x x x Y X x d d x d d xd 6
/8/8 Exmple # Derive irst order nd second order inite dierence pproximtions tt spn cross tree points. Te pproximtions sould be evluted t te irst point. x X x x x Y X.5.5 x d d x.5.5 d d xd 7 Exmple # Higer Order Accurcy ( o ) Let s evlute some derivtives t te midpoint o our discrete points. 9 7 4 8 4 8 4 8 9 7 4 8 9 9 6 6 6 6 9 9 4 8 8 4 Y X 4 4 4 4 6 6 x X x x x x 8 4
/8/8 Exmple # Higer Order Accurcy ( o ) Te coeicients re ten 9 9 6 6 6 6 9 9 4 8 8 4 4 4 4 4 4 6 6 Y 9 9 4 x.5 6 d x 7 7.5 4 4x d x.5 4 x 9 9 4 6 6 6 6 9 9 4 4 8 8 4 4 4 4 4 4 6 6 4 9 Clculting Finite Dierence Approximtions Using MATLAB 5
/8/8 Determining Finite Dierence Approximtions wit MATLAB ( o 6) We ve so r derived inite dierence pproximtions symboliclly. Wt i we wnt 6 t order ccurte inite dierences? Tis is unresonble to do symboliclly. Recll our mtrix eqution representing te polynomil written t ec discrete point. It lwys d te ollowing orm were te w s re just constnts. w w w w w w w, w, w, Slide Determining Finite Dierence Approximtions wit MATLAB ( o 6) ow, we re ble to seprte te w terms rom te terms. w w w w w w w, w, w, We were ble to put numbers to ll o tese coeicients. Tis is ully numericl mtrix. It does not contin ny symbolic vribles. Hint: W X wen X Tese re our symbolic vribles. So we build [W] by building nd pretending =. Slide 6
/8/8 Determining Finite Dierence Approximtions wit MATLAB ( o 6) Solving our mtrix eqution or [] gives w w w w w w w, w, w, V v v v v v v v v v, v, v, v, W Slide Determining Finite Dierence Approximtions wit MATLAB (4 o 6) ext we multiply our mtrices. v v v v v v v v v, v, v, v, v v v v v v v v v, v, v, v, Slide 4 7
/8/8 Determining Finite Dierence Approximtions wit MATLAB (5 o 6) ext, we red o te polynomil coeicients. v v v v v v v v v, v, v, v, vv v v v v v, v, v, Slide 5 Determining Finite Dierence Approximtions wit MATLAB (6 o 6) Lst, we write our inite dierence pproximtions rom te polynomil coeicients. vv v d v v v v v v d String t tese equtions long enoug, we relize tt te v ij coeicients cn be determined completely numericlly. We just ve to remember to divide by nd perps multiply te initedierence expression by constnt. Slide 6 8
/8/8 MATLAB Exmples 7 Exmple #4 6 t Order Accurte Finite Dierences ( o ). Here we need seven points to clculte seven polynomil coeicients. x T. To build te [W] mtrix, set = or now. x ˆ T - 9-7 8-4 79-4 -8 6-64 - - - 4 5 6 W x ˆ xˆ xˆ xˆ xˆ xˆ xˆ 4 8 6 64 9 7 8 4 79 Slide 8 9
/8/8 Exmple #4 6 t Order Accurte Finite Dierences ( o ). Invert [W]. VW. -.67.5 -.75 -..75 -.5.67.56 -.75.75 -.6.75 -.75.56.8 -.667.78. -.78.667 -.8 -.69.8 -.78.889 -.78.8 -.69 -.4.67 -.8 -..8 -.67.4.4 -.8.8 -.78.8 -.8.4 4. Write te inite dierence pproximtions, remembering to incorporte te symbolic s bck in. 4 5 6 7.67.5.75 4.75 5.5 6.67 7 x..5.5.7.5.5. x 4 5 6 7 Slide 9