Spline Interpolation

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

SPLINE INTERPOLATION

Yingwei Wang
Department of Mathematics, Purdue University, West Lafayette, IN

wywshtj@gmail.com

1 Script letters from 11 knots


Draw a script letter with the aid of cubic splines and a plotter. Proceed as follows:
Select a modest number of points on the curve, say n = 11. Label these t =
1, 2, · · · , n. For each point, set the corresponding x- and y-coordinates, which is shown
in Table 1. Then fit x = Sx (t), y = Sy (t), using cubic spline interpolating functions Sx
and Sy . This will produce a parametric representation of the original curve. Compute a
large number of values of Sx (t) and Sy (t) to give the plotter. 1000 points are employed
between each knot. The result is shown in Fig.1.

Table 1: Coordinates of the knots


knots x-coordinate y-coordinate
1 3.00 7.00
2 3.05 4.50
3 2.50 1.30
4 2.30 2.70
5 4.00 1.70
6 7.20 1.50
7 8.00 5.00
8 6.50 8.60
9 4.20 9.50
10 4.00 5.00
11 5.00 0.50

I
Yingwei Wang Computer Project #2

10

0
0 1 2 3 4 5 6 7 8 9 10

Figure 1: Script Letter ”D”

2 Comparison the interpolation with equally spaced


nodes, Chebyshev nodes and cubic spline
2.1 Equally spaced nodes
Define p to be the polynomial of degree 20 that interpolates the function

f (x) = (1 + 6x2 )−1

at 21 equally spaced nodes in the interval [−1, 1]. Include the endpoints as nodes.
Table 2 and Fig.2 show the numerical results. Besides, the L2 -norm of the error is
0.4743.

2.2 Chebyshev nodes


Repeat the experiment in Section 2.1 using the Chebyshev nodes given by

xi = cos[(i − 1)π/20], 1 ≤ i ≤ 21.

II
Yingwei Wang Computer Project #2

1.2

0.8

0.6

0.4

0.2

−0.2
−1 −0.5 0 0.5 1

Figure 2: Interpolation with equally spaced nodes

Table 3 and Fig.3 show the numerical results. Besides, the L2 -norm of the error is
9.7206e − 4.

2.3 Cubic spline


With 21 equally spaced knots, repeat the experiment using a cubic interpolating spline.
Table 4 and Fig.4 show the numerical results. Besides, the L2 -norm of the error is
4.2614e − 4.

III
Yingwei Wang Computer Project #2

0.9

0.8

0.7

0.6

0.5

0.4

0.3

0.2

0.1
−1 −0.5 0 0.5 1

Figure 3: Interpolation with Chebyshev nodes

IV
Yingwei Wang Computer Project #2

Table 2: Equally spaced nodes


