Documente Academic
Documente Profesional
Documente Cultură
fi ai bi x xi ci x xi di x xi
2 3
Equation for Cubic Splines:
Now, Let us consider 4 points then there will be 3 splines and 2knots.
Thus, for n points, there will be (n-1) splines and (n-2) knots.
Hence, We need to have 4(n-1) equations to solve for the unknowns. In the following context an
example of 3 splines and then it is generalized for n points.
S1 x a1 b1 x x1 c1 x x1 d1 x x1
2 3
For n=4;
S2 x a2 b2 x x2 c2 x x2 d2 x x2
2 3
S3 x a3 b3 x x3 c3 x x3 d3 x x3
2 3
Si x ai bi x xi ci x xi di x xi
2 3
General : (1)
For n=4;
S1 passes through x1 , y1 : S1 x1 a1 b1 x1 x1 c1 x1 x1 d1 x1 x1
2 3
or, S1 x1 a1 f1
S 2 passes through x2 , y2 : S2 x2 a2 f 2
S3 passes through x3 , y3 : S3 x3 a3 f3
General : Si xi ai fi (2)
Again,
S3 passes through x4 , y4 : S3 x4 a3 b3 x4 x3 c3 x4 x3 d3 x4 x3
2 3
S2 x | x3 , y3 S3 x | x3 , y3
ci 3di hi ci 1 (5)
ci 1 ci
or, di (6)
3hi
Third Condition: First derivative continuity : First derivatives at the knots are equal.
b1 2c1h1 3d1h12 b2
S2 x | x3 , y3 S3 x | x3 , y3
b2 2c2 h2 3d2 h2 2 b3
General : Si x | xi1 , yi1 Si 1 x | xi1 , yi1
bi 1 bi hi ci ci 1 (9)
bi bi 1 hi 1 ci 1 ci
bi bi 1 hi 1 ci 1 ci (10)
For n=4 ; S1 x | x2 , y2 S2 x | x2 , y2
a1 b1 x2 x1 c1 x2 x1 d1 x2 x1 a2 b2 x2 x2 c2 x2 x2 d2 x2 x2
2 3 2 3
a1 b1 x2 x1 c1 x2 x1 d1 x2 x1 a2
2 3
S2 x | x3 , y3 S3 x | x3 , y3
a2 b2 x3 x2 c2 x3 x2 d2 x3 x2 a3 b3 x3 x3 c3 x3 x3 d3 x3 x3
2 3 2 3
a2 b2 x3 x2 c2 x3 x2 d2 x3 x2 a3
2 3
ai bi xi 1 xi ci xi 1 xi di xi 1 xi ai 1
2 3
fi 1 fi bi xi 1 xi ci xi 1 xi di xi 1 xi
2 3
Now, hi xi 1 xi ;
Therefore , fi 1 fi bi hi ci hi 2 di hi 3 (11)
hi 2
fi 1 fi bi hi ci 1 2ci
3
fi 1 fi hi
bi ci 1 2ci (12)
hi 3
fi fi 1 hi 1
bi 1 ci 2ci 1 (13)
hi 1 3
f f h f f h
bi bi 1 i 1 i i ci 1 2ci i i 1 i 1 ci 2ci 1 (14)
hi 3 hi 1 3
f f h f f h
hi 1 ci 1 ci i 1 i i ci 1 2ci i i 1 i 1 ci 2ci 1
hi 3 hi 1 3
hi 1 h f f f f
ci 2ci 1 hi 1 ci 1 ci i ci 1 2ci i i 1 i 1 i
3 3 hi 1 hi
fi 1 fi f fi 1
hi 1ci 1 2 hi 1 hi ci hi ci 1 3 3 i (15)
hi hi 1
The equation can be made a little more concise by recognizing that the terms on the right
fi f j
hand side of equation (15) are finite differences, f xi , x j
xi x j
hi 1ci 1 2 hi 1 hi ci hi ci 1 3 f xi 1 , xi f xi , xi 1 (16)
Equation (15) can be written for the Knots, i=2,3,……,(n-1),which results in (n-2) simultaneous
tridiagonal equations with n unknown coefficients, c1 , c2 , …… , cn . Therefore if we now have two
additional conditions, we can solve for the c ’s.
fi 1 fi hi
Once this is done, b ’s can be determined from equation (12) : bi ci 1 2ci
hi 3
ci 1 ci
And d ’s can be determined from equation (6) : di
3hi
1. Natural Condition : In this condition, the second derivative at the first and the last node is
equal to zero.
Si x ai bi x xi ci x xi di x xi
2 3
From equation (1):
Therefore , c1 0 (18)
cn1 6dn1hn1 cn 0
cn 0 (19)
h1c1 2 h1 h2 c1 h2c2 3 f x3 , x2 f x2 , x1
h2c2 2 h2 h3 c2 h3c3 3 f x4 , x3 f x3 , x2
1 0 0 0 c1 0
h
1 2 h1 h2 h2 0 c2 3 f x3 , x2 f x2 , x1
0 h2 2 h2 h3 h3 c3 3 f x4 , x3 f x3 , x2
0 0 0 1 c4 0
For n points,
1 0 0 c1 0
h c 3 f x3 , x2 f x2 , x1
1 2 h1 h2 h2 0 0 0 2
0 h2 2 h2 h3 h3 0 0 3 f x4 , x3 f x3 , x2
0 0
0 0 0
0 0 0 hn 2 2 hn 2 hn 1 hn 1 cn 1 3 f xn , xn 1 f xn 1 , xn 2
0
0 1 cn
0
2. Clamped Condition : in this condition f1 and f n are specified at the first and last node.
Hence,
Si x ai bi x xi ci x xi di x xi
2 3
From equation (1) :
S1 x | x1 , y1 f1 b1
fi 1 fi hi
Substituting the above equation in equation (12): bi ci 1 2ci , we get ,
hi 3
f 2 f1 h1
f1 2c2 c1
h1 3
f 2 f1 h
f1 1 c2 2c1
h1 3
c2 h1 2h1c1 3 f x2 , x1 3 f1
Hence, f n bn
fi fi 1 hi 1
From equation (13) we know, bi 1 ci 2ci 1
hi 1 3
f n f n 1 hn 1
bn 1 cn 2cn1
hn 1 3
f f n 1 hn 1
f n hn 1 cn 1 cn n cn 2cn1
hn1 3
h
f n hn1 cn1 cn f xn , xn 1 n1 cn 2cn1
3
2hn1cn1 hn1cn 3 f n f xn , xn 1
The final equations can now be written in a matrix form as :
3 f x2 , x1 3 f1
2h1 h1 0 0 c1
h 2 h1 h2 h2 0 0 0 c 3 f x3 , x2 f x2 , x1
1 2
0 h2 2 h2 h3 h3 0 0 3 f x4 , x3 f x3 , x2
0 0
0 0 0
0 0 0 hn 2 2 hn 2 hn 1 hn 1 cn 1 3 f xn , xn 1 f xn 1 , xn 2
hn 1 cn
0
2hn 1
3 f n f xn , xn 1
3. Not –a- knot condition : The third derivative at the second and next to last knots are
continuous, therefore,
Si x ai bi x xi ci x xi di x xi
2 3
Si x 6di
S1 x | x2 , y2 S2 x | x2 , y2
ci 1 ci
From equation (6) we know , di
3hi
c2 c1 c3 c2
3h1 3h2
h2c1 h1 h2 c2 h1c3 0
For last but one node : Sn2 x | xn1 , yn1 Sn1 x | xn1 , yn1
dn1 dn2
cn 1 cn 2 cn cn 1
3hn 2 3hn 1
h2 h1 h2 h1 0 0 c1 0
3 f x3 , x2 f x2 , x1
h1 2 h1 h2 h2 0 0 0 c2
0 h2 2 h2 h3 h3 0 0 3 f x4 , x3 f x3 , x2
0 0
0 0 0
0 0 0 hn 2 2 hn 2 hn 1 hn 1 cn 1 3 f xn , xn 1 f xn 1 , xn 2
0
hn 1 hn 2 hn 1 hn 2 cn
0
Thus for the above mentioned conditions the Splines may be determined.
GENERAL LINEAR LEAST SQUARES (adapted from Mathews & Finks)
Simple linear, polynomial and multi linear all three belongs to the following general linear least
squares model:
(1)
y a0 z 0 a1 z1 a2 z 2 a3 z 3 a4 z 4 a5 z 5 . ........am z m e
It can easily be seen how simple linear and multi linear regression fall within this model ie
z 0 1, z1 x1 , z 2 x2 , , z m xm . Polynomial regression is also included if the basis functions are
z 0 1, z1 x1 , z 2 x2 , , z m xm
y Z a e
(2)
Z ' Z {a} [ Z ]'{ y} Z 'e
Where
N 0 0 n n n
Zk Zk Z Z Z
0
k Z k1 0
k Z k2 0
k Z km
k 1 k 1 k 1 k 1
n 1 0 n n n
Zk Zk Z k1 Z k1 Z Z
1 2
k k Z k1 Z km
k 1 k 1 k 1 k 1
n 2 0 n n n
Zk Zk Z k2 Z k1 Z
2
k Z k2 Z k2 Z km
k 1 k 1 k 1 k 1
(5)
n n n n
Z mZ 0 m m
Z Z
m
Z k1 m
Z k2 Zk Zk
k 1
k k
k 1
k
k 1
k
k 1
Z
k
i 1
k Z kj 1 Z1i 1Z1j 1 Z 2i 1Z 2j 1 Z3i 1Z3j 1 Z 4i 1Z 4j 1 Z ni 1Z nj 1
Z10 Z 20 Z 30 Z n0 y1
1 1 1 y
Z1 Z 2 Z 3 Z n1 2
Z ' y Z12 Z 2
Z 2
Z n2
y3
2 3
Z m Z 2m Z 3m Z nm yn
1
n 0
Z k yk
k 1 (6)
n 1
Z k yk
k 1
n 2
Z k yk
k 1
n
Z km yk
k 1
y a0 z 0 a1 z1 a2 z 2 a3 z 3 a4 z 4 a5 z 5 . ........am z m (8)
To minimize Sr it is necessary that each partial derivative be zero and these results in the system of
equations
Sr
0 (10)
ak
sr
2 zk0 yk a0 zk0 a1 z1k a2 zk2 a3 zk3 a4 zk4 a5 zk5 ........am zkm 0
n
a0 k 1
sr
2 z1k yk a0 zk0 a1 z1k a2 zk2 a3 zk3 a4 zi4 a5 zk5 ........am zkm 0
n
a1 k 1
sr
2 z20 yk a0 zk0 a1 z1k a2 zk2 a3 zk3 a4 zk4 a5 zk5 ........am zkm 0
n
a2 k 1
sr
2 zk3 yk a0 zk0 a1 z1k a2 zk2 a3 zk3 a4 zk4 a5 zk5 ........am zkm 0
n
(11)
a3 k 1
sr
2 zkm yk a0 zk0 a1 z1k a2 zk2 a3 zk3 a4 zk4 a5 zk5 ........am zkm 0
n
am k 1
a0 zk0 a1 zk0 z1k a2 zk0 zk2 a3 zk0 zk3 ............ am zk0 zkm Z k0 yk
n n n n n n
k 1 k 1 k 1 k 1 k 1 k 1
a0 z1k zk0 a1 z1k a2 z1k zk2 a3 z1k zk3 ............ am z1k zkm Z k1 yk
n n 2 n n n n
k 1 k 1 k 1 k 1 k 1 k 1
a0 zi2 zi0 a1 zk2 z1k a2 zk2 a3 zk2 zk3 ............ am z1k zkm Z k2 yk
n n n n n n
2
k 1 k 1 k 1 k 1 k 1 k 1
(12)
a0 z z a1 z z a2 z z a3 z z ............ am z Z
n n n n n n
m 0 m 1 m 2 m 3 m m
i i k k k k k k k k yk
k 1 k 1 k 1 k 1 k 1 k 1
So
Aa B
or ,
N 0 0 n n n
0 m n 0
Zk Zk Z k0 Z k1 Z k0 Z k2 Z Z
k k Z k yk
k 1 k 1 k 1 k 1
k 1
n 1 0 n n n
a n
Zk Zk Z k1 Z k1 Z Z Z k1 Z km Z k1 yk
1 2 0
k k
a1
k 1 k 1 k 1 k 1
k 1
n 2 0 2 m a2
n n n n
Zk Zk Z Z Z k Z k Z k yk
2
k Z k1 2
k Z k2 2
k 1 k 1 k 1 k 1 k 1
am (13)
n n n n n
Z mZ 0 m m
Z Z Z k yk
m
Z k1 m
Z k2 Zk Zk m
k 1
k k k k
k 1 k 1 k 1 k 1
k 1
(14)
n
yk yk
k 1
n
S t yk y
k 1
n 2
St Sr S yk y (15)
r2 1 r 1 k 1 2
y
St St n
k y
k 1
y = mean of yk
Quadratic Spline:
The objective in quadratic splines is to derive a 2nd order polynomial for each interval
between data points. The polynomial for each interval can be generally represented as:
Si (xi ) ai bi (x x i ) ci (x x i )2 (1)
fi ai bi (xi xi ) ci (xi xi )2
fi ai (2)
Or,
So the constant in each spline must be equal to the value of the dependent variable at the
beginning of the interval. Result can be incorporated into Eq 1
Si (xi ) fi bi (x x i ) ci (x x i )2
So Eq 3 simplifies to
2: The function values of adjacent polynomials must be equal at knots. This condition
can be written for knot i 1 as
fi bi (x i 1 x i ) ci (x i 1 x i ) 2 fi 1 bi 1 (x i 1 x i 1 ) ci 1 (x i 1 x i 1 ) 2 ci (x i 1 x i 1 ) 2 4
fi bi hi ci hi fi 1
2
5
The equation can be written for nodes i 1, 2,3, n 1 . So there are n 1 conditions,
Number of conditions to be evaluated has now reduced to 2n 1 n 1 n
3: The first derivatives at the interior nodes must be equal. It means that adjacent
splines will be joined smoothly. The Eq 1 can be differentiated to yield
bi 2ci hi bi 1 6
Writing this equation for all the interior nodes amounts to n 2 conditions. This means that
there is 1 remaining condition.
4: Assume the 2nd derivative is zero at the first point. 2nd derivative of the Eq 1 is
2ci . So, from Eq(6)
c1 0 7
Putting this condition in Eq(5) for i 1
b1h1 ( f 2 f1 ) 8
bi 1 bi
From Eq(6) ci 9
2hi
b1h1 b2 h1 2( f 2 f1 )
b2 h2 b3h2 2( f 3 f 2 )
11
bn 1hn 1 bn hn 1 2( f n f n 1 )
b1 b2 b1 b2
h1 0 0 b 2 ( f 2 f1 )
h h2 0 b 3 2( f3 f 2 )
2
0
0 hn 1 hn 1 b n 2( f n f n 1 )