UniversitasGadjahMadaDepartmentofCivilandEnvironmentalEngineeringMasterofEngineeringinNaturalDisasterManagement
DataProcessingTechniquesCurveFitting:RegressionandInterpolation
3-Oct-17
http://istia
rto.staff.u
gm.ac.id
1
CurveFitting• Reference• Chapra,S.C.,CanaleR.P.,1990,NumericalMethodsforEngineers,2ndEd.,McGraw-HillBookCo.,NewYork.• Chapter11and12,pp.319-398.
3-Oct-17
http://istia
rto.staff.u
gm.ac.id
2
CurveFitting• Alineorcurvethatrepresentsanumberofdatapoints• Therearetwomethodstofindsuchlineorcurve• Regression• Interpolation
• Engineeringapplications• Trendanalysis• Hypothesistesting
3-Oct-17
http://istia
rto.staff.u
gm.ac.id
3
RegressionvsInterpolation• Regression• Thedatashowsignificanterrorsornoise• Tofindasinglecurvethatrepresentgeneraltrendofthedata• Regressionline(curve)doesnotneedtopasseverydatapoint
• Interpolation• Thedataareaccurate• Tofindacurveorcurvesthatencompass(es)everydatapoint• Toestimatevaluesbetweendatapoints
3-Oct-17
http://istia
rto.staff.u
gm.ac.id
4
RegressionandInterpolation• Extrapolation• Similartointerpolationbutappliedtooutsiderangeofdatapoints• Notrecommended
3-Oct-17
http://istia
rto.staff.u
gm.ac.id
5
CurveFittingtoMeasuredData• Trendanalysis• Useofdatatrend(measurements,experiments)toestimatevalues
• Ifthedataareaccurate,useinterpolationtechnique• Ifthedatashownoise,useregressiontechnique
• Hypothesistesting• Comparisonbetweentheoreticalvalueswithcomputedones
3-Oct-17
http://istia
rto.staff.u
gm.ac.id
6
Recall:StatisticalParameters• Arithmeticmean
• Standarddeviation
• Variance
• Coefficientofvariation
represen
tdatadistrib
ution
!!sy
2 =Stn−1
!!y = 1
nyi∑
!!sy =
Stn−1 !!
St = yi −y( )2
∑
!!c.v.=
syy100%
3-Oct-17
http://istia
rto.staff.u
gm.ac.id
7
ProbabilityDistribution
X
freq
NormalDistributiononeofdatadistributionsthatisfrequentlyencounteredinengineering
3-Oct-17
http://istia
rto.staff.u
gm.ac.id
8
Regression:Least-squareMethod• Tofindasinglecurveorfunction(approximate)thatrepresentsthegeneraltrendofthedata• Thedatashowsignificanterror• Thecurvedoesnotneedtopasseverydatapoint
• Methods• Linearregression(simplelinearregression)• Linearizedexpressions• Polynomialregression• Multiplelinearregression• Non-linearregression
3-Oct-17
http://istia
rto.staff.u
gm.ac.id
10
Regression:Least-squareMethod• How• Spreadsheet(MSExcel)• Computerprogram
• MatLab• Freeware
• Octave• Scilab• Freemat
3-Oct-17
http://istia
rto.staff.u
gm.ac.id
11
SimpleLinearRegression• Tofindastraightlinethatrepresentsthegeneraltrendofdatapoints:(x0,y0),(x1,y1),…,(xn,yn)
• MSExcel• =INTERCEPT(y,x)• =SLOPE(y,x)
yreg =a0 + a1xa0 : intercepta1 : slope
3-Oct-17
http://istia
rto.staff.u
gm.ac.id
12
SimpleLinearRegression• Errororresidual• Discrepanciesbetweenactualvalueofy (y data)andapproximatevalueofy (yreg)accordingtolinearexpressiona0 +a1x
• Minimizethesumofsquaredresidues
!!e= y− a0 +a1x( )
!!min Sr!
"#$=min ei
2!"
#$=min yi −a0 −a1xi( )
2
∑!"'#$(
3-Oct-17
http://istia
rto.staff.u
gm.ac.id
13
SimpleLinearRegression• Howtofinda0 anda1?• DifferentiatetheequationofSr twice;firstlyw.r.ta0 andlastlyw.r.ta1• Seteachofthetwoequationstozero• Solvetheequationsfora0 anda1
!!
∂Sr∂a0
=−2 y−a0 −a1xi( )∑ =0
∂Sr∂a1
=−2 y−a0 −a1xi( )xi∑ =0
!!
a1 =n xiyi∑ − xi∑ yi∑n xi
2∑ − xi∑( )2
a0 = y −a1 x
3-Oct-17
http://istia
rto.staff.u
gm.ac.id
14
Example#1i xi yi =f(xi)0 1 0.51 2 2.52 3 23 4 44 5 3.55 6 66 7 5.5
01234567
0 1 2 3 4 5 6 7
y=f(x
)
X
3-Oct-17
http://istia
rto.staff.u
gm.ac.id
15
Example#1i xi yi xi yi xi2 yreg (yi−yreg)2 (yi−ymean)2
0 1 0.5 0.5 1 0.910714 0.168686 8.576531
1 2 2.5 5 4 1.75 0.5625 0.862245
2 3 2.0 6 9 2.589286 0.347258 2.040816
3 4 4.0 16 16 3.428571 0.326531 0.326531
4 5 3.5 17.5 25 4.267857 0.589605 0.005102
5 6 6.0 36 36 5.107143 0.797194 6.612245
6 7 5.5 38.5 49 5.946429 0.199298 4.290816
∑= 28 24.0 119.5 140 ∑= 2.991071 22.71429
3-Oct-17
http://istia
rto.staff.u
gm.ac.id
16
Example#1
a1 =n xiyi∑ − xi∑ yi∑
n xi2∑ − xi∑( )
2=
7 119.5( )−28 24( )7 140( )− 28( )2
= 0.839286
!!
y = 247=3.4
x = 287= 4
a0 =3.4−0.839286 4( ) =0.071429
3-Oct-17
http://istia
rto.staff.u
gm.ac.id
17
Example#1
01234567
0 1 2 3 4 5 6 7 8
Y
X
data
regression
3-Oct-17
http://istia
rto.staff.u
gm.ac.id
18
Error• Error• Standarderrormagnitude
• Noticeitssimilaritywithstandarddeviation
!!sy x =
Srn−2
!!sy =
Stn−1 !!
St = yi −y( )2
∑
!!Sr = yi −a0 −a1xi( )
2
∑
3-Oct-17
http://istia
rto.staff.u
gm.ac.id
19
Error• Diffrencebetweenthetwo“errors”signifiesanimprovementofthepredictionorareductionoferror
r2 =St − Sr
St
=1−Sr
St
r =n xiyi∑ − xi∑( ) yi∑( )
n xi2∑ − xi∑( )
2n yi
2∑ − yi∑( )2
coefficientofdetermination
correlationcoefficient
3-Oct-17
http://istia
rto.staff.u
gm.ac.id
20
Error
!!
Sr = yi −a0 −a1xi( )2
∑ =2.991071
St = yi −y( )2
∑ =22.71429
!!
r2 =1−SrSt=1− 2.991971
22.71429=0.868318
r =0.931836
3-Oct-17
http://istia
rto.staff.u
gm.ac.id
21
Example#2i xi yi =f(xi)0 1 5.51 2 62 3 3.53 4 44 5 25 6 2.56 7 0.5
01234567
0 1 2 3 4 5 6 7
y=f(x
)
X
3-Oct-17
http://istia
rto.staff.u
gm.ac.id
22
LinearRegression• Linearizednon-linearequations• Logarithmiceq.à lineareq.• Exponentialeq.à lineareq.• nthorderpolynomialeq.(n >1)à lineareq.• etc.
3-Oct-17
http://istia
rto.staff.u
gm.ac.id
24
LinearRegression
x
y ln y
1
ln a
!y =aebx
!!lny = lna+bx
x
b
3-Oct-17
http://istia
rto.staff.u
gm.ac.id
25
LinearRegression
1
x
y log y
logx
b!y =axb
!!logy = loga+blogx
!!loga
3-Oct-17
http://istia
rto.staff.u
gm.ac.id
26
LinearRegression
1/y
1!y =a x
b+ x
1/x
y
x
!!
1y=b+ xax
=1a+ba1x
!!1 a!b a
3-Oct-17
http://istia
rto.staff.u
gm.ac.id
27
PolynomialRegression• Someengineeringdata,althoughexhibitingamarkedpattern,ispoorlyrepresentedbyastraightline• Method1:Coordinatetransformation(linearizednon-lineareq.)• Method2:Polynomialregression
• Themth-degreepolynomial
• Thesumofthesquaresoftheresiduals!!y =a0 +a1x+a2x
2 +...+amxm
!!Sr = ei
2
i=1
n
∑ = yi −a0 −a1xi +a2xi2 +...+amxi
m( )2
i=1
n
∑
3-Oct-17
http://istia
rto.staff.u
gm.ac.id
29
• Theleast-squaremethodextendedtofitthedatatoanmth-degreepolynomial
• Theseequationscanbesetequaltozeroandrearrangedtodevelopasetofnormalequations
!!
∂Sr∂a0
=−2 yi −a0 −a1xi +a2xi2 +...+amxi
m( )i=1
n
∑
∂Sr∂a1
=−2 xi yi −a0 −a1xi +a2xi2 +...+amxi
m( )i=1
n
∑
∂Sr∂a2
=−2 xi2 yi −a0 −a1xi +a2xi
2 +...+amxim( )
i=1
n
∑
.
.
.∂Sr∂am
=−2 xim yi −a0 −a1xi +a2xi
2 +...+amxim( )
i=1
n
∑
3-Oct-17
http://istia
rto.staff.u
gm.ac.id
30
!!
a0n+a1 xii=1
n
∑ +a2 xi2
i=1
n
∑ +...+am xim
i=1
n
∑ = yii=1
n
∑
a0 xii=1
n
∑ +a1 xi2
i=1
n
∑ +a2 xi3
i=1
n
∑ +...+am xim+1
i=1
n
∑ = xiyii=1
n
∑
a0 xi2
i=1
n
∑ +a1 xi3
i=1
n
∑ +a2 xi4
i=1
n
∑ +...+am xim+2
i=1
n
∑ = xi2yi
i=1
n
∑
.
.
.
a0 xim
i=1
n
∑ +a1 xim+1
i=1
n
∑ +a2 xim+2
i=1
n
∑ +...+am xi2m
i=1
n
∑ = ximyi
i=1
n
∑
§ Therearem+1linearequationshavingm+1unknowns,i.e.a0,a1,a2,…,am
§ Theselinearequationscanbesimultaneouslysolvedbyusingmethodssuchas• Gausselimination• Gauss-Jordan• Jacobiiteration• Matrixinversion
3-Oct-17
http://istia
rto.staff.u
gm.ac.id
31
Example• Fitasecond-orderpolynomialtothedatainthetableontheright
• Answer
xi yi0 2.1
1 7.7
2 13.6
3 27.2
4 40.9
5 61.1
!!y =a0 +a1x+a2x2
!!
y =2.47857+2.35929x+1.86071x2
r2 =1−SrSt=1− 3.74657
2513.39=0.99851
r =0.99925
3-Oct-17
http://istia
rto.staff.u
gm.ac.id
32
MultipleLinearRegression• Supposethedependentvariabely isalinearfunctionoftwoindependentvariablesx1 andx2
• Thebestvaluesofthecoefficientsaredeterminedbysettingupthesumofthesquaresoftheresiduals
!!y =a0 +a1x1+a2x2
!!Sr = yi −a0 −a1x1i −a2x2i( )
2
i=1
n
∑
3-Oct-17
http://istia
rto.staff.u
gm.ac.id
34
MultipleLinearRegression
!!
∂Sr∂a0
=−2 yi −a0 −a1x1i −a2x2i( )i=1
n
∑
∂Sr∂a1
=−2 x1i yi −a0 −a1x1i −a2x2i( )i=1
n
∑
∂Sr∂a2
=−2 x2i yi −a0 −a1x1i −a2x2i( )i=1
n
∑
§ Differentiatingthisequationw.r.teachoftheunknowncoefficients
!!
a0n+a1 x1ii=1
n
∑ +a2 x2ii=1
n
∑ = yii=1
n
∑
a0 x1ii=1
n
∑ +a1 x1i2
i=1
n
∑ +a2 x1i x2ii=1
n
∑ = x1iyii=1
n
∑
a0 x2ii=1
n
∑ +a1 x1i x2ii=1
n
∑ +a2 x2i2
i=1
n
∑ = x2iyii=1
n
∑
§ Equatingthedifferentialstozeroandexpressingtheresultedequationasasetofsimultaneouslineareqsyield
3-Oct-17
http://istia
rto.staff.u
gm.ac.id
35
MultipleLinearRegression
!!
n x1ii=1
n
∑ x2ii=1
n
∑
x1ii=1
n
∑ x1i2
i=1
n
∑ x1i x2ii=1
n
∑
x2ii=1
n
∑ x1i x2ii=1
n
∑ x22
i=1
n
∑
"
#
$$$$$$$$
%
&
''''''''
a0a1a2
(
)**
+**
,
-**
.**
=
yii=1
n
∑
x1i yii=1
n
∑
x2i yii=1
n
∑
(
)
****
+
****
,
-
****
.
****
§ Writteninmatrixform 3-Oct-17
http://istia
rto.staff.u
gm.ac.id
36
Example• Findthebestlinearequationthatfitstothedatainthetableontheright
• Answer
x1 x2 y
0 0 5
2 1 10
2.5 2 9
1 3 0
4 6 3
7 2 27!!
y =5+4x1 −3x2R2 =1
3-Oct-17
http://istia
rto.staff.u
gm.ac.id
37
MultipleLinearRegression• Multiplelinearregressioncanbeusefulinthederivationofpowerequationsofthegeneralform
• Suchequationsareextremelyusefulwhenfittingexperimentaldata• Inordertousethemultiplelinearregression,theequationistransformedbytakingitslogarithmtoyield
!!y =a0x1a1x2
a2 ...xmam
!!logy = loga0 +a1 logx1+a2 logx2 +...+am logxm
3-Oct-17
http://istia
rto.staff.u
gm.ac.id
38
GeneralLinearLeastSquares• Thethreetypesofregressionthathavebeenpresented,i.e.simplelinear,polynomial,andmultiplelinearcanbeexpressedinageneralleast-squaresmodel
• wherez0,z1,…,zm arem+1differentfunctions• m+1isthenumberofindependentvariables• n+1isthenumberofdatapoints
• Theaboveexpressioncanbewritteninamatrixform
!!y =a0z0 +a1z1+a2z2 +...+amzm
!Y{ }= Z!" #
$ A{ }
3-Oct-17
http://istia
rto.staff.u
gm.ac.id
40
GeneralLinearLeastSquares!Y{ }= Z!" #
$ A{ }
!!
Z!" #$=
a01 a11 . . . am1
a02 a12 . . . am2
. . .
. . .
. . .a0n a1n amn
!
"
%%%%%%%%
#
$
&&&&&&&&
§ {Y}containstheobservedvaluesofthedependentvariables
§ [Z]iaamatrixoftheobservedvaluesoftheindependentvariables
§ {A}containstheunkowncoefficients
!Z!" #$TZ!" #$ A{ }= Z!" #
$TY{ }
!!Sr = yi − ajzji
j=1
m
∑#
$%%
&
'((
2
i=1
n
∑
3-Oct-17
http://istia
rto.staff.u
gm.ac.id
41
GeneralLinearLeastSquares
!Z!" #$TZ!" #$ A{ }= Z!" #
$TY{ }
§ Solutionstrategy• LUdecomposition• Cholesky’smethod• Matrixinverseapproach
!!A{ }= Z!" #
$TZ!" #$
!"%
#$&
−1
Z!" #$TY{ }
3-Oct-17
http://istia
rto.staff.u
gm.ac.id
42
Interpolation• Situation• Needtoestimateintermediatevaluesbetweenprecisedatapoints.• Themostcommonmethodusedforthispurposeispolynomialinterpolation
• Generalformulaforannth-orderpolynomialis
• Thereisonlyonepolynomialofordern orlessthatpassesthroughalln+1datapoints.
!!f x( ) =a0 +a1x+a2x2 +...+anxn
3-Oct-17
http://istia
rto.staff.u
gm.ac.id
45
Interpolation• Solutionfornthorderpolynomialrequiresn+1datapoints• Availablemethodstofindnthorderpolynomialthatinterpolatesn + 1 datapointsare:• NewtonMethod• LagrangeMethod
3-Oct-17
http://istia
rto.staff.u
gm.ac.id
46
LinearInterpolation:NewtonMethod
( ) ( ) ( ) ( )
( ) ( ) ( ) ( ) ( )001
0101
01
01
0
01
xxxxxfxf
xfxf
xxxfxf
xxxfxf
---
+=
--
=--
f(x)
f(x1)
f1(x)
f(x0)
x0 x1x
3-Oct-17
http://istia
rto.staff.u
gm.ac.id
47
QuadraticInterpolation:NewtonMethod
( ) ( ) ( )( )
( ) ( ) ( )!2
212021102010
12021022
20110
1020102
210
xbxxbxbbxxbxbb
xxbxxbxxbxbxbxbb
xxxxbxxbbxf
aaa
+--++-=
--++-+=
--+-+=
"" #"" $%""" #""" $%
( ) 22102 xaxaaxf ++=
ïî
ïí
ì
=--=+-=
22
120211
1020100
ba
xbxbba
xxbxbba
3-Oct-17
http://istia
rto.staff.u
gm.ac.id
48
QuadraticInterpolation:NewtonMethod
( ) ( ) ( ) ( )[ ] [ ] [ ]
12
0112012
12
01
01
12
12
2,
,,xxxxfxxf
xxxfxx
xxxfxf
xxxfxf
b-
--==
---
---
=
( )00 xfb =
( ) ( ) [ ]0101
011 , xxf
xxxfxf
b =--
=
3-Oct-17
http://istia
rto.staff.u
gm.ac.id
49
PolynomialInterpolation:NewtonMethod
( ) ( ) ( )( ) ( )110010 ...... ----++-+= nnn xxxxxxbxxbbxf
( )[ ][ ]
[ ]011
0122
011
00
,,...,,
.
.
.
,,
,
xxxxfb
xxxfb
xxfb
xfb
nnn -=
===
3-Oct-17
http://istia
rto.staff.u
gm.ac.id
50
PolynomialInterpolation:NewtonMethod
[ ] ( ) ( )
[ ] [ ] [ ]
[ ] [ ] [ ]0
02111011
,...,,,...,,,,...,,
,,,,
,
xxxnxfxxxf
xxxxf
xx
xxfxxfxxxf
xx
xfxfxxf
n
nnnnnn
ki
kjjikji
ji
jiji
--
=
--
=
--
=
----
( ) ( ) ( ) [ ] ( )( ) [ ]( )( ) ( ) [ ]01110
012100100
,...,,...
...,,,
xxxfxxxxxx
xxxfxxxxxxfxxxfxf
nnn
n
-----++--+-+=
3-Oct-17
http://istia
rto.staff.u
gm.ac.id
51
PolynomialInterpolation:NewtonMethod
i xi f(xi)Computational Steps
1st 2nd 3rd
0 x0 f(x0) f[x1,x0] f[x2,x1,x0] f[x3,x2,x1,x0]
1 x1 f(x1) f[x2,x1] f[x3,x2,x1]
2 x2 f(x2) f[x3,x2]
3 x3 f(x3)
3-Oct-17
http://istia
rto.staff.u
gm.ac.id
52
PolynomialInterpolation:LagrangeMethod
( ) ( ) ( )
( ) Õ
å
¹=
=
--
=
=
n
ijj ji
ji
n
iiin
xx
xxxL
xfxLxf
0
0
3-Oct-17
http://istia
rto.staff.u
gm.ac.id
53
Example
i xi f(xi)
0 1 1.5
1 4 3.1
2 5 6
3 6 2.101234567
0 1 2 3 4 5 6 7
f(x)
X
3-Oct-17
http://istia
rto.staff.u
gm.ac.id
54
SPLINEINTERPOLATIONLinearSplineQuadraticSplineCubicSpline
3-Oct-17
http://istia
rto.staff.u
gm.ac.id
55
SplineInterpolation• Forn+1datapointsà nth-orderinterpolatingpolynomials• Thereisacasewhereafunctionisgenerallysmoothbutundergoesanabruptchangesomewherealongtheregionofinterest• Higher-orderpolynomials,n >>,tendtoswingthroughwildoscillationsinthevicinityofanabruptchange
• Lower-orderpolynomial,n <<,mightbetterrepresentthedatapattern• Lower-orderpolynomials:splineinterpolation
• Linearsplines(n =1)• Quadraticsplines(n =2)• Cubicsplines(n =3)
3-Oct-17
http://istia
rto.staff.u
gm.ac.id
56
PolynomialvsSplineInterpolations
n =1n » n =1n »
§ nth-orderpolynomial
3-Oct-17
http://istia
rto.staff.u
gm.ac.id
57
LinearSplines• 1st-orderspline:straightline• Ordereddatapoints:x0,x1,x2,…,xn
( ) ( ) ( )( ) ( ) ( )
( ) ( ) ( ) nnnnn xxxxxmxfxf
xxxxxmxfxf
xxxxxmxfxf
££-+=
££-+=££-+=
---- 1111
21111
10000
.
.
.
( ) ( )ji
jii xx
xfxfm
--
=+
+
1
1
slope:
3-Oct-17
http://istia
rto.staff.u
gm.ac.id
58
LinearSplines• Linearsplines• Theyarethereforeidenticaltolinearinterpolation• Thedrawbackoflinearsplinesisthattheyarenotsmooth• Atdatapointswheretwosplinesmeet(calledaknot),theslopechangesabruptly
• Thefirstderivativeofthefunctionisdiscontinuousatknots• Theabovedeficiencyisovercomebyusinghigher-orderpolynomialsplinesthatensuresmoothnessattheknotsbyequatingderivativesatthesepoints
3-Oct-17
http://istia
rto.staff.u
gm.ac.id
59
QuadraticSplines• Quadraticsplines• Inordertoensurethatthemthderivativesarecontinuousattheknots,asplineofatleastm+1ordermustbeused
• 3rdorderpolynomialsorcubicsplinesthatensurecontinuousfirstandsecondderivativesaremostfrequentlyusedinpractice.• Thediscontinuousthirdandfourthderivativescannotusuallybedetectedvisually,thustheycanbeignored
3-Oct-17
http://istia
rto.staff.u
gm.ac.id
60
QuadraticSplines• Objective:toderivea2nd-orderpolynomialforeachintervalbetweendatapoints• Thosepolynomialshavetoshowcontinuousfirstderivativeatdatapoints
• Thegeneralformulaofa2nd-orderpolynomial
• Forn+1datapoints(i =0,1,2,…,n)therearen intervals,sothatthereare3n unknownconstants(ai,bi,ci;i =1,2,…,n) toevaluate• Requires3n equations
( ) iii cxbxaxf ++= 2
3-Oct-17
http://istia
rto.staff.u
gm.ac.id
61
QuadraticSplines• The3n equations
1. Thesplinecurvesintersecttheknots,thusthesplinesati-1andiintervalsmeetatdatapoint[xi-1,f(xi-1)]
2. Thefirstsplinecurvepassesthroughthefirstdatapoint(i =1)andthelastsplinecurvepassesthroughtheendpoint(i =n)
i =2,3,…,n2(n- 1)eqs.
( )( )11
21
1111211
---
------
=++
=++
iiiiii
iiiiii
xfcxbxa
xfcxbxa
2 eqs.( )( )nnnnnn xfcxbxa
xfcxbxa
=++
=++2
0101201
3-Oct-17
http://istia
rto.staff.u
gm.ac.id
62
QuadraticSplines• The3n equations
3. Thegradients(thefirstderivatives)ofthesplinecurveattheinteriorknotsareequal
4. Assumethatthesecondderivativeiszeroatthefirstdatapoint
i =2,3,…,n(n- 1)eqs.!!
!f x( ) =2ax+b ⇒ 2ai−1xi−1+bi−1 =2aixi−1+bi
1eq.0=ia
asaconsequence,thefirsttwodatapoints(i =0andi =1)areconnectedwithastraightline
3-Oct-17
http://istia
rto.staff.u
gm.ac.id
63
QuadraticSplines• The3n equations2(n – 1)+2+(n – 1)+1=3n
3-Oct-17
http://istia
rto.staff.u
gm.ac.id
64
CubicSplines• Objective:toderivea3rd-orderpolynomialforeachintervalbetweendatapoints• Thosepolynomialshavetoshowcontinuousfirstandsecondderivativesatdatapoints
• Thegeneralformulaofa3rd-orderpolynomial
• Forn+1datapoints(i =0,1,2,…,n)therearen intervals,sothatthereare4n unknownconstants(ai,bi,ci,di;i =1,2,…,n) toevaluate• Requires4n equations
!!f x( ) =aix3+bix2 +ci x+di
3-Oct-17
http://istia
rto.staff.u
gm.ac.id
65
CubicSplines• The4n equations
1. Thesplinecurvesintersecttheknots,thusthesplinesati-1andiintervalsmeetatdatapoint[xi-1,f(xi-1)]à (2n – 2)eqs.
2. Thefirstsplinecurvepassesthroughthefirstdatapoint(i =1)andthelastsplinecurvepassesthroughtheendpoint(i =n)à 2eqs.
3. Thegradients(thefirstderivatives)ofthesplinecurveattheinteriorknotsareequalà (n – 1)eqs.
4. Thesecondderivativesofthesplinecurveattheinteriorknotsareequalà (n – 1)eqs.
5. Thesecondderivativesattheendknotsarezeroà 2eqs.
3-Oct-17
http://istia
rto.staff.u
gm.ac.id
66
CubicSplines• The4n equations• Thefifthconditionbringstothefollowingconsequence
• Thesplinecurvesatthefirstandlastintervalsarestraightlines• thefirsttwodatapointsareconnectedbyastraightline• thelasttwodatapointsareconnectedbyastraightline
• Thereisanalternativecondition• Thesecondderivativesattheendknotsareknown
3-Oct-17
http://istia
rto.staff.u
gm.ac.id
67
CubicSplines• The4n equations2(n – 2)+2+(n – 1)+(n – 1)+2=4n
• Itispossibletodomathematicalmanipulationssothatthecubicsplinethatrequires(n – 1)equationstoevaluateà refertoChapraandCanale(1990),pp.395-396.
3-Oct-17
http://istia
rto.staff.u
gm.ac.id
68
CubicSplines( ) ( )
( ) ( ) ( )( ) ( )
( )( )
( )( ) ( )
( )( )
( )( ) ( )111
1
11
1
1
31
1
13
1
1
6
6
66
---
-
--
-
-
--
-
-
-
-úû
ùêë
é -¢¢-
-+
-úû
ùêë
é -¢¢-
-+
--¢¢
+--¢¢
=
iiii
ii
i
iiii
ii
i
iii
ii
ii
ii
xxxxxf
xxxf
xxxxxf
xxxf
xxxxxf
xxxxxf
xf
( ) ( ) ( ) ( ) ( ) ( )
( ) ( ) ( )[ ] ( ) ( ) ( )[ ]iiii
iiii
iiiiiiiii
xfxfxx
xfxfxx
xfxxxfxxxfxx
--
+--
=¢¢-+¢¢-+¢¢-
--
++
++-+--
11
11
111111
66
2
!!
n!intervals!!f x0( ) =0!!f xn( ) =0
"
#$$
%$$
⇒ n−1( ) !equation
2unknownsateachinterval:
( ) ( )ii xfxf ¢¢¢¢ - dan 1
3-Oct-17
http://istia
rto.staff.u
gm.ac.id
69