Metode Runge-Kutta Radu T. Trîmbiţaş 8 ianuarie 7 Probleme scalare, pas constant Dorim să aproximăm soluţia problemei Cauchy y (t) = f(t, y), a t b, y(a) = α. pe o grilă uniformă de (N + )-puncte din [a, b]. Dându-se un punct generic x [a, b], y R d, definim un pas al metodei cu un pas prin y next = y + hφ(x, y; h), h >. () La metodele Runge-Kutta se caută Φ de forma: Φ(x, y; h) = r α s K s s= K (x, y) = f(x, ( y) ) s K s (x, y) = f x + µ s h, y + h λ sj K j, s =, 3,..., r j= Este natural să impunem în () condiţiile () s µ s = λ sj, s =, 3,..., r, j= r α s =, (3) s= unde primul set de condiţii este echivalent cu K s (x, y; h) = u (x + µ s h) + O(h ), s,
iar a doua este condiţia de consistenţă (adică Φ(x, y; h) = f(x, y)). Formula Runge-Kutta clasică de ordin p = 4 este: Φ(x, y; h) = (K + K + K 3 + K 4 ) K (x, y; h) = f(x, y) K (x, y; h) = f ( x + h, y + hk ) K 3 (x, y; h) = f ( x + h, y + hk ) K 4 (x, y; h) = f(x + h, y + hk 3 ) (4) Metoda Runge-Kutta clasică de ordinul 4 pentru o grilă de N + puncte echidistante este dată de algoritmul. Algorithm Metoda Runge-Kutta de ordinul 4 Intrare: Funcţia f, capetele a, b ale intervalului; întregul N; valoarea iniţială α. Ieşire: N + abscise t şi aproximantele w ale lui valorilor lui y în t. h := (b a)/n; t := a; w := α; for i := to N do K := hf(t i, w i ); K := hf(t i + h/, w i + K /); K 3 := hf(t i + h/, w i + K /); K 4 := hf(t i + h, w i + K 3 ); w i+ := w i + (K + K + K 3 + K 4 ); t i+ := t i + h; end for Exemplu. Utilizând metoda Runge-Kutta de ordinul 4 pentru a aproxima soluţia problemei Cauchy y = y + t +, t [, ] y() =, cu h =., N = şi t i =.i se obţin rezultatele din tabelul de mai jos
t i Aproximante Valori exacte Eroarea...48375.4837484 8.94e-8..87394.8737538.4838e-7.3.4884.4888.39e-7.4.73889.7344.488e-7.5.539344.53597.747e-7..48893438.48839.988e-7.7.958587.95853379 3.488e-7.8.49398973.493894 3.57e-7.9.35999.3595974 3.3459e-7..378797744.37879447 3.334e-7 Se obişnuieşte să se asocieze unei metode Runge-Kutta cu r stadii () tabloul µ λ λ... λ r µ λ λ... λ r....... (în formă matricială µ ΛαT ) µ r λ r λ r... λ rr α α... α r numit tabelă Butcher. Pentru metoda Runge-Kutta clasică de ordinul patru (4) tabela Butcher este:. Probleme. Implementaţi metoda Runge-Kutta de ordinul 4. 3
. Testaţi rutina dumneavoastră pe exemple ale căror soluţii pot fi exprimate prin cuadraturi şi reprezentaţi pe acelaşi grafic soluţia exactă. 3. Implementaţi următoarele metode: Euler, Euler modificată, Heun.. Probleme practice Rezolvaţi problemele următoare. Comparaţi soluţia aproximativă cu cea exactă:. y = x y, x [, 4], y() =.. Soluţia exactă y(x) = x x + e x. y = y + x ; y() = π 4. 3. y = + x y ; y() =. Soluţia exactă: y = x + x. 4. y = y, x [, 5] y() =. Soluţia exactă: y(x) = /( + x). 4
5. y = y + cos x, x [, π] y() =. Soluţia exactă: y(x) = cos x + sin x. Sisteme de ecuaţii diferenţiale ordinare şi ecuaţii de ordin superior Rezolvaţi următoarele EDO şi sisteme de EDO. Comparaţi soluţia exactă şi cea aproximativă. Găsiţi soluţiile şi cu rezolvitori MATLAB... 3. u = 3u + u, t [, ], u () = u = 4u + u, t [, ], u () =. h =., soluţia exactă u (t) = 3 (e5t e t ), u (t) = 3 (e5t + e t ). h =., soluţia exactă h =., soluţia exactă u = 4u u + cos t + 4 sin t, u () =, u = 3u + u 3 sin t, u () =, t [, ] u (t) = e t e t + sin t, u (t) = 3e t + e t. u = u, u () = 3, u = u + e t +, u () =, u 3 = u + e t +, u 3 () =, t [, ]. u (t) = cos t + sin t +, u (t) = sin t + cos t e t, u 3 (t) = sin t + cos t. 5
4. t y ty + y = t 3 ln t, t [, ] y() =, y () =, h =.5, soluţia exactă y(t) = 7 4 t + t3 ln t 3 4 t3. 5. h =.5; soluţia exactă y = y 4, t [,.9] 3 Controlul pasului y() =, y () =, y () =, y(t) = t. Pentru o descriere sintetică a metodelor Runge-Kutta cu pas variabil tabela Butcher se completează cu o linie suplimentară care serveşte la calculul lui Φ (şi deci a lui r(x, y; h)): µ λ λ... λ r µ λ λ... λ r....... µ r λ r λ r... λ rr α α... α r α α αr αr+ Ca exemplu, tabela este tabela Butcher pentru metoda Bogacki-Shampine. Ea stă la baza rezolvitorului ode3 din Matlab. Un alt exemplu important este DORPRI5 sau RK5(4)7FM, o pereche cu ordinele 4-5 şi cu 7 stadii (tabela ). Aceasta este o pereche foarte eficientă, ea stând la baza rezolvitorului ode45 din Matlab, dar şi a altor rezolvitori importanţi. Algoritmul încearcă să dea sugestii pentru implementarea unei metode Runge-Kutta cu pas variabil când se cunoaşte tabela Butcher. ttol este produsul dintre tol şi factorul de siguranţă (.8 sau.9).
µ j λ ij 3 3 4 4 3 4 9 9 9 3 4 α i 9 9 9 α i 7 4 Tabela : Tabela Butcher pentru metoda Bogacki-Shampine 4 3 8 µ j λ ij 5 5 4 44 5 3 5 45 5 9 8 937 53 4448 9 5 87 5 79 97 355 473 49 53 38 33 547 7 85 35 5 5 87 384 3 9 784 84 35 5 5 α i 87 384 3 9 784 84 α 579 757 393 i 997 87 57 95 4 339 4 3 3 9 4 4 Tabela : Perechea inclusă RK5(4)7FM (DORPRI5) 7
Algorithm Fragment de pseudocod ce ilustrează implementarea unei metode RK cu pas variabil done := false; loop K :, := f(x, y); for i = to s do w := y + hk :,:i λ T i,:i ; K :,i := f(x + µ i h, w); end for δ := h max ( K(α α) T ) ; {estimarea erorii} β := (δ/ttol) /(+p) ; {raport lung. pas} if δ < tol then {acceptare pas} y := y + h(kα T ); {actualizare y} x := x + h; if done then EXIT {terminare şi ieşire} end if h := h/ max(β,.); {predicţie pas următor} if x + h > x end then h := x end x; {reducere pas la capăt} done := true; end if else {respingere pas} h := h/ min(β, ); {reducere pas} if done then done := false; end if end if end loop 8
3. Probleme. Implementaţi un mecanism de control al pasului pentru una din metodele descrise de tabelele Butcher precedente.. Testaţi rutina precedentă pentru o EDO scalară, un sistem şi o EDO de ordin superior. 9