Spline interpolation Givenatabulatedfunction

Spline interpolation Givenatabulatedfunction - Description

5 Spline interpolation Givenatabulatedfunction a spline isapolynomialbetween each pair oftabulated pointsbutonewhosecoe57358cientsaredeterminedslightlynonlocally 57476enonlocalityisdesignedto guarantee ID: 24868 Download Pdf

94K - views

Spline interpolation Givenatabulatedfunction

5 Spline interpolation Givenatabulatedfunction a spline isapolynomialbetween each pair oftabulated pointsbutonewhosecoe57358cientsaredeterminedslightlynonlocally 57476enonlocalityisdesignedto guarantee

Similar presentations


Download Pdf

Spline interpolation Givenatabulatedfunction




Download Pdf - The PPT/PDF document "Spline interpolation Givenatabulatedfunc..." is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.



Presentation on theme: "Spline interpolation Givenatabulatedfunction"— Presentation transcript:


Page 1
3.5 Spline interpolation Givenatabulatedfunction ,... ,a spline isapolynomialbetween each pair oftabulated points,butonewhosecoecientsaredetermined“slightly”non-locally. enon-localityisdesignedto guaranteeglobalsmoothnessintheinterpolatedfunctionuptosomeorderofderivative. Cubic splines arethemostpopular. eyproduceaninterpolatedfunctionthatiscontinuousthroughto thesecondderivative.Splinestendtobestablerthanttingapolynomialthroughthe points,withless possibilityofwildoscillationsbetweenthetabulatedpoints.

Weshallexplainhowsplineinterpolationworksbyrstgoingthroughthetheoryandthenapplyingitto interpolatethefunctionbelow: -4 -3 -2 -1 -0.5 0.5 Figure3.1:efunction sin between .evaluesof aregivenfor ,..., Figure3.1showsthefunction sin intheregion . Wearegiventhevalueofthe functionatthepoints ,..., ,where ,..., ,..., .esearewhatiscalled theinterpolating nodes ”. 3.5.1 Linear Spline Let’sfocusattentionononeparticularinterval . Linearinterpolationinthatintervalgivesthe interpolationformula Af Bf (3.1) where (3.2)
Page 2

isisjustlikethepiecewiseLagrangepolynomialinterpolationwelookedatearlier.Figure3.2showsthe piecewiseinterpolatedfunctionoverthefullrange -4 -3 -2 -1 -0.5 0.5 Figure3.2: Piecewiselinearinterpolationwith9nodes(solid)forthefunction sin between (dotted). Wecanseethatlinearinterpolationworksquitewellforlargervaluesof butdoesparticularlybadlyin asitfailstocapturethecurvatureofthefunction. eaccuracycanbeimprovedbyusingmore interpolatingnodes,butanimportantissueisthatthe rstderivatives oftheinterpolatingfunctionaredis- continuousatthenodes. 3.5.2 Cubic spline interpolation

egoalofcubicsplineinterpolationistogetaninterpolationformulathatiscontinuousinboththerst andsecondderivatives,bothwithintheintervalsandattheinterpolatingnodes.iswillgiveusasmoother interpolatingfunction.Ingeneral,ifthefunctionyouwanttoapproximateissmooth,thencubicsplineswill dobetterthanpiecewiselinearinterpolation. Beforeyoureadon,I’dlikeyoutoclearyourmindalittle. efollowingisaderivationofthe cubicinterpolationformulafromChapter3ofNumericalRecipesbyPress etal. ,whichisaslight variationonthe splineswediscussedinlectures,butinmyopinionillustratesthefundamental

ideaofsplineinterpolationmoreclearly.Ifyouunderstandthis,thenyouwillndworkingwith the splinesmucheasier. Let’srestatetheproblem. Wehaveafunction thatistabulatedatthe points ,..., . Ineachinterval ,wecantastraightlinethroughthepoints and usingtheformulagivenby(3.1).eproblemisthatwithalinearfunction,therstderivativeisnotcontin-
Page 3
uousattheboundarybetweentwoadjacentintervals,whilewewantthesecondderivativetobecontinuous, evenattheboundary! Nowsuppose,contrarytofact,thatinadditiontothetabulatedvaluesof ,wealsohavetabulatedvalues