nodes f (x) p(x) f (x) − p(x)
-1.0000 0.14285714285714 0.14285714285714 0.0000e+000
-0.9500 0.15588464536243 -0.17832013255618 3.3420e-001
-0.9000 0.17064846416382 0.17064846416382 0.0000e+000
-0.8500 0.18744142455483 0.21509981222163 -2.7658e-002
-0.8000 0.20661157024793 0.20661157024793 0.0000e+000
-0.7500 0.22857142857143 0.22454987513418 4.0216e-003
-0.7000 0.25380710659898 0.25380710659898 0.0000e+000
-0.6500 0.28288543140028 0.28374814088352 -8.6271e-004
-0.6000 0.31645569620253 0.31645569620253 0.0000e+000
-0.5500 0.35523978685613 0.35498977909360 2.5001e-004
-0.5000 0.40000000000000 0.40000000000000 0.0000e+000
-0.4500 0.45146726862302 0.45155951280367 -9.2244e-005
-0.4000 0.51020408163265 0.51020408163265 0.0000e+000
-0.3500 0.57636887608069 0.57632781653743 4.1060e-005
-0.3000 0.64935064935065 0.64935064935065 0.0000e+000
-0.2500 0.72727272727273 0.72729328666885 -2.0559e-005
-0.2000 0.80645161290323 0.80645161290323 0.0000e+000
-0.1500 0.88105726872247 0.88104710676544 1.0162e-005
-0.1000 0.94339622641509 0.94339622641509 0.0000e+000
-0.0500 0.98522167487685 0.98522480392094 -3.1290e-006
0.0000 1.00000000000000 1.00000000000000 0.0000e+000
0.0500 0.98522167487685 0.98522480392094 -3.1290e-006
0.1000 0.94339622641509 0.94339622641509 0.0000e+000
0.1500 0.88105726872247 0.88104710676544 1.0162e-005
0.2000 0.80645161290323 0.80645161290323 0.0000e+000
0.2500 0.72727272727273 0.72729328666885 -2.0559e-005
0.3000 0.64935064935065 0.64935064935065 0.0000e+000
0.3500 0.57636887608069 0.57632781653743 4.1060e-005
0.4000 0.51020408163265 0.51020408163265 0.0000e+000
0.4500 0.45146726862302 0.45155951280367 -9.2244e-005
0.5000 0.40000000000000 0.40000000000000 0.0000e+000
0.5500 0.35523978685613 0.35498977909360 2.5001e-004
0.6000 0.31645569620253 0.31645569620253 0.0000e+000
0.6500 0.28288543140028 0.28374814088352 -8.6271e-004
0.7000 0.25380710659898 0.25380710659898 0.0000e+000
0.7500 0.22857142857143 0.22454987513417 4.0216e-003
0.8000 0.20661157024793 0.20661157024793 0.0000e+000
0.8500 0.18744142455483 0.21509981222148 -2.7658e-002
0.9000 0.17064846416382 0.17064846416382 0.0000e+000
0.9500 0.15588464536243 -0.17832013255500 3.3420e-001
1.0000 0.14285714285714 0.14285714285714 0.0000e+000
V
Yingwei Wang Computer Project #2

Table 3: Chebyshev nodes


nodes f (x) p(x) f (x) − p(x)
-1.0000 0.14285714285714 0.14285714285714 0.0000e+000
-0.9500 0.15588464536243 0.15587963630736 5.0091e-006
-0.9000 0.17064846416382 0.17060650048173 4.1964e-005
-0.8500 0.18744142455483 0.18757450572407 -1.3308e-004
-0.8000 0.20661157024793 0.20656431165746 4.7259e-005
-0.7500 0.22857142857143 0.22839975404241 1.7167e-004
-0.7000 0.25380710659898 0.25384728108006 -4.0174e-005
-0.6500 0.28288543140028 0.28310809955457 -2.2267e-004
-0.6000 0.31645569620253 0.31652807961325 -7.2383e-005
-0.5500 0.35523978685613 0.35503303308818 2.0675e-004
-0.5000 0.40000000000000 0.39976094643227 2.3905e-004
-0.4500 0.45146726862302 0.45149310381431 -2.5835e-005
-0.4000 0.51020408163265 0.51048130850254 -2.7723e-004
-0.3500 0.57636887608069 0.57659871798292 -2.2984e-004
-0.3000 0.64935064935065 0.64929491127559 5.5738e-005
-0.2500 0.72727272727273 0.72700834129347 2.6439e-004
-0.2000 0.80645161290323 0.80625660954106 1.9500e-004
-0.1500 0.88105726872247 0.88108431024938 -2.7042e-005
-0.1000 0.94339622641509 0.94353204312032 -1.3582e-004
-0.0500 0.98522167487685 0.98528767120881 -6.5996e-005
0.0000 1.00000000000000 1.00000000000000 -1.1102e-015
0.0500 0.98522167487685 0.98528767120881 -6.5996e-005
0.1000 0.94339622641509 0.94353204312032 -1.3582e-004
0.1500 0.88105726872247 0.88108431024938 -2.7042e-005
0.2000 0.80645161290323 0.80625660954106 1.9500e-004
0.2500 0.72727272727273 0.72700834129347 2.6439e-004
0.3000 0.64935064935065 0.64929491127559 5.5738e-005
0.3500 0.57636887608069 0.57659871798292 -2.2984e-004
0.4000 0.51020408163265 0.51048130850254 -2.7723e-004
0.4500 0.45146726862302 0.45149310381431 -2.5835e-005
0.5000 0.40000000000000 0.39976094643227 2.3905e-004
0.5500 0.35523978685613 0.35503303308818 2.0675e-004
0.6000 0.31645569620253 0.31652807961325 -7.2383e-005
0.6500 0.28288543140028 0.28310809955457 -2.2267e-004
0.7000 0.25380710659898 0.25384728108006 -4.0174e-005
0.7500 0.22857142857143 0.22839975404241 1.7167e-004
0.8000 0.20661157024793 0.20656431165746 4.7259e-005
0.8500 0.18744142455483 0.18757450572407 -1.3308e-004
0.9000 0.17064846416382 0.17060650048173 4.1964e-005
0.9500 0.15588464536243 0.15587963630736 5.0091e-006
1.0000 0.14285714285714 0.14285714285714 0.0000e+000
VI
Yingwei Wang Computer Project #2

