Numercal Methods 數 值 方 法 概 說 Danel Lee Nov. 1, 2006
Outlnes Lnear system : drect, teratve Nonlnear system : Newton-lke Interpolatons : polys, splnes, trg polys Approxmatons (I) : orthogonal polys Approxmatons (II) : specal func Numercal quadratures : Smpson s, Gaussan Numercal ODE (IVP) : RK, PC Numercal ODE (BVP) : shootng, FD, MOL Numercal ODE (BVP) : collocaton, spectral Numercal PDE (IBVP) : selected topcs
Course Foc 1/3 Lnear system (I) : GE, Trd, GS_SOR Lnear system (II) : CG, BCGstab, GMRes Nonlnear sys (I) : secant_1d, damped Newton Nonlnear sys (II) : Broyden s, Inexact Newton Interpolatons (I) : polynomals, splnes Interpolatons (II) : trg_polys Approxmatons (I) : orthogonal polynomals, L2 theory Approxmatons (II) : Chebyshev polys, mnmax theory Approxmatons (III) : specal functons, Bessel s, Numercal ntegraton : Smpson s, Gaussan quadrature
Course Foc 2/3 Numercal ODE, IVP : rkf45, N-dm Numercal ODE, IVP : PC, predct-correct Numercal ODE, BVP : MOL, 1D/2D Numercal ODE, TPBVP : FD Numercal ODE, TPBVP : Collocaton/splne Numercal ODE, TPBVP : Collocaton/Tchebyshev Numercal ODE, TPBVP : Spectral/Tchebyshev Numercal ODE, TPBVP : Spectral/Bessel Numercal ODE, TPBVP : Shoottng
Course Foc 3/3 Posson 3D Heat 2D Wave 2D Incompressble NS 2D
Lnear (Algebrac) System Matrx types : dense or sparse Methods : drect or teratve
Gaussan Elmnaton wthout Pvotng A 4-by-4 example (on page 264) Phase 1 : forward elmnatons Phase 2 : back substtutons 6x1 2x2 + 2x3 + 4x4 = 16 12x1 8x2 + 6x3 + 10x4 = 26 3x1 13x2 + 9x3 + 3x4 = 19 6x1 + 4x2 + x3 18x4 = 34
Forward Elmnatons (1) 6x1 2x2 + 2x3 + 4x4 = 16 12x1 8x2 + 6x3 + 10x4 = 26 3x1 13x2 + 9x3 + 3x4 = 19 6x1 + 4x2 + x3 18x4 = 34 6x1 2x2 + 2x3 + 4x4 = 16 x1 4x2 + 2x3 + 2x4 = 6 12x2 + 8x3 + x4 = 27 2x2 + 3x3 14x4 = 18
Forward Elmnatons (2) 6x1 2x2 + 2x3 + 4x4 = 16 x1 4x2 + 2x3 + 2x4 = 6 12x2 + 8x3 + x4 = 27 2x2 + 3x3 14x4 = 18 6x1 2x2 + 2x3 + 4x4 = 16 4x2 + 2x3 + 2x4 = 6 2x3 5x4 = 9 4x3 13x4 = 21
Forward Elmnatons (3) 6x1 2x2 + 2x3 + 4x4 = 16 4x2 + 2x3 + 2x4 = 6 2x3 5x4 = 9 4x3 13x4 = 21 6x1 2x2 + 2x3 + 4x4 = 16 4x2 + 2x3 + 2x4 = 6 2x3 5x4 = 9 3x4 = 3
Back Substtutons 6x1 2x2 + 2x3 + 4x4 = 16 4x2 + 2x3 + 2x4 = 6 2x3 5x4 = 9 3x4 = 3? x = 1 3 x = 2 1 x 2 3 = x = 4 1
GE --- Key Ponts An upper trangular matrx s easy to solve Elementary row operatons on a matrx GE as a seq of matrx left-multplcatons
GE --- Notatons and Termnologes Gaussan Elmnaton ( GE ) Upper trangular matrx Pvot element, pvot equaton Multplers Resdual vector r = Ax b Error vector e = x_sol x_computed Condton Num cond(a)= A A_nv No/partal/complete pvotng
GE --- More Thoughts Q1: Upper Trangular vs. Lower Trangular? Q2: Elementary column operatons?
GE --- wth Partal Pvotng Choose the pvot elements ( and eqs ) Interchange rows accordngly Compute multplers and do elmnatons Back substtutons as before In practce, store pvots and multplers Amng at lots of RHS and same matrx Routnes : LU_Decomp(), LU_Solve()
GE --- HW Functon ludecomp( ), page 285 Functon lusolve( ), page 287 Man : test
Nonlnear Solve--- Hghlghts 1D zero fnder N-dm Newton s method : Bascs Practcal N-dm Newton s method Two-pont Newton Methods Inexact Newton method Broyden s method
1-dm Zero Fnders Bsecton method Newton s method, quadratc convergence Secant method, superlnear convergence Other methods More readng assgnment
N-dm Newton Basc Issues (Crtcal) ntal start Expensve Jacoban evaluaton Approxmate Jacoban needed n practce Effcent lnear solve
Practcal N-dm Newton Modfed newton Damped newton Two-grd newton Inexact newton
Interpolaton --- Hghlghts Algebrac polynomal nterpolaton Cubc splne nterpolaton Trgonometrc polynomal nterpolaton
Polynomal Interpolatons Problem formulaton Lagrange bass functon approach Newton s recursve approach Ptfall of unform nodes : The Runge func Dvded dfference : general knots Newton s approach va dvded dfference Interpolaton at Chebyshev nodes
Splne Interpolatons (General) splnes as pecewse polynomals (Smooth) Cubc splnes Count of defnng coeffcents Count of constrants The degree-of-freedom Varous boundary condtons Matrx forms Convergence and stablty
Trg-polynomal Interpolatons Even/odd degree A trgonometrc dentty The bass functon
Approxmatons --- Hghlghts Orthogonal polynomals : weghted - 2 Chebyshev polynomals : L - theory (Non-poly) Specal Functons : Bessel s L
Orthogonal Polynomals Fnte/sem-nfnte/nfnte ntervals Weghted Remann ntegrals Weghted L 2 - norms Polynomals as subspace Gram-Schmdt orthogonalzaton Typcal examples
Chebyshev Polynomals T ( x) = cos( nθ ), wth x = cos n A few examples : explct forms A few examples : the graphs Three-term recurson Extremes and zeros θ T, T, L, T 1 2 8 More recursve relatons The mn-max characterzaton Varous applcatons n numercal analyss
Numercal Integratons 1/2 Remann ntegrals : as upper/lower lmts One-pont quadrature : md-pont rule Two-pont quadrature : trapezod rule Three-pont quadrature: Smpson s rule (Composte) Smpson s rule General Newton-Cotes formulae Gaussan type : nodes and weghts Software resources : Quadpack/netlb
Md-pont rule b a n 1 1 ( ) ( ) ( + ) + 1 + 1 2 = 0 f x dx x x f x x Trapezod rule b a n 1 1 f ( x) dx ( x + 1 x ) f ( x ) + f ( x + 1) 2 = 0 [ ]
(Composte) Smpson s Rule b a n / 2 h f ( x) dx f ( a) + f ( b) + 4 f a + (2 1) h 3 = 1 Gaussan type : [ ] [ ] ( n 2)/ 2 + 2 f ( a + 2 h) = 1 b f x dx A f x + A f x + A f x a 0 0 1 1 L + n n ( ) ( ) ( ) ( ) nodes weghts x, x, L, x 0 1 n A, A, L, A 0 1 n
Numercal Integratons 2/2 Runge-Kutta approach Lower order RK methods : RK2 RK3 method : Varous RK4 methods : RK5, RK6, RK7, RK8 : Acceleraton : halvng and combnng rkf45, rk56 : Software resources : rksute/netlb
RK2 where x( t + h) = x( t) + ( K + K ) 1 2 1 2 K = hf ( t, x) 1 K = hf ( t + h, x + K ) 2 1
RK3 x( t + h) = x( t) + (2K + 3K + 4 K ) 1 9 1 2 3 where K1 = hf ( t, x) 1 1 K2 = hf ( t + h, x + K 2 2 1) 3 3 K3 = hf ( t + h, x + K 4 4 2)
RK4 x( t + h) = x( t) + ( K + 2K + 2 K + K ) 1 6 1 2 3 4 where K1 = hf ( t, x) 1 1 K2 = hf ( t + h, x + K 2 2 1) 1 1 K3 = hf ( t + h, x + K 2 2 2) K4 = hf ( t + h, x + K3)
RK5 x( t + h) = x( t) + K + K + K K 25 1408 2197 1 216 1 2565 3 4104 4 5 5 where K1 = hf ( t, x) 1 1 K2 = hf ( t + h, x + K 4 4 1) 3 3 9 K3 = hf ( t + h, x + K 8 32 1 + K 32 2) 12 1932 7200 7296 K4 = hf ( t + h, x + K 13 2197 1 K 2197 2 + K 2197 3) 439 3680 845 K5 = hf ( t + h, x + K 216 1 8 K2 + K 513 3 K 4104 4)
Numercal ODE --- Hghlghts Types : IVP, BVP Doman geometry : regular or not, 1D/2D/ Numercal methods : mostly sem-mplct Dfferencng : explct, mplct, 3-level Spatal dfferences : FD, FV (cell-centered) Other methods for BVP : MOL, Collocaton Package approach : rksute, odepack, DAE :
Numercal BVP-FD 1st dervatve, 2-pont 1st order dfference 1st dervatve, 2-pont 2nd order central 2nd dervatve, 3-pont 2nd order central 2nd dervatve, 3-pont one-sded 1st order Combnaton of two lower order schemes 2D Cartesan type fve-pont stencls General geometry
Numercal BVP-FV Dvergence theorem and conservaton law Concept of fnte volumes Center/Vertex/Edge based FV methods Boundary-ftted or not Combnatons of dfferent types of FV Relatons to FD and FEM
Numercal BVP-MOL Sem-mplct dscretzaton Contnuous n tme, dscrete n spatal var Results n system of ODE/IVP Good IVP package/solver/routne expected Easy 1D for learnng May not be effcent for 3D applcatons
Numercal BVP-Collocaton The Fourer case Chebyshev polys and seres Bessel functons and seres Legendre polys and seres Model examples
Fnte Dfference for PDE Implct tme dfferencng u ( n+ 1) ( n) u x ( 1), j u x n+, j t ( x, j ) ( ) ( ) t Explct/Implct spatal dfferencng ( α = n, n + 1) u α α u x ( n 1) + 1, j u x + 1, j x ( x, j ) ( ) ( ) 2 x
FD --- Unform Cartesan Grd y y y + 1 1 2h y y 2y + y + 1 1 2 2h
FV --- General Geometry y p = Ap y p + Aw yw + Ae ye + As ys + An yn conservaton law plus Dvergence Theorem
Numercal BVP MOL (1) D.E. ut = uxx, 0 x 1, t 0 I.C. B.C. t = 0, u( x,0) = f ( x) x = 0,1, u(0, t) = u ( t), u(1, t) = u ( t) 0 n+ 1 Model : (contnuous n t, dscrete n x) Spatal Dscretzaton : 0 = x0 < x1 < L < x < Lxn < x n + 1 = 1 u( x, t) u ( t)
MOL (2) Dscrete System : = 1,2, L, n u ( t) = u ( t), u ( t) 0 n+ 1 u+ 1( t) u 1( t) 2 x : gven Problem : Solve system of IVP n t
FD -Frst Dervatve Approxmatons y x y( x ) y( x ) + 1 ( ) x+ 1 x y( x ) y( x 1) y ( x ) x x 1 y( x + 1) y( x 1) y ( x ) x x + 1 1
FD - 2nd Dervatve Approxmatons y 2y + y y ( x ) = h y, y, y + 2 + 1 y, y, y 1 2 + 1 1 2
Dervaton of Central Dfference of y h h h y y hy y y y 2 6 24 2 3 4 (4) + 1 = + + + + h h h y y hy y y y 2 6 24 2 3 4 (4) 1 = + + 3 h 5 y+ 1 y 1 = 2 hy + y + O( h ) 3 2 y+ 1 y 1 h 4 y = + y + O( h ) 2h 6
Dervaton of Central Dfference of y h h h y y hy y y y 2 6 24 2 3 4 (4) + 1 = + + + + h h h y y hy y y y 2 6 24 2 3 4 (4) 1 = + + 2 y+ 1 2y + y 1 h (4) 4 y + y ( ) 2 + O h h 12
One-sded Dfference for y 2 3 h h ''' y+ 1 = y + hy + y + y 2 6 2 3 4h 8h y + 2 = y + 2hy + y + y 2 6 ''' 4h y y y hy y 6 3 ''' + 2 4 + 1 + 3 = 2 + 1 3 y + 2y y 2 2 h + 2 + 1 1 2 = y h y 3
One-sded Dfference for y h h y y hy y y 2 6 2 3 ''' + 1 = + + + 4h 8h y y hy y y 2 6 2 3 ''' + 2 = + 2 + + 2h 6h y y y y y 2 6 2 3 ''' + 2 2 + 1 + = + y 2y + y + 2 + 1 2 h = y + hy
Combnng Two FD Schemes 2 y+ 1 2y + y 1 h (4) 4 y + y ( ) 2 + O h h 12 2 y+ 2 2y + y 2 4h (4) 4 y + y ( ) 2 + O h 4h 12 y 16y + 30y 16y + y + 4h + 2 + 1 1 2 4 3 y O( h ) 2
Two-dmensonal FD Applcatons u j j ( u ) x ( u ) u y xx = u( x, y ) j j + u yy u u u + 1, j 1, j 2h, j+ 1, j 1 2h x u y u + u + u + u 4u + 1, j 1, j, j+ 1, j 1 j 4
數 值 習 題 自 習 手 冊 李 天 佑 東 海 大 學 數 學 系 Nov. 1, 2006
線 性 系 統 Q1 : 何 謂 二 階 段 陽 春 高 斯 消 去 法? Q2 : 陽 春 型 前 進 消 去 階 段 之 可 能 障 礙 為 何? 解 決 方 法 為 何? Q3 : 前 述 階 段 是 否 必 定 成 功? Q4 : 消 去 階 段 結 束, 該 矩 陣 主 對 角 元 素 乘 積 之 理 論 意 義 為 何? Q5 : 前 述 判 斷 之 風 險 為 何? Q6 : 後 退 代 入 階 段 之 理 想 假 設 為 何? Q7 : 試 述 部 分 列 篩 選 型 高 斯 消 去 法 Q8 : 詳 述 高 斯 消 去 法 之 LU 分 解 理 論 Q9 : 當 高 斯 ( 消 去 ) 遇 見 對 稱 ( 矩 陣 ),, 請 補 實 續 完 Q10 : 重 新 開 始, 如 選 擇 第 n 個 方 程 式 與 第 n 個 變 數, 消 去 其 餘 方 程 之, 再 利 用 第 n-1 個 方 程 式 之 此 類 推, 是 為 後 退 消 去 階 段, 變 數, 消 去 其 餘 方 程 () 之 變 數 係 數, 以 所 得 矩 陣 有 何 特 徵? 本 階 段 有 何 風 險? 如 何 解 決? Q11 : ( 續 前 ) 繼 以 前 進 代 入, 總 結 為 UL 型 高 斯 消 去 法 程 式 習 作 : P1 : 設 計 並 測 試 副 程 式 ludecomp( ), lusolve( )
多 項 式 插 值 法 Q1 : 何 謂 多 項 式 插 值 問 題? Q2 : 相 關 之 Lagrange 基 底 函 數 為 何? Q3 : 為 何 b-orthogonalty 意 謂 線 性 獨 立? Q4 : 試 以 Lagrange 基 底 表 示 內 插 解 Q5 : 牛 頓 之 遞 迴 建 構 法 為 何? Q6 : 試 詳 述 ( 高 階 ) 差 分? Q7 : 內 插 解 之 差 分 形 式 為 何? 程 式 習 作 : P1 : Lagrange 形 式 插 值 解 之 簡 易 測 試 P2 : 牛 頓 差 分 型 插 值 解 之 軟 體 設 計
三 角 多 項 式 插 值 法 Q1 : 何 謂 三 角 多 項 式 插 值 問 題? Q2 : 相 關 之 基 底 函 數 為 何? 程 式 習 作 : P1 : 軟 體 設 計 與 測 試
三 次 樣 條 函 數 內 插 法 Q1 : 何 謂 片 段 多 項 式? Q2 : 何 謂 樣 條 函 數? Q3 : 何 謂 三 次 樣 條 插 值 問 題? Q4 : 節 點 與 結 點 差 異 為 何? Q5 : 樣 條 插 值 一 般 是 否 有 解? Q6 : 可 能 之 邊 界 條 件 為 何? Q7 : 實 用 性 之 考 量 因 素 為 何? 程 式 習 作 : P1 : 設 計 副 程 式 splne3_coef(), splne3_evalu8() 與 測 試 用 之 主 程 式
數 值 積 分 Q1 : 何 謂 中 點 法, 梯 形 法, 與 辛 普 森 法? Q2 : 試 述 Newton-Cotes 之 想 法? Q3 : 高 斯 積 分 公 式 之 想 法 為 何? Q4 : 試 比 較 前 述 二 種 構 想 Q5 : 調 適 型 辛 普 森 法 之 想 法 為 何? 程 式 習 作 : P1 : 設 計 辛 普 森 法 副 程 式 與 測 試 用 之 主 程 式 P2 : 針 對 次 數 為 4, 6, 8 之 高 斯 積 分 公 式, 設 計 副 程 式 與 測 試 用 之 主 程 式
Lnear System Readng assgnment : norms, analyss, prob Q1 : work out by hands an example va QL P1 : routne and test trd_dag (n,a_vec,b_vec,c_vec,x_vec,rhs_vec) P2 : lu_decomp( ), lu_solve( ) and test P3 : gs_sor( ) and test P4 : cg() and test
Newton s Method 1/2 How s Newton s method related to Taylor expanson? How s the newton step mplemented n practce? Descrbe reasonable stoppng crteron(s) How s Newton s method related to functonal teratons? Can accelerated Newton s method accelerate? Does damped newton s method damp somethng?
Newton s method 2/2 Desgn approxmate Jacoban n varous ways. What can a two-grd setup help Newton s method n one way or the other? Desgn a modfed Newton s method at a double root.of a two-by-two system
Interpolatons --- polynomals Readng assgnment : Q1 : What s a polynomal nterpolaton problem? Q2 : What are the Lagrange bass functons? Q3 : Why b-orthogonalty mples ndependence? Q4 : Express the nterpolant n terms of Lagrange bass. Q5 : What s the recursve constructon of Newton s? Q6 : Descrbe dvded dfferences n detals? Q7 : Express the nterpolant n terms of dvded dfferences. P1 : Smple test of Lagrange form. P2 : Work out the nterpolant n newton s form
Interpolatons --- Trg polys Odd and/or even degree. Some trg denttes. The bass functons. P1 : Desgn the routne(s) and test.
Interpolatons --- Cubc splnes What s a pecewse polynomal functon? What s a (polynomal) splne functon? What s a cubc splne nterpolaton problem? Dfferences bewteen nodes and knots? What s a rule of thurm for solvablty? Some possble boundary condtons? Practcal ssues and dscussons. P1 : routnes splne3_coef(), splne3_evalu8(), test
Numercal Quadratures Descrbe mdpont rule, trapezod s, and smpson s What s the dea of Newton-Cotes? Why s the Newton-Cotes restrctve, compared to Gaussan quadrature? What s the dea behnd adaptve smpson s? P1 : smpson s and test P2 : gaussan quadrature of degree 4, 6, 8.
Numercal ODE --- IVP P1 : rk4 of general dm, and test. Predctor-Corrector method : low order case Exercse on usng rkf45 : fnd cycle problem from your ODE text.
Numercal ODE --- BVP P0 : Implement the Shootng method for 1D P1 : Implement the FD method for 1D/2D P2 : Implement the MOL method for 1D/2D P3 : Implement Collocaton va cubc splne