[go: up one dir, main page]

0% found this document useful (0 votes)
9 views8 pages

Example - Interpolation

The document presents an interpolation example using a function defined as y = 0.4x - 0.4x^2, demonstrating various methods including Newton's Divided-Difference, Lagrange, Linear Splines, and Cubic Splines to find a polynomial that fits given data points. It details the calculations for each method and evaluates the function at x = 3, yielding different results for each interpolation technique. The document concludes with visual comparisons of the original function and the interpolating polynomials.

Uploaded by

jodohjehop
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views8 pages

Example - Interpolation

The document presents an interpolation example using a function defined as y = 0.4x - 0.4x^2, demonstrating various methods including Newton's Divided-Difference, Lagrange, Linear Splines, and Cubic Splines to find a polynomial that fits given data points. It details the calculations for each method and evaluates the function at x = 3, yielding different results for each interpolation technique. The document concludes with visual comparisons of the original function and the interpolating polynomials.

Uploaded by

jodohjehop
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Interpolation Example

By: Ahmad Sirojuddin, S.T., M.Sc., Ph.D.


sirojuddin@its.ac.id

Given a function as
� = � � = �0.4� − 0.4�2 (exponential plus quadratic).
Find a polynomial function that interpolates � � at � =− 1, � = 1, � = 4, � = 6, and � = 8 by using
A. Newton’s Divided-Difference Interpolating Polynomial
B. Lagrange Interpolating Polynomial
C. Linear Splines
D. Cubic Splines (with natural spline condition)

Evaluate the function at � = 3

Solution:

From the problem, we have the following data:


�0 =− 1 � �0 = 0.27032
�1 = 1 � �1 = 1.0918247
�2 = 4 � �2 =− 1.4469676
�3 = 6 � �3 =− 3.3768236
�4 = 8 � �4 =− 1.0674698

A. Newton’s Divided-Difference Interpolating Polynomial


Since we have 5 data points, then the polynomial order is 4 (� = 4). Accordingly, the polynomial form is
expressed as:
� � = �0 + �1 � − �0 + �2 � − �0 � − �1 + �3 � − �0 � − �1 � − �2
+ �4 � − �0 � − �1 � − �2 � − �3
Here, our task is to determine the values of �0 until �4. Before we calculate them, let’s calculate the finite
divided differences corresponding to the data points.
First finite divided difference equations:
� �1 − � �0 1.0918247 − 0.27032
� �1, �0 = = = 0.4107523
�1 − �0 1 − −1
� �2 − � �1 −1.4469676 − 1.0918247
� �2, �1 = = =− 0.8462641
�2 − �1 4−1
� �3 − � �2 −3.3768236 − −1.4469676
� �3, �2 = = =− 0.964928
�3 − �2 6−4
� �4 − � �3 −1.0674698 − −3.3768236
� �4, �3 = = = 1.1546769
�4 − �3 8−6
Second finite divided difference equations:
� �2 , �1 − � �1 , �0 −0.8462641 − 0.4107523
� �2, �1 , �0 = = =− 0.2514033
�2 − �0 4 − −1
� �3 , �2 − � �2 , �1 −0.964928 − −0.8462641
� �3, �2 , �1 = = =− 0.0237328
�3 − �1 6−1
� �4 , �3 − � �3 , �2 1.1546769 − −0.964928
� �4, �3 , �2 = = = 0.5299012
�4 − �2 8−4
Third finite divided difference equations:
� �3 , �2 , �1 − � �2 , �1 , �0 −0.0237328 − −6.2570164
� �3, �2 , �1 , �0 = = = 0.0325244
�3 − �0 6 − −1
� �4 , �3 , �2 − � �3 , �2 , �1 0.5299012 − −0.0237328
� �4, �3 , �2 , �1 = = = 0.0790906
�4 − �1 8−1
Fourth finite divided difference equations:
� �4 , �3 , �2 , �1 − � �3 , �2 , �1 , �0 0.0790906 − 0.8904691
� �4, �3 , �2 , �1, �0 = = = 0.005174
�4 − �0 8 − −1

Now, we can compute the values of �0 until �4 .


�0 = � �0 = 0.27032
�1 = � �1 , �0 = 0.4107523
�2 = � �2 , �1 , �0 =− 0.2514033
�3 = � �3 , �2 , �1 , �0 = 0.0325244
�4 = � �4 , �3 , �2 , �1 , �0 = 0.005174