0.9

0.8

0.7

0.6

0.5

0.4

0.3

0.2

0.1
−1 −0.5 0 0.5 1

Figure 4: Interpolation with Cubic spline

VII
Yingwei Wang Computer Project #2

Table 4: Cubic spline


nodes f (x) p(x) f (x) − p(x)
-1.0000 0.14285714285714 0.14285714285714 0.0000e+000
-0.9500 0.15588464536243 0.15590784534968 -2.3200e-005
-0.9000 0.17064846416382 0.17064846416382 0.0000e+000
-0.8500 0.18744142455483 0.18743202917232 9.3954e-006
-0.8000 0.20661157024793 0.20661157024793 0.0000e+000
-0.7500 0.22857142857143 0.22856966807685 1.7605e-006
-0.7000 0.25380710659898 0.25380710659898 0.0000e+000
-0.6500 0.28288543140028 0.28288101450098 4.4169e-006
-0.6000 0.31645569620253 0.31645569620253 0.0000e+000
-0.5500 0.35523978685613 0.35523827825458 1.5086e-006
-0.5000 0.40000000000000 0.40000000000000 0.0000e+000
-0.4500 0.45146726862302 0.45147739759194 -1.0129e-005
-0.4000 0.51020408163265 0.51020408163265 0.0000e+000
-0.3500 0.57636887608069 0.57641465926570 -4.5783e-005
-0.3000 0.64935064935065 0.64935064935065 0.0000e+000
-0.2500 0.72727272727273 0.72739026853516 -1.1754e-004
-0.2000 0.80645161290323 0.80645161290323 0.0000e+000
-0.1500 0.88105726872247 0.88115580907953 -9.8540e-005
-0.1000 0.94339622641509 0.94339622641509 0.0000e+000
-0.0500 0.98522167487685 0.98496786435573 2.5381e-004
0.0000 1.00000000000000 1.00000000000000 0.0000e+000
0.0500 0.98522167487685 0.98496786435573 2.5381e-004
0.1000 0.94339622641509 0.94339622641509 0.0000e+000
0.1500 0.88105726872247 0.88115580907953 -9.8540e-005
0.2000 0.80645161290323 0.80645161290323 0.0000e+000
0.2500 0.72727272727273 0.72739026853516 -1.1754e-004
0.3000 0.64935064935065 0.64935064935065 0.0000e+000
0.3500 0.57636887608069 0.57641465926570 -4.5783e-005
0.4000 0.51020408163265 0.51020408163265 0.0000e+000
0.4500 0.45146726862302 0.45147739759194 -1.0129e-005
0.5000 0.40000000000000 0.40000000000000 0.0000e+000
0.5500 0.35523978685613 0.35523827825458 1.5086e-006
0.6000 0.31645569620253 0.31645569620253 0.0000e+000
0.6500 0.28288543140028 0.28288101450098 4.4169e-006
0.7000 0.25380710659898 0.25380710659898 0.0000e+000
0.7500 0.22857142857143 0.22856966807685 1.7605e-006
0.8000 0.20661157024793 0.20661157024793 0.0000e+000
0.8500 0.18744142455483 0.18743202917232 9.3954e-006
0.9000 0.17064846416382 0.17064846416382 0.0000e+000
0.9500 0.15588464536243 0.15590784534968 -2.3200e-005
1.0000 0.14285714285714 0.14285714285714 0.0000e+000
VIII

You might also like