Exercises — Modified Euler (Heun's method)
4.8.23 · D4· Maths › Numerical Methods › Modified Euler (Heun's method)
Das graded problems hain, "bas pieces ko pehchano" se lekar "ek variation khud banao" tak. Har ek problem mein ek collapsible box ke andar full worked solution chhupa hua hai — pehle khud try karo, phir reveal karo.
Yeh page parent note ki machinery assume karta hai: Heun's method. Yaad rakho woh do moves jo hum baar baar use karte hain:
Poore page mein, = slope start pe, = slope predicted end pe. Har problem bas itna hai: nikalao, ek peek-step lo, nikalao, average karo. Yeh picture apne saamne rakho.
Neeche ki figure woh mental image hai jo har problem ke liye dimag mein rakho — yeh un chaar cheezon ko draw karti hai jo hum juggle karte hain (start slope, predicted endpoint, end slope, averaged Heun step), running example ke liye (bade ke saath draw ki hai taaki geometry clearly dikhe):

Isse aise padho: coral dashed line start slope hai — sirf iske saath chalo aur tum coral predicted point pe pohonchoge (yeh exactly woh plain-Euler guess hai jo har predictor step mein hoti hai, jaise L1.1 ka ya L2.1 ka ). Butter dotted line woh end slope hai jo us predicted point pe evaluate hoti hai. Lavender line Heun step hai: uski slope coral aur butter ka average hai, aur yeh lavender pe land karti hai, jo coral prediction se kaafi zyada mint true point ke kareeb baith jaati hai. Jab bhi koi solution neeche "dono slopes ko average karo" kahe, lavender line ko coral aur butter lines ke beech ka angle split karte hue imagine karo.
Level 1 — Recognition
(Kya tum pieces point kar sakte ho aur machine mein numbers plug kar sakte ho?)
L1.1
Diya hai , , aur . Yeh pe depend nahi karta. , predictor , phir , aur aakhir mein compute karo.
Recall Solution
Pehle kya karte hain: start point padho. , .
— start pe slope (figure mein coral dashed line). ko mein plug karo: .
Predictor — peek step (coral ke saath predicted point tak chalo). . Kyun? Hume endpoint pe ki value chahiye taaki end-slope evaluate kar sakein.
— predicted end pe slope (butter dotted line). . Kyunki yahan ko ignore karta hai, .
Corrector — average karo aur step lo (lavender line). Sanity note: kyunki mein nahi hai, Heun yahan pe exactly trapezoidal rule hai, isliye bilkul exact hai. Koi error hi nahi.
L1.2
, , ke liye aur (numbers mein) identify karo, phir do.
Recall Solution
: . Predictor: . : . Corrector: Exact: . Error — bahut chhota.
Level 2 — Application
(Ek real ODE pe poori method chalao, pehle ek step mein phir do steps mein.)
L2.1
, solve karo, ke saath ek Heun step se tak pohoncho.
Recall Solution
, , , .
: . Predictor: . : . Corrector: Exact solution deta hai . Error .
L2.2
Wahi ODE , , lekin ke do steps lo tak pohonchne ke liye. Upar wale single-step answer se compare karo.
Recall Solution
Step 1 ( se tak): ; predictor ; ;
Step 2 (, se tak): ; predictor ; ;
Compare: two-step vs single-step ; exact . Errors: single-step , two-step . ko half karne se error roughly kam hua — exactly woh promise.
Level 3 — Analysis
(Method ke baare mein khud reason karo, sirf numbers crunch mat karo.)
L3.1
Linear ODE ke liye, dikhao ki ek Heun step yeh deta hai: yaani Heun exponential ko term tak reproduce karta hai.
Recall Solution
, toh ki value irrelevant hai.
: . Predictor: . : . Corrector:
= y_0 + \frac{h\lambda}{2}\big[1 + 1 + h\lambda\big]y_0.$$ $$y_1 = y_0\Big[1 + \frac{h\lambda}{2}(2 + h\lambda)\Big] = y_0\Big[1 + h\lambda + \tfrac{1}{2}(h\lambda)^2\Big].$$ **Matlab kya hai:** true step hai $y_1 = e^{h\lambda}y_0 = y_0(1 + h\lambda + \tfrac{1}{2}(h\lambda)^2 + \tfrac{1}{6}(h\lambda)^3 + \dots)$. Heun pehle **teen** terms match karta hai aur pehli baar $(h\lambda)^3$ pe disagree karta hai — exactly ek second-order method ka fingerprint. Yeh [[Order of Accuracy and Step Size]] ke peeche linear-case proof hai.L3.2
lo, ke saath (ek fast-decaying, "stiff" problem), . L3.1 ka amplification factor use karke, decide karo ki Heun aur ke liye bounded rehta hai (blow up nahi hota) ya nahi.
Recall Solution
Har step ko se multiply karta hai jahan . Numerical solution bounded rehta hai iff .
: . . Kyunki , stable — values shrink karti hain, true decaying solution se match karti hai.
: . . Kyunki , unstable — har step value ko grow karta hai, jabki true solution zero ki taraf race kar raha hota hai.
Poori picture (complex ). Generally complex ho sakta hai (oscillatory ya spiral solutions), toh complex plane mein ek point hai. RK2 ki region of absolute stability complex ka woh set hai jahan — ek bounded egg-shaped region jo left half-plane mein origin ke paas rehti hai. Hamare real cases sirf negative real axis ke saath woh slice hain: turns out wahan exactly ke liye hota hai, toh andar baitha hai (stable) aur bahar girta hai (unstable). Stiff problem ke liye tumhe us region ke andar rakhna hi hoga.
Yeh kya sikhata hai: accuracy order poori kahani nahi hai. Stiff problems ke liye itna chhota hona chahiye ki stability region mein rahe, warna answer oscillate aur explode ho jaata hai.
Level 4 — Synthesis
(Ideas combine karo — iterated correctors, weighted variants, error estimation.)
L4.1 (Iterated corrector)
, , ke liye: predictor + corrector karo, phir corrector ko do baar aur iterate karo (latest ko har baar mein wapas feed karte hue). Sequence report karo aur dekho kahan settle hota hai.
Recall Solution
(fixed — sirf start point use karta hai).
Woh implicit equation jo hum solve kar rahe hain. True trapezoidal corrector implicit hai kyunki unknown dono sides pe appear karta hai:
= 1 + 0.05\big[1 + (0.1 + y_1)\big] = 1.055 + 0.05\,y_1.$$ Hum isse **fixed-point iteration** se solve karte hain: $y_1^{(n+1)} = 1.055 + 0.05\,y_1^{(n)}$ likho aur har output ko wapas feed karo. **Iteration 0 (predictor):** $y^{(0)} = 1 + 0.1(1) = 1.1$. **Iteration 1:** $k_2 = f(0.1, 1.1) = 1.2$; $\;y^{(1)} = 1 + 0.05(1 + 1.2) = 1.11$. **Iteration 2:** $k_2 = f(0.1, 1.11) = 1.21$; $\;y^{(2)} = 1 + 0.05(1 + 1.21) = 1.1105$. **Iteration 3:** $k_2 = f(0.1, 1.1105) = 1.2105$; $\;y^{(3)} = 1 + 0.05(1 + 1.2105) = 1.110525$. **Kahan settle hota hai.** Kyunki map ki slope $0.05$ hai (1 se kaafi kum), iteration ek contraction hai aur exact fixed point $y_1^{*} = \dfrac{1.055}{1-0.05} = \dfrac{1.055}{0.95} = 1.1105263\ldots$ ki taraf converge karta hai — woh implicit trapezoidal equation ka true solution. Iterates $1.1,\,1.11,\,1.1105,\,1.110525,\dots$ seedha us pe march karte hain. **Hum kya seekhte hain:** iterating implicit corrector ko zyada exactly solve karta hai, lekin yeh trapezoid ke apne answer tak converge karta hai, jo ODE ke exact $y = 2e^{0.1}-1.1 = 1.110342$ ke against method ka $O(h^2)$ truncation error abhi bhi carry karta hai — iterating underlying rule ko nahi beat kar sakti. Yeh [[Predictor-Corrector Methods]] ka core hai.L4.2 (Error estimate predictor vs corrector se)
Har step ke liye ek sasta error indicator gap hai. Isse , , ke liye compute karo, aur comment karo.
Recall Solution
L4.1 se: predictor , first corrector . Is point pe actual global error (exact ke against) hai. Predictor–corrector gap () true error se bada hai lekin same order in track karta hai — yeh ke proportional hai aur adaptive step-size control mein use hota hai yeh decide karne ke liye ki ko shrink karein ya grow. Yeh ek conservative alarm hai, exact error nahi.
Level 5 — Mastery
(Ek general result prove/derive karo, ya ek nayi variant banao.)
L5.1 (Order-2 condition ek general two-slope method ke liye)
Ek general two-stage scheme consider karo:
y_1 = y_0 + h(a\,k_1 + b\,k_2).$$ Dikhao ki Heun ($p=1,\,a=b=\tfrac12$) **second order** ke liye zaroori do conditions satisfy karta hai, aur $(p,a,b)$ ki ek *aur* aisi choice dhundho jo bhi second order ho. > [!recall]- Solution > **Pehle notation.** Maano $f_x := \dfrac{\partial f}{\partial x}$ aur $f_y := \dfrac{\partial f}{\partial y}$, > dono **start point** $(x_0,y_0)$ pe evaluated, aur $f := f(x_0,y_0)$ likho. Yeh measure karte hain ki $f$ kitni tez badlata hai jab tum $x$ nudge karte ho ($y$ hold karke) ya $y$ nudge karte ho ($x$ hold karke). > > **Two-variable Taylor expansion kyun?** True step ki Taylor series mein $y''$ aata hai, aur chain rule se $y'' = \dfrac{d}{dx}f(x,y(x)) = f_x + f_y\,y' = f_x + f_y f$. Toh scheme ko $h^2$ order pe truth se compare karne ke liye hume $f$ ko ek *shifted* point $(x_0+ph,\,y_0+ph\,k_1)$ pe expand karna hoga. > Multivariable first-order Taylor expansion hai: > $$f(x_0+\Delta x,\ y_0+\Delta y) = f + f_x\,\Delta x + f_y\,\Delta y + O(\Delta^2),$$ > yaani "value plus (rate in $x$) $\times$ (step in $x$) plus (rate in $y$) $\times$ (step in $y$)." > > **$k_2$ pe apply karo.** Yahan $\Delta x = ph$ aur $\Delta y = ph\,k_1 = ph\,f$, toh > $$k_2 = f + f_x(ph) + f_y(ph\,f) + O(h^2) = f + ph\,f_x + ph\,f\,f_y + O(h^2).$$ > > **Scheme ka step banao aur Taylor se match karo.** True step: > $$y(x_1) = y_0 + h f + \tfrac{h^2}{2}(f_x + f_y f) + O(h^3).$$ > Scheme: > $$y_1 = y_0 + h\big(a f + b[f + ph f_x + ph f f_y]\big) + O(h^3) > = y_0 + (a+b)hf + bph^2(f_x + f f_y) + O(h^3).$$ > > **Term by term match karo:** > - $h^1$ term: $(a+b) = 1.$ > - $h^2$ term: $bp = \tfrac12.$ > > Yeh hain **do order-2 conditions**. Heun $p=1,\ b=\tfrac12$ use karta hai: check karo $a+b = \tfrac12+\tfrac12 = 1$ ✓ aur $bp = \tfrac12\cdot1 = \tfrac12$ ✓. > > **Ek aur valid choice — midpoint method.** $p=\tfrac12$ lo. Tab $bp=\tfrac12$ force karta hai > $b = 1$, aur $a+b=1$ force karta hai $a = 0$: > $$k_1 = f(x_0,y_0),\quad k_2 = f\big(x_0+\tfrac{h}{2},\,y_0+\tfrac{h}{2}k_1\big),\quad y_1 = y_0 + h\,k_2.$$ > Yeh **midpoint (modified Euler-midpoint) method** hai — bhi second order, sirf > single mid-step slope use karke. Dono RK2 family ke andar hain (dekho [[Runge-Kutta Methods]]). ### L5.2 (Midpoint variant apply karo) L5.1 ka midpoint method $y' = x+y$, $y(0)=1$, $h=0.1$ pe use karo, aur iska error Heun ($1.11$) se compare karo. > [!recall]- Solution > $k_1 = f(0,1) = 1$. > Mid-point value: $x_0 + \tfrac{h}{2} = 0.05$, $\;y_0 + \tfrac{h}{2}k_1 = 1 + 0.05 = 1.05$. > $k_2 = f(0.05, 1.05) = 0.05 + 1.05 = 1.1$. > $$y_1 = 1 + 0.1(1.1) = \mathbf{1.11}.$$ > Exact $= 1.110342$; error $\approx 0.00034$ — essentially Heun jaisi hi accuracy, kyunki dono order 2 hain. Woh sirf third-order term mein differ karte hain, toh is smooth problem ke liye same rounded value pe land karte hain. > [!mistake] L5 trap: yeh sochna ki sirf EK second-order method hai > **Kyun sahi lagta hai:** Heun woh hai jo sabse zyada naam se jaana jaata hai, toh canonical/unique lagta hai. > **Kyun galat hai:** order-2 conditions $a+b=1$, $bp=\tfrac12$ ke solutions ki ek **one-parameter > family** hoti hai (koi bhi $p\neq0$ chuno). Heun ($p=1$), midpoint ($p=\tfrac12$), aur Ralston's > method ($p=\tfrac23$) sab second order hain. > **Fix:** "second order" ek property hai (Taylor ko $h^2$ tak match karna), jo infinitely many > two-stage schemes satisfy karte hain — Heun sirf equal-weight member hai. --- ## Connections - [[Euler's Method]] — yahan har predictor ek Euler step hai. - [[Trapezoidal Rule]] — corrector; L1.1 exactly yahi rule hai. - [[Runge-Kutta Methods]] — L5.1 ki family RK2 hai; midpoint aur Ralston wahan bhi hain. - [[Order of Accuracy and Step Size]] — L2.2 aur L3.1 $O(h^2)$ scaling demonstrate karte hain. - [[Predictor-Corrector Methods]] — L4.1 ki iteration prototype hai. - [[Taylor Series Methods]] — L5.1 Taylor expansion ko term by term match karta hai.