Professional Documents
Culture Documents
ES 204 – Numerical
1st Semester AY 2022-2023
Methods in Engineering
COLLOCATION
Consider a polynomial of degree n, and make
it pass through (n+1) data points with no
restriction on the spacing of the data:
f (x )= y = a0 + a1 x + a2 x +…+ a n–1
2
x n–1
+ an
x n
… …
.
(xn , yn ): y n = a0 + a1 xn +…+ an–1 x n n–1
+ an x n n
COLLOCATION
The previous equations can be rewritten
in matrix notation:
i 0 1 2
Ti 300 400 500
ρi 0.616 0.525 0.457
COLLOCATION
SAMPLE PROBLEM
0.616 = a(300) + b(300) + c
2
In matrix notation:
COLLOCATION
SAMPLE PROBLEM
Using any method to solve the given system:
FOLLOW-UP QUESTION:
What is the value of the density at T = 350? p = 0.567625
COLLOCATION
NOTES:
➢ A unique solution exists to the formulated
system of linear equations upon solving the
unknown coefficients.
➢ The coefficient matrix (Vandermonde matrix)
is very ill-conditioned.
-- The determination of f(x) through the
solution of the systems of equations
may not be an efficient procedure.
INTERPOLATION
➢ Process of estimating an intermediate value
from a set of discrete (or tabulated) values
➢ A collocation function can be used for
interpolation
➢ Interpolation can be done using polynomials,
spline functions, or Fourier series
-- Polynomial functions are commonly
used for interpolation
INTERPOLATION
SPLINE FUNCTIONS
ES 204 – Numerical
1st Semester AY 2022-2023
Methods in Engineering
INTERPOLATION
FOURIER SERIES
ES 204 – Numerical
1st Semester AY 2022-2023
Methods in Engineering
POLYNOMIAL INTERPOLATION
There are several alternative forms in which the
polynomial can be expressed
-- To avoid the ill-conditioning problem
in the coefficient matrix
-- To ease its computer implementation
ALTERNATIVES:
➢ Lagrange Interpolating Polynomials
➢ Newton’s Divided-Difference
Interpolating Polynomials
LAGRANGE POLYNOMIALS
➢ Consider fitting a quadratic function through
three data points (xi, yi), i = 0, 1, 2.
➢ Instead of expressing the quadratic function in
the usual manner, it will be expressed in terms
of the Lagrange polynomial of degree two
f (x )= y = a0 (x – x1 )(x – x2 )+ a1 (x – x0 )(x – x2 )
+ a (x – x )(x – x )
2 0 1
i 0 1 2
Ti 300 400 500
ρi 0.616 0.525 0.457
LAGRANGE POLYNOMIALS
ADDITIONAL NOTES:
➢ The error in Lagrange interpolation depends
on the following factors:
-- Range of the interpolation domain
-- Spacing of the values of xi
-- Degree of the interpolating polynomial
(number of data points, n +1)
LAGRANGE POLYNOMIALS
ADDITIONAL NOTES:
➢ It has the following limitations:
-- If the number of data points is to be
increased or decreased, the results
of the previous calculations cannot be used.
DE BC
=
AE AC
where a0 = f (x 0 )
f (x1 )– f (x0 ) Approximation of
a1 =
x1 – x0 first derivative
LINEAR INTERPOLATION
SAMPLE PROBLEM
Estimate the natural logarithm of 2 using
linear interpolation. Note that the true
value of ln 2 is 0.6931472.
ES 204 – Numerical
1st Semester AY 2022-2023
Methods in Engineering
QUADRATIC INTERPOLATION
➢ If three data points are available as [x0, f(x0)],
[x1, f(x1)], and [x2, f(x2)], we can use a 2nd-degree
or quadratic polynomial to fit the data.
f (x )= a + a (x – x )+ a (x – x )(x – x )
2 0 1 0 2 0 1
Approximation of
second derivative
QUADRATIC INTERPOLATION
NOTES:
➢ All previous computations can still be used
when new data points are considered to
increase the degree of the interpolating
polynomial.
➢ It is expected that the estimate will be
improved due to the introduction of a
curvature term, as manifested from the
expression for a2.
QUADRATIC INTERPOLATION
SAMPLE PROBLEM
Employ a second degree Newton polynomial
to estimate the value of ln 2 with the same
three points from the previous example.
i 0 1 2
xi 1 4 6
f(xi) 0 1.386294 1.791759
QUADRATIC INTERPOLATION
SAMPLE PROBLEM
ES 204 – Numerical
1st Semester AY 2022-2023
Methods in Engineering
nth DEGREE POLYNOMIAL INTERPOLATION
➢ Also known as nth degree Newton’s divided-
difference interpolating polynomial
fn (x )= a0 + a1 (x – x 0 )+ a2 (x – x 0 )(x – x 1 )+…
+ an (x – x 0 )(x – x 1 ). . . (x –x n–1 )
ES 204 – Numerical
1st Semester AY 2022-2023
Methods in Engineering
COLLOCATION ISSUES
EXTRAPOLATION
➢ Process of estimating
a value of f(x) that lies
outside the range of
the known base
points, x1, x2, …, xn.
➢ Extreme care should
be exercised
whenever a case
arises where one
must extrapolate.
COLLOCATION ISSUES
OSCILLATIONS
➢ Higher-degree
polynomials tend
to be very ill-
conditioned.
➢ To illustrate, consider
Runge’s function
1
f (x ) =
1 + 25x2
in the interval [-1,1]
SPLINE INTERPOLATION
➢ Done to address the errors of high-order
polynomial interpolation (round-off errors
and oscillations)
➢ Provides a superior approximation of the
behavior of functions that have local,
abrupt changes
SPLINE FUNCTIONS
➢ Lower-order, connecting polynomials in a
piecewise fashion to subsets of data points
SPLINE FUNCTIONS
LINEAR SPLINES
➢ For n data points (i = 1, 2,…, n), there are
(n-1) intervals
➢ Each interval i has its own spline function, si(x)
LINEAR SPLINES
➢ Each function is merely the straight line
connecting the two points at each end of
the interval
s (x )= a + b (x – x )
i i i i
fi +1 – fi
si (x )= fi + (x – x i )
x i +1 – x i
LINEAR SPLINES
• SAMPLE PROBLEM
• Use linear splines to fit the data below,
• then evaluate the function at x = 5.
i xi fi
1 3.0 2.5
2 4.5 1.0
3 7.0 2.5
4 9.0 0.5
LINEAR SPLINES
NOTES:
➢ Linear splines are not smooth
➢ Slope changes abruptly at knots (data points
where two splines meet)
➢ Use of higher-order splines [at least (n+1) order]
is recommended to ensure smoothness
Cubic Splines
𝑆1 𝑥 = 𝑎1 + 𝑏1 𝑥 − 𝑥1 + 𝑐1 𝑥 − 𝑥1 2 + 𝑑1 𝑥 − 𝑥1 3
if 𝑥1 ≤ 𝑥 ≤ 𝑥2
𝑺 𝑥 = 𝑆2 𝑥 = 𝑎2 + 𝑏2 𝑥 − 𝑥2 + 𝑐2 𝑥 − 𝑥2 2 + 𝑑2 𝑥 − 𝑥2 3
if 𝑥2 ≤ 𝑥 ≤ 𝑥3
⋮ ⋮
2 3
𝑆𝑛−1 𝑥 = 𝑎𝑛−1 + 𝑏𝑛−1 𝑥 − 𝑥𝑛−1 + 𝑐𝑛−1 𝑥 − 𝑥𝑛−1 + 𝑑𝑛−1 𝑥 − 𝑥𝑛−1 if 𝑥𝑛−1 ≤ 𝑥 ≤ 𝑥𝑛
which satisfies a number of conditions.
The problem becomes:
Solve all 𝑎𝑖 , 𝑏𝑖 , 𝑐𝑖 , and 𝑑𝑖 as a system of 4 𝑛 − 1
equations in 4 𝑛 − 1 unknowns.
ERV
Cubic Splines
Example
𝑛 = 4 data points
𝑆1 𝑥 𝑆3 𝑥
𝑆2 𝑥
ℎ1 ℎ2 ℎ3
𝑥1 𝑥2 𝑥3 𝑥4
𝑆1 𝑥 = 𝑎1 + 𝑏1 𝑥 − 𝑥1 + 𝑐1 𝑥 − 𝑥1 2 + 𝑑1 𝑥 − 𝑥1 3 if 𝑥1 ≤ 𝑥 ≤ 𝑥2
𝑺 𝑥 = ൞𝑆2 𝑥 = 𝑎2 + 𝑏2 𝑥 − 𝑥2 + 𝑐2 𝑥 − 𝑥2 2 + 𝑑2 𝑥 − 𝑥2 3 if 𝑥2 ≤ 𝑥 ≤ 𝑥3
𝑆3 𝑥 = 𝑎3 + 𝑏3 𝑥 − 𝑥3 + 𝑐3 𝑥 − 𝑥3 2 + 𝑑3 𝑥 − 𝑥3 3 if 𝑥3 ≤ 𝑥 ≤ 𝑥4
ERV
Cubic Splines
First condition:
(Interpolating property)
For 𝑖 = 1, 2, … , 𝑛 − 1 , 𝑆𝑖 𝑥𝑖 = 𝑦𝑖
“Each spline must pass through the data points
𝑥𝑖 , 𝑦𝑖 .”
𝑆1 𝑥 = 𝑎1 + 𝑏1 𝑥 − 𝑥1 + 𝑐1 𝑥 − 𝑥1 2 + 𝑑1 𝑥 − 𝑥1 3 if 𝑥1 ≤ 𝑥 ≤ 𝑥2
𝑺 𝑥 = ൞𝑆2 𝑥 = 𝑎2 + 𝑏2 𝑥 − 𝑥2 + 𝑐2 𝑥 − 𝑥2 2 + 𝑑2 𝑥 − 𝑥2 3 if 𝑥2 ≤ 𝑥 ≤ 𝑥3
𝑆3 𝑥 = 𝑎3 + 𝑏3 𝑥 − 𝑥3 + 𝑐3 𝑥 − 𝑥3 2 + 𝑑3 𝑥 − 𝑥3 3 if 𝑥3 ≤ 𝑥 ≤ 𝑥4
𝑆1 𝑥1 = 𝑎1 + 𝑏1 𝑥1 − 𝑥1 + 𝑐1 𝑥1 − 𝑥1 2+ 𝑑1 𝑥1 − 𝑥1 3 = 𝑦1
𝑆2 𝑥2 = 𝑎2 + 𝑏2 𝑥2 − 𝑥2 + 𝑐2 𝑥2 − 𝑥2 2+𝑑 𝑥 −𝑥 3 =𝑦
2 2 2 2
2+𝑑 𝑥 −𝑥 3 =𝑦
𝑆3 𝑥3 = 𝑎3 + 𝑏3 𝑥3 − 𝑥3 + 𝑐3 𝑥3 − 𝑥3 3 3 3 3
ERV
Cubic Splines
First condition:
(Interpolating property)
For 𝑖 = 1, 2, … , 𝑛 − 1 , 𝑆𝑖 𝑥𝑖 = 𝑦𝑖
“Each spline must pass through the data points
𝑥𝑖 , 𝑦𝑖 .”
𝑆1 𝑥1 = 𝑎1 + 𝑏1 𝑥1 − 𝑥1 + 𝑐1 𝑥1 − 𝑥1 2+ 𝑑1 𝑥1 − 𝑥1 3 = 𝑦1
𝑆2 𝑥2 = 𝑎2 + 𝑏2 𝑥2 − 𝑥2 + 𝑐2 𝑥2 − 𝑥2 2+𝑑 𝑥 −𝑥 3 =𝑦
2 2 2 2
𝑆3 𝑥3 = 𝑎3 + 𝑏3 𝑥3 − 𝑥3 + 𝑐3 𝑥3 − 𝑥3 2+𝑑 𝑥 −𝑥 3 =𝑦
3 3 3 3
𝑎1 = 𝑦1
𝑎2 = 𝑦2
𝑎3 = 𝑦3
𝑎𝑖 = 𝑦𝑖 for 𝑖 = 1, 2, … , 𝑛 − 1
ERV
Cubic Splines
Second condition:
(Continuity at interior points & rightmost end point)
For 𝑖 = 1, 2, … , 𝑛 − 2 , 𝑆𝑖 𝑥𝑖+1 = 𝑆𝑖+1 𝑥𝑖+1
For the last spline, 𝑆𝑛−1 𝑥𝑛 = 𝑦𝑛
“The right end of a spline must be equal to the
left end of the next spline.”
𝑆1 𝑥 = 𝑎1 + 𝑏1 𝑥 − 𝑥1 + 𝑐1 𝑥 − 𝑥1 2 + 𝑑1 𝑥 − 𝑥1 3 if 𝑥1 ≤ 𝑥 ≤ 𝑥2
𝑺 𝑥 = ൞𝑆2 𝑥 = 𝑎2 + 𝑏2 𝑥 − 𝑥2 + 𝑐2 𝑥 − 𝑥2 2 + 𝑑2 𝑥 − 𝑥2 3 if 𝑥2 ≤ 𝑥 ≤ 𝑥3
𝑆3 𝑥 = 𝑎3 + 𝑏3 𝑥 − 𝑥3 + 𝑐3 𝑥 − 𝑥3 2 + 𝑑3 𝑥 − 𝑥3 3 if 𝑥3 ≤ 𝑥 ≤ 𝑥4
ERV
Cubic Splines
Second condition:
(Continuity at interior points & rightmost end point)
𝑆1 𝑥 = 𝑎1 + 𝑏1 𝑥 − 𝑥1 + 𝑐1 𝑥 − 𝑥1 2 + 𝑑1 𝑥 − 𝑥1 3 if 𝑥1 ≤ 𝑥 ≤ 𝑥2
𝑺 𝑥 = ൞𝑆2 𝑥 = 𝑎2 + 𝑏2 𝑥 − 𝑥2 + 𝑐2 𝑥 − 𝑥2 2 + 𝑑2 𝑥 − 𝑥2 3 if 𝑥2 ≤ 𝑥 ≤ 𝑥3
𝑆3 𝑥 = 𝑎3 + 𝑏3 𝑥 − 𝑥3 + 𝑐3 𝑥 − 𝑥3 2 + 𝑑3 𝑥 − 𝑥3 3 if 𝑥3 ≤ 𝑥 ≤ 𝑥4
𝑆1 𝑥2 = 𝑦1 + 𝑏1 𝑥2 − 𝑥1 + 𝑐1 𝑥2 − 𝑥1 2 + 𝑑1 𝑥2 − 𝑥1 3 = 𝑆2 𝑥2
= 𝑦2 + 𝑏2 𝑥2 − 𝑥2 + 𝑐2 𝑥2 − 𝑥2 2 + 𝑑2 𝑥2 − 𝑥2 3
𝑆2 𝑥3 = 𝑦2 + 𝑏2 𝑥3 − 𝑥2 + 𝑐2 𝑥3 − 𝑥2 2 + 𝑑2 𝑥3 − 𝑥2 3
= 𝑆3 𝑥3 = 𝑦3 + 𝑏3 𝑥3 − 𝑥3 + 𝑐3 𝑥3 − 𝑥3 2 + 𝑑3 𝑥3 − 𝑥3 3
2 3
𝑆3 𝑥4 = 𝑦3 + 𝑏3 𝑥4 − 𝑥3 + 𝑐3 𝑥4 − 𝑥3 + 𝑑3 𝑥4 − 𝑥3 = 𝑦4
𝑆1 𝑥 = 𝑎1 + 𝑏1 𝑥 − 𝑥1 + 𝑐1 𝑥 − 𝑥1 2 + 𝑑1 𝑥 − 𝑥1 3 if 𝑥1 ≤ 𝑥 ≤ 𝑥2
𝑺 𝑥 = ൞𝑆2 𝑥 = 𝑎2 + 𝑏2 𝑥 − 𝑥2 + 𝑐2 𝑥 − 𝑥2 2 + 𝑑2 𝑥 − 𝑥2 3 if 𝑥2 ≤ 𝑥 ≤ 𝑥3
𝑆3 𝑥 = 𝑎3 + 𝑏3 𝑥 − 𝑥3 + 𝑐3 𝑥 − 𝑥3 2 + 𝑑3 𝑥 − 𝑥3 3 if 𝑥3 ≤ 𝑥 ≤ 𝑥4
ERV
Cubic Splines
Third condition:
(Continuity of slopes at interior points)
𝑆1 𝑥 = 𝑎1 + 𝑏1 𝑥 − 𝑥1 + 𝑐1 𝑥 − 𝑥1 2 + 𝑑1 𝑥 − 𝑥1 3 if 𝑥1 ≤ 𝑥 ≤ 𝑥2
𝑺 𝑥 = ൞𝑆2 𝑥 = 𝑎2 + 𝑏2 𝑥 − 𝑥2 + 𝑐2 𝑥 − 𝑥2 2 + 𝑑2 𝑥 − 𝑥2 3 if 𝑥2 ≤ 𝑥 ≤ 𝑥3
𝑆3 𝑥 = 𝑎3 + 𝑏3 𝑥 − 𝑥3 + 𝑐3 𝑥 − 𝑥3 2 + 𝑑3 𝑥 − 𝑥3 3 if 𝑥3 ≤ 𝑥 ≤ 𝑥4
𝑆1 𝑥 = 𝑎1 + 𝑏1 𝑥 − 𝑥1 + 𝑐1 𝑥 − 𝑥1 2 + 𝑑1 𝑥 − 𝑥1 3 if 𝑥1 ≤ 𝑥 ≤ 𝑥2
𝑺 𝑥 = ൞𝑆2 𝑥 = 𝑎2 + 𝑏2 𝑥 − 𝑥2 + 𝑐2 𝑥 − 𝑥2 2 + 𝑑2 𝑥 − 𝑥2 3 if 𝑥2 ≤ 𝑥 ≤ 𝑥3
𝑆3 𝑥 = 𝑎3 + 𝑏3 𝑥 − 𝑥3 + 𝑐3 𝑥 − 𝑥3 2 + 𝑑3 𝑥 − 𝑥3 3 if 𝑥3 ≤ 𝑥 ≤ 𝑥4
ERV
Cubic Splines
Fourth condition:
(Continuity of curvatures at interior points)
𝑆1 𝑥 = 𝑎1 + 𝑏1 𝑥 − 𝑥1 + 𝑐1 𝑥 − 𝑥1 2 + 𝑑1 𝑥 − 𝑥1 3 if 𝑥1 ≤ 𝑥 ≤ 𝑥2
𝑺 𝑥 = ൞𝑆2 𝑥 = 𝑎2 + 𝑏2 𝑥 − 𝑥2 + 𝑐2 𝑥 − 𝑥2 2 + 𝑑2 𝑥 − 𝑥2 3 if 𝑥2 ≤ 𝑥 ≤ 𝑥3
𝑆3 𝑥 = 𝑎3 + 𝑏3 𝑥 − 𝑥3 + 𝑐3 𝑥 − 𝑥3 2 + 𝑑3 𝑥 − 𝑥3 3 if 𝑥3 ≤ 𝑥 ≤ 𝑥4
𝑐𝑖 + 3𝑑𝑖 ℎ𝑖 = 𝑐𝑖+1
for 𝑖 = 1, 2, … , 𝑛 − 2
ERV
Cubic Splines
Fifth condition:
(Zero curvature at end points)
𝑆1′′ 𝑥1 = 0 and 𝑆𝑛−1
′′
𝑥𝑛 = 0
“The curvature at the leftmost and rightmost
endpoints are zero.”
𝑆1 𝑥 = 𝑎1 + 𝑏1 𝑥 − 𝑥1 + 𝑐1 𝑥 − 𝑥1 2 + 𝑑1 𝑥 − 𝑥1 3 if 𝑥1 ≤ 𝑥 ≤ 𝑥2
𝑺 𝑥 = ൞𝑆2 𝑥 = 𝑎2 + 𝑏2 𝑥 − 𝑥2 + 𝑐2 𝑥 − 𝑥2 2 + 𝑑2 𝑥 − 𝑥2 3 if 𝑥2 ≤ 𝑥 ≤ 𝑥3
𝑆3 𝑥 = 𝑎3 + 𝑏3 𝑥 − 𝑥3 + 𝑐3 𝑥 − 𝑥3 2 + 𝑑3 𝑥 − 𝑥3 3 if 𝑥3 ≤ 𝑥 ≤ 𝑥4
𝑆1 𝑥 = 𝑎1 + 𝑏1 𝑥 − 𝑥1 + 𝑐1 𝑥 − 𝑥1 2 + 𝑑1 𝑥 − 𝑥1 3 if 𝑥1 ≤ 𝑥 ≤ 𝑥2
𝑺 𝑥 = ൞𝑆2 𝑥 = 𝑎2 + 𝑏2 𝑥 − 𝑥2 + 𝑐2 𝑥 − 𝑥2 2 + 𝑑2 𝑥 − 𝑥2 3 if 𝑥2 ≤ 𝑥 ≤ 𝑥3
𝑆3 𝑥 = 𝑎3 + 𝑏3 𝑥 − 𝑥3 + 𝑐3 𝑥 − 𝑥3 2 + 𝑑3 𝑥 − 𝑥3 3 if 𝑥3 ≤ 𝑥 ≤ 𝑥4
ERV
Gathering all results: 4 𝑛 − 1 equations, 4 𝑛 − 1 unknowns
Condition 1: Eq. (1) 𝑎𝑖 = 𝑦𝑖 for 𝑖 = 1, 2, … , 𝑛−1
Condition 2: Eq. (2) 𝑦𝑖 + 𝑏𝑖 ℎ𝑖 + 𝑐𝑖 ℎ𝑖2 + 𝑑𝑖 ℎ𝑖3 = 𝑦𝑖+1 for 𝑖 = 1, 2, … , 𝑛−1
Condition 3: Eq. (3) 𝑏𝑖 + 2𝑐𝑖 ℎ𝑖 + 3𝑑𝑖 ℎ𝑖2 = 𝑏𝑖+1 for 𝑖 = 1, 2, … , 𝑛−2
Condition 4: Eq. (4) 𝑐𝑖 + 3𝑑𝑖 ℎ𝑖 = 𝑐𝑖+1 for 𝑖 = 1, 2, … , 𝑛−2
Condition 5: Eq. (5) 𝑐1 = 0
Eq. (6) 𝑐𝑛 = 0
𝑐𝑖+1 − 𝑐𝑖
Eq. (7) 𝑑𝑖 =
3ℎ𝑖
Eq. (8) 𝑏𝑖 + ℎ𝑖 𝑐𝑖 + 𝑐𝑖+1 = 𝑏𝑖+1
Eq. (9) 𝑏𝑖−1 + ℎ𝑖−1 𝑐𝑖−1 + 𝑐𝑖 = 𝑏𝑖
ERV
Gathering all results: 4 𝑛 − 1 equations, 4 𝑛 − 1 unknowns
Condition 1: Eq. (1) 𝑎𝑖 = 𝑦𝑖 for 𝑖 = 1, 2, … , 𝑛−1
Condition 2: Eq. (2) 𝑦𝑖 + 𝑏𝑖 ℎ𝑖 + 𝑐𝑖 ℎ𝑖2 + 𝑑𝑖 ℎ𝑖3 = 𝑦𝑖+1 for 𝑖 = 1, 2, … , 𝑛−1
Condition 3: Eq. (3) 𝑏𝑖 + 2𝑐𝑖 ℎ𝑖 + 3𝑑𝑖 ℎ𝑖2 = 𝑏𝑖+1 for 𝑖 = 1, 2, … , 𝑛−2
Condition 4: Eq. (4) 𝑐𝑖 + 3𝑑𝑖 ℎ𝑖 = 𝑐𝑖+1 for 𝑖 = 1, 2, … , 𝑛−2
Condition 5: Eq. (5) 𝑐1 = 0
Eq. (6) 𝑐𝑛 = 0
𝑐𝑖+1 − 𝑐𝑖
Eq. (7) 𝑑𝑖 =
3ℎ𝑖
Eq. (8) 𝑏𝑖 + ℎ𝑖 𝑐𝑖 + 𝑐𝑖+1 = 𝑏𝑖+1
Eq. (9) 𝑏𝑖−1 + ℎ𝑖−1 𝑐𝑖−1 + 𝑐𝑖 = 𝑏𝑖
ℎ𝑖2
Eq. (10) 𝑦𝑖 + 𝑏𝑖 ℎ𝑖 + 2𝑐𝑖 + 𝑐𝑖+1 = 𝑦𝑖+1
3 For ease, let us define:
𝑦 − 𝑦𝑖 ℎ𝑖 𝑦𝑖+1 − 𝑦𝑖
Eq. (11) 𝑏𝑖 = 𝑖+1 − 2𝑐𝑖 + 𝑐𝑖+1 𝑀𝑖 =
ℎ𝑖 3 ℎ𝑖
Substitute Eq. (11) to Eq. (9):
𝑦𝑖 − 𝑦𝑖−1 ℎ𝑖−1 𝑦𝑖+1 − 𝑦𝑖 ℎ𝑖
Eq. (12) ℎ𝑖−1
−
3
2𝑐𝑖−1 + 𝑐𝑖 + ℎ𝑖−1 𝑐𝑖−1 + 𝑐𝑖 =
ℎ𝑖
−
3
2𝑐𝑖 + 𝑐𝑖+1
ERV
Cubic Splines
Algorithm:
Given: 𝑛 data points, 𝑥𝑖 , 𝑦𝑖 , for 𝑖 = 1, 2, … , 𝑛
1. Compute for 𝑎𝑖 using Eq. (1).
2. Based on Eqs. (5, 6, 13), compute 𝑐𝑖 by solving the
following system of 𝑛 − 2 equations:
𝑨𝒙 = 𝑩
2 ℎ1 + ℎ2 ℎ2 0 0 ⋯ 0 0
ℎ2 2 ℎ2 + ℎ3 ℎ3 0 ⋯ 0 0
0 ℎ3 2 ℎ3 + ℎ4 ℎ4 ⋯ 0 0
𝑨=
0 0 ⋱ ⋱ ⋱ 0 0
⋮ ⋮ ⋮ ⋱ ⋱ ⋱ ⋮
0 0 0 0 0 ℎ𝑛−2 2 ℎ𝑛−2 + ℎ𝑛−1
𝑐2 3 𝑀2 − 𝑀1
𝑐3 3 𝑀3 − 𝑀2
𝒙= ⋮ 𝑩=
⋮
𝑐𝑛−1 3 𝑀𝑛−1 − 𝑀𝑛−2
3. Compute for 𝑏𝑖 using Eq. (11).
4. Compute for 𝑑𝑖 using Eq. (7).
ERV
Example 5.7
Use natural cubic spline to determine 𝑦 at 𝑥 = 4.
𝑥 3 4.5 7 9
𝑦 2.5 1 2.5 0.5
ERV
Example 5.7
Script:
% Data set
x = [3 4.5 7 9]; N = length(x);
y = [2.5 1 2.5 0.5]; close all; clc;
S(4) = 1.2668
ERV
References