4.8.12 · HinglishNumerical Methods

Cubic spline interpolation — natural, clamped

1,661 words8 min readRead in English

4.8.12 · Maths › Numerical Methods


Cubic spline KYA hoti hai?

YEH TEEN CONDITIONS KYUN? Condition 1 har piece ko simple rakhti hai. Condition 2 curve ko data se guzarne par majboor karti hai. Condition 3 magic hai: value, slope aur curvature ka match hona visible kinks hatata hai aur curve ko "fair" banata hai.


Hum unknowns kaise count karte hain (bookkeeping)

intervals hain, har cubic ke 4 coefficients hain → unknowns.

Constraints:

  • Har piece ke dono ends pe interpolation: equations.
  • Interior nodes pe ki continuity: .
  • Interior nodes pe ki continuity: .

Total equations.


System ko scratch se derive karna ( / moment method)

Hum second derivatives ke saath kaam karte hain (inhe moments kehte hain). Maano .

Step 1 — pe, linear hai (kyunki cubic hai, degree 1 hai). Yeh step kyun? Ek cubic ki second derivative linear hoti hai, aur se guzarne wali line forced hai:

Step 2 — Do baar integrate karo recover karne ke liye. Kyun? Ek jaani hui ko integrate karne se milta hai do constants tak, jinhe hum , use karke pin karte hain:

Yeh exact form kyun? Cubic terms ko integrate karte hain; linear terms woh integration constants hain jo is tarah choose kiye gaye hain ki endpoints pe values aayen (check karo: pe cubic terms aur cancel ho jaate hain aur bachta hai).

Step 3 — Differentiate karo aur slope continuity impose karo . Kyun? Yeh condition 3 hai, yahi woh jagah hai jahan pieces ek doosre se "baat" karte hain. Ise kaam karne par master recurrence milta hai:

Yeh moments ke liye equations hain. Do aur chahiye → boundary conditions.


Do boundary types

Figure — Cubic spline interpolation — natural, clamped

Worked Example 1 — Natural spline, 3 points

Data: . Equal spacing .

Step 1. Natural ⇒ . Kyun? Natural condition end curvatures ko zero karta hai, sirf unknown bachta hai.

Step 2. pe interior equation use karo: Numbers plug karo: Toh Yeh step kyun? Yeh master recurrence hai; RHS (right slope left slope) hai.

Step 3. pe banao ke saath:

= -\tfrac{1}{2}x^3 + 0 + \Big(1+\tfrac12\Big)x = -\tfrac12 x^3+\tfrac32 x.$$ *Kyun?* Step-2 formula mein $h=1$ substitute karke. Check karo: $S_0(0)=0$✓, $S_0(1)=-\tfrac12+\tfrac32=1$✓, $S_0''(0)=0$✓ (natural). --- ## Worked Example 2 — Clamped spline, same points Data $(0,0),(1,1),(2,0)$, clamped with $f_0'=0,\ f_2'=0$ (flat ends). **Step 1.** Do boundary equations + ek interior equation mila ke $M_0,M_1,M_2$ ka $3\times3$ system banta hai. Left boundary: $2h_0M_0+h_0M_1=6(\frac{y_1-y_0}{h_0}-f_0')=6(1-0)=6.$ Right boundary: $h_1M_1+2h_1M_2=6(f_2'-\frac{y_2-y_1}{h_1})=6(0-(-1))=6.$ Interior: $M_0+4M_1+M_2=-12$ (Example 1 se). **Step 2.** $3\times3$ system solve karo: - Left boundary: $2M_0+M_1=6$. - Right boundary: $M_1+2M_2=6$. - Interior: $M_0+4M_1+M_2=-12$. Data ki symmetry se, guess karo $M_0=M_2$. Left boundary se $M_0=(6-M_1)/2$. $M_0=M_2=(6-M_1)/2$ ko interior equation mein substitute karo: $$\frac{6-M_1}{2}+4M_1+\frac{6-M_1}{2}=-12 \;\Rightarrow\; (6-M_1)+4M_1=-12 \;\Rightarrow\; 6+3M_1=-12 \;\Rightarrow\; M_1=-6.$$ Tab $M_0=M_2=(6-(-6))/2=6.$ *Kyun?* Clamping ends pe extra curvature force karta hai ($M_0=M_2=6$) slope ko zero pe laane ke liye — natural se bilkul alag jahan $M_0=0$ tha. Clamped curve ends pe "stiffer" hota hai aur imposed zero slope ko exactly match karta hai. --- > [!recall]- Active recall — answers cover karo > - Ek bada polynomial kyun nahi? ::: Runge oscillation; splines local aur smooth rehti hain. > - Humein kitni extra conditions chahiye aur kyun? ::: 2; kyunki $4n$ unknowns vs $4n-2$ equations. > - Natural kya impose karta hai? ::: $M_0=M_n=0$ (zero end curvature). > - Clamped kya impose karta hai? ::: Given end **slopes** $S'(x_0),S'(x_n)$. > - Tridiagonal system kis quantity ko solve karta hai? ::: Moments $M_i=S''(x_i)$. --- ## Common mistakes (Steel-man + fix) > [!mistake] "Clamped matlab main end *values* fix karta hun." > **Kyun sahi lagta hai:** "Clamp" sunne mein lagta hai jaise height nail down ho rahi hai. **Sachchi baat:** values *hamesha* interpolation se fix hoti hain. Clamped ends pe **first derivative (slope)** fix karta hai. *Fix:* yaad rakho clamp = ek angle pe pakda hua. > [!mistake] "Natural spline sabse accurate curve deti hai." > **Kyun sahi lagta hai:** "natural" physically ideal lagta hai. **Sachchi baat:** natural tab best hai jab boundary slopes ke baare mein kuch pata na ho; agar true slopes available hain, toh **clamped** ends ke paas zyada accurate hai aur boundary error hatata hai. *Fix:* jo information tumhare paas hai use karo. > [!mistake] Linear terms mein $\frac{M h}{6}$ correction bhool jaana. > **Kyun sahi lagta hai:** akela linear interpolant "done" lagta hai. **Sachchi baat:** $M h/6$ subtract kiye bina formula nodes pe $y_i$ reproduce nahi karega. *Fix:* har baar verify karo ki $S_i(x_i)=y_i$. --- > [!recall]- Feynman (ek 12-saal ke bacche ko samjhao) > Socho ek patli flexible stick ko is tarah modte hain ki woh ek row of pins se guzre (tumhara data). Stick mein kink nahi aa sakta — use ek pin se doosre tak smoothly curve karna hoga. Do pins ke beech ke har chhote stretch ko ek smooth cubic curve describe karta hai, aur jahan do stretches milte hain, heights, tilt, aur *bendiness* teeno match karte hain taaki kabhi corner na dikhe. Ek **natural** stick apne dono free ends pe seedhi rehti hai. Ek **clamped** stick har end pe ek fixed tilt pe pakdi jaati hai, jaise apni ungliyon se ends pakad lo. > [!mnemonic] Yaad rakho > **"Natural = No curvature ($M$=0); Clamped = Controlled slope ($S'$ diya hua)."** > Dono us cheez ke same letter se start karte hain jo woh ek known value pe set karte hain (Natural→zero, Clamped→slope... *C for Controlled derivative*). --- ## #flashcards/maths Spline pieces ko $C^2$ kya property banati hai? ::: Value, first derivative, aur second derivative teeno interior nodes pe continuous hain. Spline interpolation mein moment $M_i$ define karo. ::: $M_i = S''(x_i)$, node $i$ pe second derivative. Natural boundary condition likho. ::: $M_0 = 0$ aur $M_n = 0$. Clamped boundary condition likho. ::: $S'(x_0)=f_0'$ aur $S'(x_n)=f_n'$ (fixed end slopes). Spline linear system tridiagonal kyun hai? ::: Har interior equation sirf $M_{i-1},M_i,M_{i+1}$ ko link karta hai. Interior spline equation ka RHS kya represent karta hai? ::: $6\times$ (adjacent secant slopes ka difference) ≈ curvature. Smoothness conditions kitni equations short hain, jiske liye boundary conditions chahiye? ::: 2 ($4n$ unknowns vs $4n-2$ equations). Splines ko ek single high-degree polynomial se kyun prefer karte hain? ::: Yeh Runge oscillation avoid karte hain aur local rehte hain. $[x_i,x_{i+1}]$ pe $S''$ linear kyun hoti hai? ::: Kyunki $S$ cubic hai isliye uski second derivative degree 1 ki hoti hai. Clamped, natural se zyada accurate kab hota hai? ::: Jab true boundary slopes pata hon. --- ## Connections - [[Runge phenomenon]] — woh problem jo splines solve karti hain. - [[Lagrange interpolation]] — global polynomial alternative. - [[Tridiagonal systems & Thomas algorithm]] — moment system fast solve karne ka tarika. - [[Hermite interpolation]] — yeh bhi derivative data use karta hai jaise clamped splines. - [[Finite differences]] — RHS curvature term ek second difference hai. - [[B-splines]] — basis-function generalization. ## 🖼️ Concept Map ```mermaid flowchart TD R[Runge oscillation] -->|motivates| PW[Piecewise cubics] PW -->|defines| CS[Cubic spline S x] CS -->|interpolates| INT[S xi equals yi] CS -->|smoothness| C2[C2 continuity of S S' S''] INT -->|gives| EQ[4n minus 2 equations] C2 -->|gives| EQ PW -->|has| UNK[4n unknowns] UNK -->|short by 2| BC[2 boundary conditions] BC -->|choice yields| NAT[Natural spline] BC -->|choice yields| CLA[Clamped spline] C2 -->|derived via| MOM[Moment method Mi equals S'' xi] MOM -->|slope continuity| TRI[Tridiagonal system] ```