Math 104A Homework #2 ∗
General Instructions: Please write your homework papers neatly. You need to turn in both
your codes and descriptions on the appropriate runs you made by compressing and emailing them
to TA with your name and perm number as the file name. Write your own code, individually. Do
not copy codes!
1. (a) Write the Lagrangian form of the interpolating polynomial P2(x) corresponding to the
data in the table below:
xj f(xj )0 11 13 -5
(b) Use P2(x) you obtained in (a) to approximate f(2).
2. (a) Implement the Barycentric Formula for evaluating the interpolating polynomial for arbitrarily distributed nodes x0, ..., xn; you need to write a function or script that computes
the barycentric weights λ
(n)
j = 1/Πk6=j (xj jxk) first and another code to use these values
in the Barycentric Formula. Make sure to test your implementation.
(b) Consider the following table of data
xj f(xj )
0.00 0.0000
0.25 0.7071
0.50 1.0000
0.75 0.7071
1.25 -0.7071
1.50 -1.0000
Use your code in (a) to find P5(2) as an approximation of f(2).
3. The Runge Example. Let
∗All course materials (class lectures and discussions, handouts, homework assignments, examinations, web materials) and the intellectual content of the course itself are protected by United States Federal Copyright Law, the
California Civil Code. The UC Policy 102.23 expressly prohibits students (and all other persons) from recording
lectures or discussions and from distributing or selling lectures notes and all other course materials without the prior
written permission of Prof. Hector D. Ceniceros.
Using your Barycentric Formula code (Prob. 3) and (2) and (3) below, evaluate and plot the
interpolating polynomial of f(x) corresponding to
(a) the equidistributed nodes xj = =5 + j(10/n), j = 0, ..., n for n = 4, 8, and 12.
(b) the nodes xj = 5 cos( jπn
), j = 0, ..., n for n = 4, 8, 12, and 100.
(c) Repeat (a) for f(x) = e
for x ∈ [[5, 5] and comment on the result.
Remark 1. It can be shown that for equidistributed nodes one can use the barycentric weights
is the binomial coefficient (nchoosek(n,j) in Matlab). It can be shown that for the
Make sure to employ (2) and (3) in your Barycentric Formula code for this problem. To plot
the corresponding Pn(x) evaluate Pn(x) at a large number of points x¯ to have a good plotting
resolution, e.g. x¯k = =5+k(10/ne), k = 0, ..., ne with ne = 5000. Note that your Barycentric
Formula cannot be used to evaluate Pn(x) when x coincides with an interpolating node! Plot
also f for comparison. Compare (a) and (b) and comment on the result in view of what you
observed in Prob. 2.