Therefore, the polynomial function that fit data given in the problem is stated as
� � = 0.27032 + 0.4107523 � − �0 − 0.2514033 � − �0 � − �1
+0.0325244 � − �0 � − �1 � − �2
+0.005174 � − �0 � − �1 � − �2 � − �3
� � = 0.27032 + 0.4107523 � + 1 − 0.2514033 � + 1 � − 1
+0.0325244 � + 1 � − 1 � − 4
+0.005174 � + 1 � − 1 � − 4 � − 6

The figure above shows the plot of original function � � (black curve) and the interpolating polynomial
function � � (red curve) found by using the Newton’s divided-difference method. The conclusion of the
figure:
 � � and � � intersect at � =− 1, � = 1, � = 4, � = 6, and � = 8.
 Within interval −1 ≤ � ≤ 8, the curve of � � and � � is near.
 Within interval � <− 1 or � > 8, we cannot guarantee that � � and � � is near.

The value of the function at � = 3


� � = 0.27032 + 0.4107523 3 + 1 − 0.2514033 3 + 1 3 − 1
+0.0325244 3 + 1 3 − 1 3 − 4
+0.005174 3 + 1 3 − 1 3 − 4 3 − 6
=− 0.23389

B. Lagrange Interpolating Polynomial


By using Lagrange Interpolating Polynomial, the polynomial function that fit with 5 data points (order 4) is
expressed as
� − �1 � − �2 � − �3 � − �4 � − �0 � − �2 � − �3 � − �4
� � = � �0 + � �1
�0 − �1 �0 − �2 �0 − �3 �0 − �4 �1 − �0 �1 − �2 �1 − �3 �1 − �4
� − �0 � − �1 � − �3 � − �4 � − �0 � − �1 � − �2 � − �4
+ � �2 + � �3
�2 − �0 �2 − �1 �2 − �3 �2 − �4 �3 − �0 �3 − �1 �3 − �2 �3 − �4
� − �0 � − �1 � − �2 � − �3
+ � �4
�4 − �0 �4 − �1 �4 − �2 �4 − �3
�−1 �−4 �−6 �−8 �+1 �−4 �−6 �−8
= 0.27032 + 1.0918247
−1 − 1 −1 − 4 −1 − 6 −1 − 8 1+1 1−4 1−6 1−8
�+1 �−1 �−6 �−8 �+1 �−1 �−4 �−8
+ −1.4469676 + −3.3768236
4+1 4−1 4−6 4−8 6+1 6−1 6−4 6−8
�+1 �−1 �−4 �−6
+ −1.0674698
8+1 8−1 8−4 8−6
� � = 0.0004290793 � − 1 � − 4 � − 6 � − 8 − 0.005199165 � + 1 � − 4 � − 6 � − 8
−0.01205806 � + 1 � − 1 � − 6 � − 8 + 0.02412016 � + 1 � − 1 � − 4 � − 8
−0.002117996 � + 1 � − 1 � − 4 � − 6

The figure above shows the plot of original function � � (black curve) and the interpolating polynomial
function � � (red curve) found by using the Lagrange method. As seen, � � obtained by using the Lagrange
method is the same as � � obtained by using the Newton’s Divided-Difference method (see the previous
figure).

The value of the function at � = 3


� � = 0.0004290793 3 − 1 3 − 4 3 − 6 3 − 8 − 0.005199165 3 + 1 3 − 4 3 − 6 3 − 8
−0.01205806 3 + 1 3 − 1 3 − 6 3 − 8 + 0.02412016 3 + 1 3 − 1 3 − 4 3 − 8
−0.002117996 3 + 1 3 − 1 3 − 4 3 − 6
=− 0.2339152

C. Linear Splines
Interpolating using Splines means we need to create a function for each interval of data points. Since the
problem gives us 5 data points, then there are 4 four intervals with different equations.
The general equation form for interval i by using linear splines is
� �� − � ��−1
�� � = � ��−1 + � − ��−1
�� − ��−1

Interval 1 �0 ≤ � ≤ �1 , � = 1:
�0 =− 1 � �0 = 0.27032
�1 = 1 � �1 = 1.0918247
� �1 − � �0 1.0918247 − 0.27032
� � = � �0 + � − �0 = 0.27032 + � − −1
�1 − �0 1 − −1
= 0.27032 + 0.4107524 � + 1 ; −1≤�≤1

