Lecture 14
●
MEEN 357 Homework Solution
1
Lecture-14-Homework-Solution-2009.doc
RMB
1.
Problem 15.5 of the textbook.
Solution
:
You are given the data
x
1
2
2.5
3
4
5
()
f
x
0
5
7
6.5
2
0
Part a):
You are asked to use Newton’s interpolation polynomial determine the
interpolated value at
3.4
x
=
for three cases 1) linear interpolation, 2) quadratic
interpolation and 3) cubic interpolation.
Solution:
One mfile will be used to generate the three answers to Part a).
The script
%Problem 15.1
clc,clear
all
%Need value at x=3.4
%PART a)Linear Interpolation
x=[3,4];
y=[6.5,2];
%You have two easy ways to solve.
%Use function file newtona.m and polyval
[b,P]=newtona(x,y);
yint_a=polyval(P,3.4)
%Use function file in book that we did not cover
yint_a=Newtint(x,y,3.4)
%PART b)Quadratic Interpolation.
You need three points.
%There are two cases as follows
%Two points in front of x=3.4, one point behind
x1=[3,4,5];
y1=[6.5,2,0];
%Two points behind x=3.4, one point in front
x2=[2.5,3,4];
y2=[7,6.5,2];
%Each can be worked by the two methods above
%Use function file newtona.m and polyval
[b,P]=newtona(x1,y1);
yint_b1=polyval(P,3.4)
%Use function file in book that we did not cover
yint_b1=Newtint(x1,y1,3.4)
%Use function file newtona.m and polyval
[b,P]=newtona(x2,y2);
yint_b2=polyval(P,3.4)
%Use function file in book that we did not cover
yint_b2=Newtint(x2,y2,3.4)
%PART c) Cubic Interpolation.
You need four points.
%There are again two cases
%Two points in front of x=3.4, two behind