chapter 6 numerical methods
play

Chapter 6: Numerical Methods 6.1 Euler Method Basic Idea y ODE: y - PowerPoint PPT Presentation

Chapter 6: Numerical Methods 6.1 Euler Method Basic Idea y ODE: y = f ( t, y ) y(t+h) truncation Assume y ( t ) is known error y ap (t+h) For small h approximate tangent line y ( t + h ) y ( t ) y(t) y ( t ) h


  1. Chapter 6: Numerical Methods 6.1 Euler Method Basic Idea y • ODE: y ′ = f ( t, y ) y(t+h) truncation • Assume y ( t ) is known error y ap (t+h) • For small h approximate tangent line y ( t + h ) − y ( t ) y(t) y ′ ( t ) ≈ h h t = f ( t, y ( t )) t t+h Iteration Scheme y ( t + h ) ≈ y ap ( t + h ) ⇒ IVP: y ′ = f ( t, y ), y ( t 0 ) = y 0 where Approximate y ( t k ) ≈ y k at t k : y 1 = y 0 + h f ( t 0 , y 0 ) , t 1 = t 0 + h y ap ( t + h ) = y ( t ) + h f ( t, y ( t )) y 2 = y 1 + h f ( t 1 , y 1 ) , t 2 = t 1 + h . • Truncation Error: . . y k +1 = y k + h f ( t k , y k ) | y ( t + h ) − y ap ( t + h ) | = t k + h t k +1 1

  2. 3 Euler approximation Ex: Approximate the solution to for y’=y, y(0)=1 y ′ = y, y (0) = 1 2.5 exact in 0 ≤ t ≤ 1. Start: t 0 = 0, y 0 = 1 h=.25 y 2 h = 1 h=1 1.5 h=.5 y 1 = y 0 + h f (0 , 1) = 1 + 1 · 1 = 2 t 1 = t 0 + h = 0 + 1 = 1 1 0 0.2 0.4 0.6 0.8 1 t h = 0 . 5 y 1 = 1 + 0 . 5 · 1 = 1 . 5 Ex: Approximate the solution to t 1 = 0 + 0 . 5 = 0 . 5 y ′ = t − y, y (0) = 0 . 5 = 1 . 5 + 0 . 5 · 1 . 5 = 2 . 25 y 2 t 2 = 0 . 5 + 0 . 5 = 1 in 0 ≤ t ≤ 1 using h = 0 . 25 Start: y 0 = 0 . 5, t 0 = 0 h = 0 . 25 y 1 = 0 . 5 + 0 . 25 · (0 − 0 . 5) = 0 . 375 y 1 = 1 + 0 . 25 · 1 = 1 . 25 t 1 = 0 + 0 . 25 = 0 . 25 t 1 = 0 + 0 . 25 = 0 . 25 y 2 = 0 . 375 + 0 . 25 · (0 . 25 − 0 . 375) = 1 . 25 + 0 . 25 · 1 . 25 = 1 . 5625 y 2 = 0 . 3438 t 2 = 0 . 25 + 0 . 25 = 0 . 5 t 2 = 0 . 25 + 0 . 25 = 0 . 5 y 3 = 1 . 5625 + 0 . 25 · 1 . 5625 y 3 = 0 . 3438 + 0 . 25 · (0 . 5 − 0 . 3438) = 1 . 953125 = 0 . 3828 = 0 . 5 + 0 . 25 = 0 . 75 t 3 t 3 = 0 . 5 + 0 . 25 = 0 . 75 y 4 = 1 . 953125 + 0 . 25 · 1 . 953125 = 0 . 3828 + 0 . 25 · (0 . 75 − 0 . 3828) y 4 = 2 . 44140625 = 0 . 4746 t 4 = 0 . 75 + 0 . 25 = 1 2 t 4 = 0 . 75 + 0 . 25 = 1

  3. Ex.: y ′ = t − y, y (0) = . 5 Errors Approximate y (1) for stepsizes Three error sources: h = 1 /m, m = 1 , 2 , 4 , 8 , 16 , 32 • Truncation error at each Exact Value: y (1) = 0 . 5518 Euler step Error: E ( h ) = | y (1) − y m | • Propagated (accumulated) h y m E ( h ) truncation error 1 0 0 . 5518 1 / 2 0 . 375 0 . 1768 • Roundo ff error 1 / 4 0 . 4746 0 . 0772 (not controlable) 1 / 8 0 . 5154 0 . 0364 1 / 16 0 . 5341 0 . 0177 exact solution 1 / 32 0 . 5431 0 . 0087 y solution for y(t 0 +h)=y 1 E ( h/ 2) ≈ E ( h ) / 2 ⇒ E ( h ) ≈ C h TE: truncation error PTE: propagated PTE truncation error TE y 2 Theorem: There ∃ C > 0 s.t. y 1 E ( h ) ≤ C h y 0 h h (Euler method is first order t t 0 t 0 +h t 0 +2h method) 3

  4. Worked out Examples from Exercises Ex. 1: y ′ = ty , y (0) = 1. Compute five Euler-iterates for h = 0 . 1. Arrange computation and results in a table. k t k y k f ( t k , y k ) = t k y k h f ( t k , z k ) h 0 0 1 0 0 . 1 0 1 0 . 1 1 0 . 1000 0 . 1 0 . 0100 2 0 . 2 1 . 0100 0 . 2020 0 . 1 0 . 0202 3 0 . 3 1 . 0302 0 . 3091 0 . 1 0 . 0309 4 0 . 4 1 . 0611 0 . 4244 0 . 1 0 . 0424 5 0 . 5 1 . 1036 0 . 5518 0 . 1 0 . 0552 4

  5. Ex. 7: y ′ + 2 xy = x , y (0) = 8 (i) Compute Euler-approximations in 0 ≤ x ≤ 1 for h = 0 . 2, h = 0 . 1, h = 0 . 05. (ii) Find exact solution (iii) Plot exact solution as curve and Euler approximations as points. �� x (i) In Matlab, Euler approximation � = e − x 2 y h ( x ) = exp ( − 2 x ) dx for h = 0 . 2 is computed and stored 0 in arrays x0 2 , y0 2 via � x � � h=0.2; y ( x ) = y h ( x ) 8 + [ f ( ξ ) /y h ( ξ )] d ξ m=1/h;x=0;y=8; 0 8 e − x 2 + e − x 2 � x xv=x;yv=y; ξ e ξ 2 d ξ = for k=1:m 0 8 e − x 2 + e − x 2 ( e x 2 − 1) / 2 f=-2*x*y+x; = (15 / 2) e − x 2 + 1 / 2 y=y+h*f;yv=[yv y]; = x=x+h;xv=[xv x]; end (iii) Matlab plot commands: x0_2=xv;y0_2=yv; x=linspace(0,1,100); Analogously for h = 0 . 1 and h = 0 . 05 y=1/2+15/2*exp(-x.^2); (arrays x0 1 , y0 1 and x0 05 , y0 05 ). plot(x0_2,y0_2,’ko’,x0_1,y0_1,’k*’,... x0_05,y0_05,’k+’,x,y,’k’), (ii) Variation of Parameter: xlabel(’x’),ylabel(’y’) y ′ h = − 2 xy ⇒ axis([0 1 3.5 8]) 5

  6. Plot for Ex. 7 8 7 6 y 5 4 0 0.2 0.4 0.6 0.8 1 x 6

Recommend


More recommend