Interval 2 �1 ≤ � ≤ �2 , � = 2:
�1 = 1 � �1 = 1.0918247
�2 = 4 � �2 =− 1.4469676
� �2 − � �1 −1.4469676 − 1.0918247
� � = � �1 + � − �1 = 1.0918247 + �−1
�2 − �1 4−1
= 1.0918247 − 0.8462641 � − 1 ; 1≤�≤4

Interval 3 �2 ≤ � ≤ �3 , � = 3:
�2 = 4 � �2 =− 1.4469676
�3 = 6 � �3 =− 3.3768236
� �3 − � �2 −3.3768236 − −1.4469676
� � = � �2 + � − �2 =− 1.4469676 + �−4
�3 − �2 6−4
=− 1.4469676 − 0.964928 � − 4 ; 4≤�≤6

Interval 4 �3 ≤ � ≤ �4 , � = 4:
�3 = 6 � �3 =− 3.3768236
�4 = 8 � �4 =− 1.0674698
� �4 − � �3 −1.0674698 − −3.3768236
� � = � �3 + � − �3 =− 3.3768236 + �−6
�4 − �3 8−6
=− 3.3768236 + 1.1546769 � − 6 ; 6≤�≤8
The value of the function at � = 3 can be obtained by using interval 2 1 ≤ � ≤ 4
� � = 1.0918247 − 0.8462641 3 − 1 =− 0.6007035

D. Cubic Splines
By using cubic splines, the equation at each interval i is given by:
�'' ��−1 3
�'' �� 3
� ��−1 �'' ��−1 �� − ��−1
�� � = �� − � + � − ��−1 + − �� − �
6 �� − ��−1 6 �� − ��−1 �� − ��−1 6
� �� �'' �� �� − ��−1
+ − � − ��−1
�� − ��−1 6
Note that the values of ��−1 , �� , � ��−1 , � �� are given by the problem. This equation contains only two
unknowns, �'' ��−1 and �'' �� , which can be found by evaluating the following equation:
�� − ��−1 �'' ��−1 + 2 ��+1 − ��−1 �'' �� + ��+1 − �� �'' ��+1
6 6
= � ��+1 − � �� + � ��−1 − � ��
��+1 − �� �� − ��−1

Let’s re-write the data given by the problem:


�0 =− 1 � �0 = 0.27032
�1 = 1 � �1 = 1.0918247
�2 = 4 � �2 =− 1.4469676
�3 = 6 � �3 =− 3.3768236
�4 = 8 � �4 =− 1.0674698

 From the case � = 1:


�1 − �0 �'' �0 + 2 �2 − �0 �'' �1 + �2 − �1 �'' �2
6 6
= � �2 − � �1 + � �0 − � �1
�2 − �1 �1 − �0
Then,
1 −− 1 �'' �0 + 2 4 −− 1 �'' �1 + 4 − 1 �'' �2
6 6
= −1.4469676 − 1.0918247 + 0.27032 − 1.0918247
4−1 1 −− 1
Then,
2�'' �0 + 10�'' �1 + 3�'' �2 =− 7.5420987 eq. (1)

 From the case � = 2:


�2 − �1 �'' �1 + 2 �3 − �1 �'' �2 + �3 − �2 �'' �3
6 6
= � �3 − � �2 + � �1 − � �2
�3 − �2 �2 − �1
Then,
4 − 1 �'' �1 + 2 6 − 1 �'' �2 + 6 − 4 �'' �3
6 6
= −3.3768236 −− 1.4469676 + 1.0918247 −− 1.4469676
6−4 4−1
Then,
3�'' �1 + 10�'' �2 + 2�'' �3 =− 0.7119834 eq. (2)

 From the case � = 3:


�3 − �2 �'' �2 + 2 �4 − �2 �'' �3 + �4 − �3 �'' �4
6 6
= � �4 − � �3 + � �2 − � �3
�4 − �3 �3 − �2
Then,
6 − 4 �'' �2 + 2 8 − 4 �'' �3 + 8 − 6 �'' �4
6 6
= −1.0674698 −− 3.3768236 + −1.4469676 −− 3.3768236
8−6 6−4
Then,
2�'' �2 + 8�'' �3 + 2�'' �4 = 12.7176294 eq. (3)
 Because of the natural spline condition, the second derivatives of the first and last points are zero, i.e.,
