1. MAN 547
Reverse Engineering in Mechanical Design
Dr. Mohamed Badran
Department of Mechanical Engineering
Spline Interpolation
MAN 547 Dr. Mohamed Badran 1
2. References
• Chapra, Steven C., and Canale, Raymond P.
“Numerical Methods for Engineers”, 5th edition,
McGraw Hill. Inc., 2006.
MAN 547 Dr. Mohamed Badran 2
3. Interpolation
• Employed to estimate intermediate values between precise data
points. Most common method : Polynomial interpolation
General formula for an nth-order polynomial:
f (x) =a0+a1x+a2x2+a3x3+ …….+anxn
For n+1 data points, there is one and only one polynomial of
order n that passes through all the points.
MAN 547 Dr. Mohamed Badran 3
4. Spline Interpolation
• There are cases where polynomials can lead to erroneous results
because of round off error and overshoot.
• Alternative approach is to apply lower-order polynomials to
subsets of data points. Such connecting polynomials are called
spline functions. e.g. 3rd order curves employed to connect each
pair of data points are called “ cubic splines”
MAN 547 Dr. Mohamed Badran 4
5. Spline Interpolation Vs. High order
interpolation polynomial
• When a function includes an abrupt change in values, e.g. the step
function, higher order curve fitting introduces wiggles known as
“spatial oscillations”
MAN 547 Dr. Mohamed Badran 5
6. Linear Splines
• First order splines connect each 2 successive points with a
straight line, i.e.:
These equations can be used to evaluate the function at any point
between x0 and xn by first locating the interval within which the point
lies. Then the appropriate equation is used to determine the function
value within the interval. Identical to linear interpolation
f(x) = f(x0) + m0 (x-x0), x0 x x1
f(x) = f(x1) + m1 (x-x1), x1 x x2 mi =
f x f x
x x
i i
i i
( ) ( )
( )
1
1
.... = ........................ is the slope of the
f(x) = f(xi) + mi (x-xi), xi x xi+1 connecting line
….. = ………………
f(x) = f(xn-1) + mn-1 (x-xn-1), xn-1 x xn
MAN 547 Dr. Mohamed Badran 6
7. Example 1(18.8)*
Fit the data in the table below with first-order splines. Evaluate
the function at x=5.
*Chapra, Steven C., and Canale, Raymond P. “Numerical Methods for Engineers”, 5th edition, McGraw Hill. Inc., 2006.
x F(x)
3.0 2.5
4.5 1.0
7.0 2.5
9.0 0.5
MAN 547 Dr. Mohamed Badran 7
8. Example 1(18.8)*
continued
*Chapra, Steven C., and Canale, Raymond P. “Numerical Methods for Engineers”, 5th edition, McGraw Hill. Inc., 2006.
MAN 547 Dr. Mohamed Badran 8
9. Quadratic Splines
continued
• For each interval we derive a 2nd order polynomial:
fi(x) = ai x2 +bi x+ ci
• for (n+1) data points
( i = 0,1,2,..n) there are
n intervals, i.e. 3n unknown
coefficients (ai , bi ,ci )
MAN 547 Dr. Mohamed Badran 9
10. Quadratic Splines
The ( 3n) equations are:
1. function values equal at interior knots[i=1n-1] :
ai xi
2 + bi xi + ci = f(xi)
ai+1xi
2+bi+1xi + ci+1= f(xi) (2n-2) eqs (1)
2. first and last function pass through end pts:
a1x0
2 + b1x0 + c1 = f(x0)
anxn
2 + bn xn+ cn = f(xn) 2 eqns (2)
3. first derivative( fi(x) = 2 aix+bi) at interior knots[i=1n-1] are
equal:
2 aixi + bi = 2 ai+1 xi + bi+1 ( n-1) eqns (3)
4. an arbitrary choice, e.g. assume fi(xi) = 0 at first pt., hence:
f1(x0) = 2 a1 = 0 a1 = 0 (1 eqn.) (4)
which implies that first 2 pts are connected by straight line , which
is the natural spline condition.
MAN 547 Dr. Mohamed Badran 10
11. Example 2(18.9)*
Fit the data in the table below with quadratic splines. Evaluate the
function at x=5.
*Chapra, Steven C., and Canale, Raymond P. “Numerical Methods for Engineers”, 5th edition, McGraw Hill. Inc., 2006.
x F(x)
3.0 2.5
4.5 1.0
7.0 2.5
9.0 0.5
MAN 547 Dr. Mohamed Badran 11
12. Example 2(18.9)*
continued
*Chapra, Steven C., and Canale, Raymond P. “Numerical Methods for Engineers”, 5th edition, McGraw Hill. Inc., 2006.
MAN 547 Dr. Mohamed Badran 12
13. Cubic Splines
•For each interval we derive a 3rd order polynomial:
fi(x) = ai x3 +bi x2+ ci x + di
• for (n+1) data points ( i = 0,1,2,..n) there are n intervals,
4n unknown coefficients (ai , bi ,ci ,di)
The 4n equations are:
1. Function values are equal at interior knots = 2(n-1) equations
2. First and last functions pass through end points = 2 equations
3. First derivatives at interior knots must be equal = n-1 equations
4. Second derivatives at interior knots must be equal = n-1 equations
5. Second derivatives at the end knots are zero = 2 equations
(arbitrary)
4n equations
MAN 547 Dr. Mohamed Badran 13
14. Another method to derive Cubic Splines
Since 2nd derivative (f(x)= 6ai x+2bi) within each interval is a straight
line, it can be expressed by:
, for xi-1 x xi
(1)
Integrating equation(1) twice to yield fi(x) and evaluating the 2 constants
of integration from the conditions:
fi(x) = f(xi-1) at x=xi-1 and fi(x)= f(xi) at x= xi
yields:
(2)
To determine the unknowns f(xi-1), f(xi) we invoke the condition that :
(3)
𝑓𝑖
′
𝑥𝑖 = 𝑓𝑖+1
′
𝑥𝑖
𝑓𝑖 𝑥 =
𝑓𝑖
′′
𝑥𝑖−1
6 𝑥𝑖 − 𝑥𝑖−1
𝑥𝑖 − 𝑥 3
+
𝑓𝑖
′′
𝑥𝑖
6 𝑥𝑖 − 𝑥𝑖−1
𝑥 − 𝑥𝑖−1
3
+
𝑓 𝑥𝑖−1
𝑥𝑖 − 𝑥𝑖−1
−
𝑓′′
𝑥𝑖−1 𝑥𝑖 − 𝑥𝑖−1
6
𝑥𝑖 − 𝑥
+
𝑓 𝑥𝑖
𝑥𝑖 − 𝑥𝑖−1
−
𝑓′′
𝑥𝑖 𝑥𝑖 − 𝑥𝑖−1
6
𝑥−𝑥𝑖−1
𝑓𝑖
′′
𝑥 = 𝑓𝑖
′′
𝑥𝑖−1
𝑥 − 𝑥𝑖−1
𝑥𝑖−1 − 𝑥𝑖
+ 𝑓𝑖
′′
𝑥𝑖
𝑥 − 𝑥𝑖−1
𝑥𝑖 − 𝑥𝑖−1
MAN 547 Dr. Mohamed Badran 14
15. Another method to derive Cubic Splines
continued
Thus differentiating (2) w.r.t. x, for both fi and fi-1 and equating both
sides (i.e. eqn(3)), yields:
(4)
Equation (4) is expressed for all interior knots , giving (n-1)
simultaneous equations for :
f(xi), for i= 1 to (n-1), given f(x0) and f(xn).
The resulting set is TDM and hence is solved employing TDMA
Equation (2) can then be employed as the cubic spline interpolation
polynomial, to interpolate f(x) in any interval between x0 and xn.
𝑥𝑖 − 𝑥𝑖−1 𝑓′′
𝑥𝑖−1 + 2 𝑥𝑖+1 − 𝑥𝑖−1 𝑓′′
𝑥𝑖 + 𝑥𝑖+1 − 𝑥𝑖 𝑓′′
𝑥𝑖+1
=
6
𝑥𝑖+1 − 𝑥𝑖
𝑓 𝑥𝑖+1 − 𝑓 𝑥𝑖 +
6
𝑥𝑖 − 𝑥𝑖−1
𝑓 𝑥𝑖−1 − 𝑓 𝑥𝑖
MAN 547 Dr. Mohamed Badran 15
16. Example 3(18.10)*
Fit the data in the table below with cubic splines. Evaluate the
function at x=5.
*Chapra, Steven C., and Canale, Raymond P. “Numerical Methods for Engineers”, 5th edition, McGraw Hill. Inc., 2006.
x F(x)
3.0 2.5
4.5 1.0
7.0 2.5
9.0 0.5
MAN 547 Dr. Mohamed Badran 16
17. Example 3(18.10)*
continued
*Chapra, Steven C., and Canale, Raymond P. “Numerical Methods for Engineers”, 5th edition, McGraw Hill. Inc., 2006.
MAN 547 Dr. Mohamed Badran 17