Saint Louis University: Laboratory Manual Activity No. 6 Polynomial Interpolation Activity Objective
Saint Louis University: Laboratory Manual Activity No. 6 Polynomial Interpolation Activity Objective
Saint Louis University: Laboratory Manual Activity No. 6 Polynomial Interpolation Activity Objective
LABORATORY MANUAL
ACTIVITY NO. 6
POLYNOMIAL INTERPOLATION
ACTIVITY OBJECTIVE:
At the end of the activity, the student should be able to write programs to determine the
interpolating polynomial for a given set of data and use polynomial interpolation to determine an
approximate polynomial for non-polynomial functions.
EQUIPMENT NEEDED:
PC with Scilab
LABORATORY ACTIVITIES:
Problem and Results:
1. Given the data set
x 0 0.5 1 1.5 2
f(x) 1.2 0.5 1.9 5.8 10.8
(a) Determine the interpolating polynomial p(x) for the data set.
p(x) = __1.2+(7/3)x – 0.1x2 + (62/15) x3 – (6/5) x4________
(b) Plot the data points and the interpolating polynomial for -0.2≤x≤2.2.
LABORATORY MANUAL
(c) Estimate the value of f(x) at x=0.75, and x=1.4 using the interpolating polynomial.
f(0.75) ≈ p(0.75) f(1.4) ≈ p(1.4)
f(0.75) ≈ _________________________ f(1.4) ≈ _________________________
-x
2. Given the function f(x) = 5e sin(0.5πx)
(a) Determine a 2nd-order approximate polynomial p(x) for f(x) on the interval 0≤x≤2 using polynomial
interpolation with three equally spaced data points.
p(x) = ___________________________________________________________________________
(b) Determine a 4th-order approximate polynomial p(x) for f(x) on the interval 0≤x≤2 using polynomial
interpolation with five equally spaced data points.
p(x) = ___________________________________________________________________________
(c) Compute and tabulate the values of f(x) and p(x) as indicated in the given table.
p(x)
x f(x)
2nd-Order 4th-Order
0.2
0.8
1.2
1.8
(d) Plot the graph of f(x) and the 2nd-order p(x) for -0.5≤x≤2.5.
Plot the graph of f(x) and the 4th-order p(x) for -0.5≤x≤2.5.
(e) Answer the following questions based on the computed values and graphs.
Do the preceding results show that the interpolating polynomial and the non-polynomial function
coincide at the data points? ______
LABORATORY MANUAL
Do the preceding results show that an interpolating polynomial with a higher degree is more accurate
in approximating a non-polynomial function than an interpolating polynomial with a lower degree?
_____
Do the preceding results show that an interpolating polynomial is a good approximation of a non-
polynomial function within the interval covered by the data points. _____
Do the preceding results show that an interpolating polynomial is a good approximation of a non-
polynomial function outside the interval covered by the data points. _____
SAMPLE PROGRAM:
-2x
Determine a 6th-order interpolating polynomial p(x) for f(x)=10xe on the interval 0≤x≤2.5.
//POLYNOMIAL INTERPOLATION
//Generate the values of x as a column vector
N=7; //no. of data points
a=0; //lower limit of the interval
b=2.5; //upper limit of the interval
dx=(b-a)/(N-1);
x=(a:dx:b)'
//Solve for the coefficients of p(x) using Vandermonde matrix and Gauss-Jordan
elimination
AM=[x.^0, x.^1,x.^2,x.^3,x.^4, x.^5, x.^6,fx]
//Consider a pivot row starting from the first row until the the last row
[nrow,ncol]=size(AM);
for prow=1:nrow
//If the pivot element is zero, interchange the pivot row with a row below it
row=prow+1;
LABORATORY MANUAL
LABORATORY MANUAL
//POLYNOMIAL INTERPOLATION
//Generate the values of x as a column vector
N=5; //no. of data points
a=0; //lower limit of the interval
b=2; //upper limit of the interval
dx=(b-a)/(N-1);
x=(a:dx:b)'
//Solve for the coefficients of p(x) using Vandermonde matrix and Gauss-Jordan elimination
AM=[x.^0, x.^1,x.^2,x.^3,x.^4,fx]
//Consider a pivot row starting from the first row until the the last row
[nrow,ncol]=size(AM);
for prow=1:nrow
//If the pivot element is zero, interchange the pivot row with a row below it
row=prow+1;
while row<=nrow & abs(AM(prow,prow))<(10^-16)
if AM(row,prow)~=0 then
for col=prow:ncol
temp=AM(prow,col);
AM(prow,col)=AM(row,col);
AM(row,col)=temp;
end;
else
row=row+1;
end;
end;
LABORATORY MANUAL
plot2d(xv,fxv);xgrid