�'' �0 = 0 eq. (4)
�'' �4 = 0 eq. (5)

Equation 1 − 5 form a system of linear equation, where the variables are �'' �0 until �'' �4 . Let’s put
them together in one place.
�'' �0 = 0
2�'' �0 + 10�'' �1 + 3�'' �2 =− 7.5420987
3�'' �1 + 10�'' �2 + 2�'' �3 =− 0.7119834
2�'' �2 + 8�'' �3 + 2�'' �4 = 12.7176294
�'' �4 = 0

We can use any methods to find the solution, such as Gaussian elimination and substitution, Gauss-Jordan
Elimination, etc. The details are omitted here. The solution to above system of linear equations is:
�'' �0 = 0, �'' �1 =− 0.69739262, �'' �2 =− 0.18939083, �'' �3 = 1.63705138, �'' �4 = 0

Substituting this result to �� � yields the interpolation functions as follows:

Interval 1 �0 ≤ � ≤ �1 , � = 1:
�'' �0 �'' �1 � �0 �'' �0 �1 − �0
�1 � = �1 − � 3 + � − �0 3 + − �1 − �
6 �1 − �0 6 �1 − �0 �1 − �0 6
� �1 �'' �1 �1 − �0
+ − � − �0
�1 − �0 6
0 −0.69739262 0.27032 0 1 −− 1
= 1−� 3+ � −− 1 3 + − 1−�
6 1 −− 1 6 1 −− 1 1 −− 1 6
1.0918247 −0.69739262 1 −− 1
+ − � −− 1
1 −− 1 6
=− 0.05811605 � + 1 3 + 0.13516 1 − � + 0.7783766 � + 1
3
=− 0.05811605 � + 1 + 0.6432165� + 0.9135366

Interval 2 �1 ≤ � ≤ �2 , � = 2:
�'' �1 �'' �2 � �1 �'' �1 �2 − �1
�2 � = �2 − � 3 + � − �1 3 + − �2 − �
6 �2 − �1 6 �2 − �1 �2 − �1 6
� �2 �'' �2 �2 − �1
+ − � − �1
�2 − �1 6
−0.69739262 −0.18939083
= 4−� 3+ �−1 3
6 4−1 6 4−1
1.0918247 −0.69739262 4 − 1
+ − 4−�
4−1 6
−1.4469676 −0.18939083 4 − 1
+ − �−1
4−1 6
=− 0.03874403 4 − � 3 − 0.01052171 � − 1 3 + 0.7126379 4 − � − 0.3876271 � − 1

Interval 3 �2 ≤ � ≤ �3 , � = 3:
�'' �2 3
�'' �3 3
� �2 �'' �2 �3 − �2
�3 � = �3 − � + � − �2 + − �3 − �
6 �3 − �2 6 �3 − �2 �3 − �2 6
� �3 �'' �3 �3 − �2
+ − � − �2
�3 − �2 6
−0.18939083 1.63705138 −1.4469676 −0.18939083 6 − 4
= 6−� 3+ �−4 3+ − 6−�
6 6−4 6 6−4 6−4 6
−3.3768236 1.63705138 6 − 4
+ − �−4
6−4 6
=− 0.01578257 6 − � 3 + 0.1364209 � − 4 3 − 0.6603535 6 − � − 2.2340956 � − 4

Interval 4 �3 ≤ � ≤ �4 , � = 4:
�'' �3 3
�'' �4 3
� �3 �'' �3 �4 − �3
�4 � = �4 − � + � − �3 + − �4 − �
6 �4 − �3 6 �4 − �3 �4 − �3 6
� �4 �'' �4 �4 − �3
+ − � − �3
�4 − �3 6
1.63705138 0 −3.3768236 1.63705138 8 − 6
= 8−� 3+ �−6 3+ − 8−�
6 8−6 6 8−6 8−6 6
−1.0674698 0 8 − 6
+ − �−6
8−6 6
= 0.1364209 8 − � 3 − 2.2340956 8 − � − 0.5337349 � − 6
The value of the function at � = 3 can be obtained by using interval 2 1 ≤ � ≤ 4
�2 3 =− 0.03874403 4 − 3 3 − 0.01052171 3 − 1 3 + 0.7126379 4 − 3 − 0.3876271 3 − 1
=− 0.185534

You might also like