Starting from:

$29.99

MA 3457 / CS 4033 HW #2

MA 3457 / CS 4033
HW #2
1. (20 points) Lagrange Interpolating Polynomials: Exploring function approximation at different data
points or nodes.
For this problem, we will be looking at the following function,
f(x) = 1
1 + 25x
2
(a) (5 points) Main code. Create an m-file that will take D as an argument (the number of data points)
and will will give PD, the (D − 1) degree Lagrange interpolating polynomial for f generated by
D equally spaced nodes on the interval [−1, 1]. You can generate the x values of the nodes with
the command x = linspace(−1, 1, D). You can then generate the f(x) values with the following
command:
f = 1./(1+25.*x.^2)
You may modify/use any of the code posted on Canvas.
(b) (3 points) Generate plots of the data nodes, function f, and Lagrange interpolating polynomial
P for D = 5, 10, 15, and 20. (Might be easiest to copy and paste each individual graph into one
word file to then print out). Comment on what is happening. When plotting, we would like to
plot the polynomial evaluated at additional points, xeval = linspace(−1, 1, 100).
(c) (5 points) Generate a table or bar graph to examine the error, where error will be defined as:
ED =
 
 
 
 
Z 1
−1
f(x)dx −
Z 1
−1
PD(x)dx
 
 
 
 
for D = 5, 10, 15, 20
(d) (4 points) What you are seeing is called Runge’s phenomenon. It happens with certain functions
when we use Lagrangian interpolation with evenly spaced nodes. Why does it happen? Look at
f(1), f
0
(1), f
00(1), and f
(3)(1). What happens to these derivatives, and what does that have to
do with the error?
(e) (3 points) Ways to choose nodes such that this effect is minimized have been developed. One
such choice of nodes are called Chebyshev nodes, where the nodes are not equally spaced and
more nodes are closer to the endpoints. For the case D = 15, plot a graph of the Lagrangian
interpolation using Chebyshev nodes and compare the error using Chebyshev nodes and equally
spaced nodes. The Chebyshev nodes in the interval [-1,1] are:
xi = cos 
2i − 1
2D
π

, i = 1, . . . , D
Comment on the difference between the evenly spaced nodes/data points and the Chebyshev
nodes.
1
2. (6 points) Divided Differences:
Assuming that xr = xo + rh, verify directly (from the definition) the following special cases:
f[xo, x1] = 1
h
(f(x1) − f(xo))
f[xo, x1, x2] = 1
2!h
2
(f(x2) − 2f(x1) + f(xo))
f[xo, x1, x2, x3] = 1
3!h
3
(f(x3) − 3f(x2) + 3f(x1) − f(xo))
Note: These look very similar to approximations of derivatives that we will go over later in the course.
2

More products