ter Nuercal DE Algorts Aprl 8 0 ter Algorts or rdar Deretal Equatos Larr aretto Mecacal Egeerg 09 Nuercal Aalss o Egeerg Sstes Aprl 8 0 utle Scedule Revew sstes o DEs Sprg-ass-daper proble wt two asses as eaple Usg DE solvers MATLAB ter approaces or solvg te tal value proble Multstep etods Iplct etods Etrapolato etods Reag ourse Scedule Aprl 8 toda More o DEs; prograg assget s due Aprl 0 Last quz o DEs. Fal lecture o uercal solutos o DEs Ma 5 Revew or al ad prograg eas; prograg assget seve due Ma 7 Prograg ea Ma Fal ea 8 0 p Revew Sstes o DEs a covert t order DE to rstorder DEs a appl algorts or oe rst-order DE to sstes o rst-order DEs Must ave tal coos o all varables overtg a t order DE to rst-order DEs gves dervatve DEs wose tal values we eed Must appl eac step o algorts to all DEs beore gog o to et step Eaple Two asses joed b a sprg/daper rgal DEs or eac ass Dee veloctes Rewrte orgal DEs usg veloctes d d d c F d d d c F d v d v dv c F v v dv c F v v = sprg costat N/ c = dapg coecet g/s 5 Eaple otued Replace v v equatos below b d v dv c v v d v dv c v v d d F F Result s stadard-or sste: d / = d F c d F c 6 ME 09 Nuercal Aalss o Egeerg Sstes
ter Nuercal DE Algorts Aprl 8 0 MATLAB Dervatve Fucto ucto = sprgmassdapert =; =; c = 0.5; = ; = zeros; = ; = ; = c*-+*-/; = c*-+*-/; Ed >>[t ] = ode5@sprgmassdaper [0 ] [ - 0 0] 7 Geeral Sste For Have N DEs wt coo or: Eac a deped o t ad all Equatos or ters o t ad all values deped o proble descrpto Appl usual algorts + = + avg to eac equato: + = + avg s value o at t = t or = Must do eac step/substep to all equatos beore tag et step/substep t - t - t t + t + t + d 8 How to ode Ts For a algort eac step ust be doe or all equatos All equatos ave te or d / = User-deed ucto = Subt coputes all values or put t Eac step eac algort s a loop over all equatos gettg approprate updates Fourt-order Ruge Kutta RK Uses our dervatve evaluatos per step t t 6 t Loo at code or t ts algort te see cages t to appl to a sste o equatos t oo te value or all to copute t - t - t t + t + t + 9 0 RK ode oe DE = ted - tstart/steps t = depedet varable at start o step = t For step = To Steps t = tstart + * step - = Fctt tal values = * Use Applcato.Ru Fct t VBA = Fctt + / + / = * = Fctt + / + / = * = Fctt + + = + + * + * + * / 6 Net step Use sae progra varable or + ad RK or N DEs s s value o t varable at t t 6 t t t t t - t - t t + t + t + t Vector otato or ad sows tat ca deped o all values ad eac calculato requres all values to be updated ME 09 Nuercal Aalss o Egeerg Sstes
ter Nuercal DE Algorts Aprl 8 0 RK ode Multple DEs = Ed - Start / Steps For step = To Steps = Start + * step - = Fct tal values For = To N Use Applcato. Ru Fct t VBA = * Tep = + 0.5 * Net = Fct + / Tep For = To N = * Tep = + 0.5 * Eaple: t -order Ruge-Kutta all Fct + / Tep For = To N = * Tep = + 0.5 * Net = Fct + / Tep For = To N = * Tep = + Net = Fct + Tep Eaple: t -order Ruge-Kutta Use sae progra varable or + ad = Fct + Tep For = To N Net Net step = * = + + * _ + * + * / 6 Tese ew values are used at start o loop to beg et step Sae stateets adle ucto put values or 5 DE Solvers MATLAB Several deret solvers For tal value probles te geeral ucto call s [t ] = solvernae dervatvef tspa 0 optos were t s a colu vector o te pots output b te calculato s te output atr or te soluto olu o s te soluto or varable Eac row o s te soluto o all or te te pot te sae row o t 6 DE Solvers MATLAB II dervatvef s te adle or a ucto tat evaluates te dervatves t I dervatveft t s a scalar te ad s a colu vector o te depedet varables Te ucto returs a colu vector or Te user as to wrte ts ucto to dee te proble beg solved Te tspa arguet s a row atr tat ust gve at least te tal ad al te MATLAB uses te s as te ae o te depedet varable wc ca be a quatt 7 DE Solvers MATLAB III I tere are ol te u o two pots start ad ed solvers wll gve output or eac te depedet varable used calculato Voluous output good or soot plots I tree or ore pots are used put ol tese put tes wll appear output Te 0 arguet s a vector or tal coos o te depedet varables Y0 = [ 5 -] gves 0 = 0 = 5 Te optos arguet allows te user to overrde oral deaults te solver See MATLAB elp or ore optos orato 8 ME 09 Nuercal Aalss o Egeerg Sstes
ter Nuercal DE Algorts Aprl 8 0 DE Solvers MATLAB Solver aes: ode5 ode ode ode5s odes odet odetb ode5 sould be rst coce Ts s a Ruge-Kutta procedure tat uses a ourt ad t order epressos called te Dorad-Prce par to adjust step sze ode s a ultstep algort based o te Adas-Basort-Moulto approac Applcato orato or solvers ro MATLAB elp o et slde 9 Solver MATLAB Solver Help Proble Tpe rder o Accurac We to Use ode5 Nost Medu Most o te te. Ts sould be te rst solver ou tr ode Nost Low Probles wt crude error toleraces or or solvg oderatel st probles ode Nost Low to g ode5s St Low to edu Probles wt strget error toleraces or coputatoall tesve probles I ode5 s slow because te proble s st odes St Low Wt crude error toleraces to solve st sstes ass atr s costat odet Moderatel St Low Moderatel st probles ou eed a soluto wtout uercal dapg. odetb St Low I usg crude error toleraces to solve st sstes. 0 MATLAB ode5 Eaple >> tpe odef. ucto = odef t %odef -- saple ode dervatve route = zeros; = -*/; %Use se = -**/^; %colos = -**; %to avod prts ed >> ts = [0....6.8 ]; %Te data >> 0 = [ ]'; %Ital values >> [t ] = ode5@odefts0 %use solver %utput te t ad soluto o et %slde MATLAB ode5 Eaple II t = 0 0.000 0.000 0.000 0.6000 0.8000.0000 =.0000.0000.0000 0.908 0.887 0.708 0.887 0.670 0.588 0.670 0.9 0.0 0.588 0.0 0.65 0.9 0.09 0.0907 0.679 0.5 0.098 %Results sow ol or speced tes %I t arra were etered as [0 ] results % or all tes would be dsplaed %I eact soluto Eact ow errors % uercal solutos or all tes are >> err = abs[ Eact] Nuercal DE Approaces Have see eplct sgle-step etods le Ruge-Kutta tat solve or + usg ol values at step Iplct etods use orato about pot + algort or + ; soe sort o approato requred Multstep etods use orato ro steps etc. Etrapolato etods Iplct Metods Metods dscussed prevousl are called eplct a d + ters o values at Use predctors to estate values betwee ad + Iplct etods use + algort Usuall requre approate soluto a use larger values wt ore wor per step copared to eplct etods Trapezod etod s a eaple ME 09 Nuercal Aalss o Egeerg Sstes
ter Nuercal DE Algorts Aprl 8 0 ME 09 Nuercal Aalss o Egeerg Sstes 5 5 Trapezod Metod I Basc plct result or ts etod Have to copute partal dervatves Need wa to copute + we we do ot ow + Frst approac: replace + b Talor seres 6 Trapezod Metod II Aoter approac to usg + algort to solve or te uow + Use a eplct approac to get a tal approato or + Iterate o plct etod E.g.: Euler step or rst approato o + 0 7 Trapezod Metod III Use Newto-Rapso terato or + Solve g = 0 b terato + = g / g g + = + / + + / g + = + 0 0 // 8 Trapezod Metod Dervato Subtract seres epaso or about + ro seres or + about ' ' ' ' ' ' 9 Trapezod Metod Dervato II ollect ters s last equato ad substtute + = + + ' 0 Trapezod Metod Eaple Loo at saple equato d/d = = -a Here = -a / = 0 ad / = -a a a a a a a a 0 So + = G wt G = a/ + a Wll use ts later stablt dscusso
ter Nuercal DE Algorts Aprl 8 0 Multstep Metods Prevous etods used ol orato ro ost recet step ad Too teredate steps betwee ad + to prove accurac Multstep etods use orato ro prevous steps or proved accurac wt less wor ta sgle step etods Need startg procedure tat s a sgle step etod Multstep Metod Dervato Uses terpolato poloal tat passes troug prevous pots Poloal s tegrated ro to + Resultg epresso gves + ters o values ad dervatves o prevous steps Leads to process ow as predctorcorrector wt two epressos or + ad a error cotrol epresso Adas-Basort-Moulto Predctor corrector etod Predctor equato uses dervatve values ro our pots P 55 59 7 9 orrector equato uses our pots cludg pot + wt predcted P P 9 9 5 Adas-Basort-Moulto II Use derece betwee predctor ad corrector results to get error estate P 55 59 7 9 P 9 9 5 Dervato result et two sldes gves error estate ters o P + v P E 9 5 9 70 70 Derve Error Equato Fro a error aalss o te tegrated terpolato poloals we ca d P 5 5 v P 70 9 5 70 v P 5 5 9 5 9 v 5 0 P 5 v 5 v 0 P 70 70 70 70 70 5 v v P Neglect v P - v. Subtract equatos. Subtract ad add v ter 5 9 5 v 70 70 5 P Derve Error Equato Solve or E te 9 5 E corrector error 70 P 5 9 5 v 70 5 v 70 70 70 6 v P 9 5 v 9 9 P 70 70 70 70 70 Error estate gves step sze cotrol How to cage ultstep etod? E ME 09 Nuercal Aalss o Egeerg Sstes 6
ter Nuercal DE Algorts Aprl 8 0 Step Sze otrol Establs e ad e a to aceve desred proble accurac I e E e a do ot cage I E < e double step sze I E > e a al step sze arr etra steps to be read or stepsze doublg Iterpolate data s cut al 7 Grd alvg error too large Noral operato o step sze cage - - - + old step --------- --------- --------- --------- --------- ew - - - + Error too large: Hal grd sze ad repeat step - - - + old step ----o---- ----o---- ----o---- ----o---- repeated - - - + terpolated pots 8 Grd doublg or ver sall error Noral operato o step sze cage -5 - - - - + old step o-----o-----o-----o-----o-----o-----o-----o -5 - - - - + ew Error ver sall: Double grd sze -5 - - - - + old step -----o----- -----o----- -----o----- ----------- - - - + Grd Halvg ad Doublg Keep etra values - ad -5 eor to be read or grd doublg -ew = -5 ; -ew = - ; -ew = - ; ew = + Grd alvg requres terpolato or ssg values old grd -ew = - ; ew = ew 5 8 70 0 5 8 ew 6 5 6 Retaed to use or doublg 9 0 Use o Multstep Metods Ma deret equatos possble wt deret orders ad errors Used or g accurac coputato requreets wt less coputer te Used g-accurac MATLAB solver ode Ruge-Kutta tpe etods easer to appl ad ca ave error cotrol or lower accurac requreets Etrapolato Metods Use Rcardso etrapolato or better estate ro results o two values o ostruct large step H betwee two values ad + H Subdvde H to saller steps = H/ opute teredate approatos to called z or te substep de Use Rcardso etrapolato or deret s Bulrsc-Stoer etod uses etrapolato ad ratoal ucto approato ME 09 Nuercal Aalss o Egeerg Sstes 7