Graphics Programs Reference
In-Depth Information
Substituting Eqs. (d) and (e) into Eq. (c) results in
(
x
x
i
+
1
)
x
i
+
1
)
3
k
i
6
−
f
i
,
i
+
1
(
x
)
=
−
(
x
−
x
i
+
1
)(
x
i
−
x
i
−
x
i
+
1
(
x
x
i
+
1
)
x
i
)
3
k
i
+
1
6
−
−
x
i
+
1
−
−
x
i
)(
x
i
−
(
x
(3.10)
x
i
−
y
i
(
x
−
x
i
+
1
)
−
y
i
+
1
(
x
−
x
i
)
+
x
i
−
x
i
+
1
The second derivatives
k
i
of the spline at the interior knots areobtained from
the slopecontinuity conditions
f
i
−
1
,
i
(
x
i
)
f
i
,
i
+
1
(
x
i
), where
i
=
=
2
,
3
,...,
n
−
1. Aftera
little algebra,this results in the simultaneousequations
k
i
−
1
(
x
i
−
1
−
+
2
k
i
(
x
i
−
1
−
+
k
i
+
1
(
x
i
−
x
i
)
x
i
+
1
)
x
i
+
1
)
6
y
i
−
1
−
,
y
i
y
i
−
y
i
+
1
=
x
i
−
i
=
2
,
3
,...,
n
−
1
(3.11)
x
i
−
1
−
x
i
−
x
i
+
1
Because Eqs. (3.11)have a tridiagonal coefficient matrix, they can be solved econom-
icallywith functions
LUdec3
and
LUsol3
describedinArt.2.4.
If the datapoints areevenly spacedat intervals
h
, then
x
i
−
1
−
x
i
=
x
i
−
x
i
+
1
=−
h
,
and the Eqs. (3.11)simplify to
6
h
2
(
y
i
−
1
−
k
i
−
1
+
4
k
i
+
k
i
+
1
=
2
y
i
+
y
i
+
1
),
i
=
2
,
3
,...,
n
−
1
(3.12)
splineCurv
The first stageofcubicspline interpolationis to set up Eqs. (3.11) and solve them
for the unknown
k
's(recall that
k
1
=
k
n
=
0). Thistask iscarried out by the function
splineCurv
:
functionk=splineCurv(xData,yData)
% Returns curvatures of a cubic spline at the knots.
%USAGE:k=splineCurv(xData,yData)
% xData = x-coordinates of data points.
% yData = y-coordinates of data points.
n = length(xData);
c=zeros(n-1,1);d=ones(n,1);
e=zeros(n-1,1);k=zeros(n,1);
c(1:n-2) = xData(1:n-2) - xData(2:n-1);
d(2:n-1) = 2*(xData(1:n-2) - xData(3:n));
e(2:n-1) = xData(2:n-1) - xData(3:n);
k(2:n-1) = 6*(yData(1:n-2) - yData(2:n-1))...
./(xData(1:n-2) - xData(2:n-1))...
Search WWH ::
Custom Search