forthefunction’ssecondderivatives,thatis,asetofnumbers .enwithineachinterval ,we canaddtotheright-handsideofequation(3.1)acubicpolynomialwhosesecondderivativevarieslinearly fromavalue ontheletoavalue ontheright.Doingso,wewillhavethedesiredcontinuoussecond derivative.Ifwealsoconstructthecubicpolynomialtohavezerovaluesat and ,thenaddingitinwill notspoiltheagreementwiththetabulatedfunctionalvalues and attheendpoints and Alittlesidecalculationshowsthatthereisonlyonewaytoarrangethisconstruction,namelyreplacingequa- tion(3.1)by Af Bf Cf Df (3.3) where and aredenedasbeforeand

)( )( (3.4) Notethatsince and arelinearlydependenton and (through and )havecubic -dependence. Wecanreadilycheckthat isinfactthesecondderivativeofthenewinterpolatingpolynomial.Wetake derivativesofequation(3.3)withrespectto ,usingthedenitionsof and tocompute dA dx dB dx dC dx and dD dx eresultis df dx (3.5) fortherstderivative,and dx Af Bf (3.6) forthesecondderivative.Since at and at ,and at and at ,(3.6)shows that isjustthetabulatedsecondderivative,andalsothatthesecondderivativewillbecontinuousacross theboundarybetweentwointervals,say and

eonlyproblemnowisthatwesupposedthe stobeknown,whenactually,theyarenot. However, wehavenotyetrequiredthatthe rst derivative,computedfrom(3.5),becontinuousacrosstheboundary betweentwointervals. ekeyideaofacubicsplineistorequirethiscontinuityandtouseittogetequations forthesecondderivatives erequiredequationsareobtainedbysettingequation(3.5)evaluatedfor intheinterval equaltothesameequationevaluatedfor butintheinterval . Withsomerearrangement, thisgive(for ,..., (3.7) eseare linearequationsinthe unknowns ,..., .ereforethereisatwo-parameter

familyofpossiblesolutions. Forauniquesolution,weneedtospecifyfurtherconditions,typicallytakenasboundaryconditionsat and . emostcommonwaysofdoingthisistosetboth and equaltozero,givingtheso-called
Page 4
naturalcubicspline ,whichhaszerosecondderivativesonbothofitsboundaries. Nowwehavethesolutionfor ,..., ,wecansubstitutebackintoequation(3.3)togivethecubic interpolationformulaineachinterval .isisprobablytheeasiestapproachtouseifyouwantto writeanumericalcodetocalculatecubicsplineinterpolation. So what are -splines?

Intheaboveapproach,westartedwithafunctionalformfortheinterpolationformula( Af Bf Cf Df ),andhadtouseconstraints( continuousatintervalboundaries)tosolvefor Asmathematicians,weliketobuildthingsupfromfundamentalunits. Inthiscase,wecanuseasetof piecewisecubicpolynomialsdenedonsome sub-interval of ,whicharebyconstructioncontinuous throughtosecondderivativeattheboundariesofintervals.eywouldformasetof basisfunctions ,since linear combinations ofthesefunctionswouldalsosatisfythecontinuitypropertiesattheboundariesbetween adjacentintervals.Toconstructthecubicsplineoverthewholerange

,wewouldthensimplyneed matchthesumofthebasisfunctionswithtabulatedvaluesof attheinterpolatingnodes ,..., e -splinesarethebasisfunctionsthatsatisfyourcontinuityconditions. Iftheinterpolationisoverthe region ,then isdenedby )) )) )) )) (3.8) where isthewidthbetweeninterpolatingnodes(assumedtobeequal).Notethat hasnon-zerovaluesoverfourintervals.Wecaneasilycheckthat satisfythecontinuityconditionsatthe boundariesoftheintervals,namely, and arecontinuousat and (x) k+1 (x) k+2 (x) k-1 (x) k-2 k-1 k+1 k+2 Figure3.3:Cubic -spline
Page 5
Wedene kh (i.e.the

functionsshiedtotherightby nodes).isisillustrated inFigure3.3,whichshows and .Notethatallfourofthesebasisfunctionsarenon-zero intheinterval ecubicsplinefunction, in isthenwrittenasthelinearcombinationofthe s: (3.9) esumisfrom to ,since isnonzerointheinterval ,and isnonzerointheinterval ,soweneedtotakeintoaccountthesefunctions. Istheproblemnowcompletelyspecied? Weknowthatweneed4conditions(coecients)touniquely specifyacubic,andin thereare intervals,soaltogetheratotalof conditionsareneeded.

econtinuityconditionsareautomaticallysatisedinthe interiorpoints,sincethe ssatisfythe continuityconditions(that’s conditions).eotherrequirementisthat mustmatchthetabulated points,i.e. ,for ,..., conditions).Sotherearetwounspeciedconditions,and likebeforewecantake (i.e.,curvatureequalszeroattheboundaries, naturalspline ’). Nowevaluating at (3.10) (allother sarezero) Fromthedenitionsof and ,wend Substitutinginto(3.10),wegettherecurrencerelationforthecoecients (3.11) for ,..., Whathappensattheboundaries?Rememberweset .Dierentiating

gives (3.12) Soweneedtondthesecondderivativesof
Page 6
Dierentiating twice,weget (3.13) Soasbefore,wehave ha (3.14) From(3.10),wehave (3.15) Subtract(3.14)from(3.15),weobtain (3.16) Similarly,wend (3.17) Wenowcanwriteamatrixequationtosolveforthecoecients ,..., 1 0 0 1 4 1 0 0 0 1 4 1 0 0 0 1 4 1 0 0 0 1 (3.18) issetofequationsistridiagonalandcanbesolvedin operationsbythetridiagonalalgorithm.e naltwocoecientstocompletelydetermine are (3.19)
Page 7
Worked Example

Nowwecantrytoapplycubicsplineinterpolationtothefunction sin ,withthe9 nodes Here and .Sofromequation(3.8),thebasisfunction isgivenby (3.20) ecubicspline ,andwecanndthecoecients ,..., bysolvingthe linearsystem 1 0 0 0 0 0 0 0 0 1 4 1 0 0 0 0 0 0 0 1 4 1 0 0 0 0 0 0 0 1 4 1 0 0 0 0 0 0 0 1 4 1 0 0 0 0 0 0 0 1 4 1 0 0 0 0 0 0 0 1 4 1 0 0 0 0 0 0 0 1 4 1 0 0 0 0 0 0 0 0 1 (3.21) iscanbereadilysolvedtogive ,..., .Additionally, .enumericalvalues are 0343336821 010180972 12539589 59975424 9493829 10 17 59975424 12539589 010180972 034336821 (3.22) 058492670

058492670 Weshalljustshowtheconstructionof intheinterval (( )) (( (( )) (( Soneedtoworkoutthefunctionalformof foreachinterval.ewholeprocessissomewhattedious, butasshowninthenextgure,itdoesgivetherightresult!
Page 8
-4 -3 -2 -1 -0.5 0.5 Figure3.4:Here’sthefunction sin again(dotted),andnowwiththecubicsplineinterpolation for superimposedontop.