首页 > > 详细

调试R、R程序讲解、讲解R程序、Math 104A调试、解析R语言程序、R编程解析

Math 104A Homework #2
Instructor: Lihui Chai
General Instructions: Please write your homework papers neatly. You need to turn in both
full printouts of your codes and the appropriate runs you made. 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:
(b) Use P2(x) you obtained in (a) to approximate f(2).
2. (optional) We proved in class that
kf Pnk1 (1 + n)kf P nk1; (1)
where Pn is the interpolating polynomial of f at the nodes x0, ..., xn, P n is the best ap-
proximation of f, in the maximum (in nity) norm, by a polynomial of degree at most n,
is the Lebesgue constant (here the l(n)j are the elementary Lagrange polynomials).
(a) Write a computer code to evaluate the Lebesgue function
associated to a given set of pairwise distinct nodes x0, ..., xn.
All course materials (class lectures and discussions, handouts, homework assignments, examinations, web ma-
terials) 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.
(b) Consider the equidistributed points xj = 1 +j(2=n) for j = 0;:::;n. Write a computer
code that uses (a) to evaluate and plot L(n)(x) (evaluate L(n)(x) at a large number of
points x to have a good plotting resolution, e.g. xk = 1 + k(2=ne), k = 0;:::;ne with
ne = 1000) for n = 4, 10, and 20. Estimate n for these three values of n.
(c) Repeat (b) with the nodes given by xj = cos(j n ), j = 0;:::;n. Contrast the behavior. of
L(n)(x) and n with those corresponding to the equidistributed points in (b).
3. (a) Implement the Barycentric Formula for evaluating the interpolating polynomial for arbi-
trarily distributed nodes x0;:::;xn; you need to write a function or script. that computes
the barycentric weights (n)j = 1= k6=j(xj xk) rst 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 nd P5(2) as an approximation of f(2).
4. The Runge Example. Let
f(x) = 11 +x2; x2[ 5;5]: (4)
Using your Barycentric Formula code (Prob. 3) and (5) and (6) 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 x2=5 for x2[ 5;5] and comment on the result.
Remark 1. It can be shown that for equidistributed nodes one can use the barycentric weights
(n)j = ( 1)jnj
; j = 0;:::;n; (5)
where nj is the binomial coe cient (nchoosek(n,j) in Matlab). It can be shown that for the
nodes xj = a+b2 + b a2 cos(j n ), j = 0;:::;n, in [a;b], one can use
(n)j =(12( 1)
j for j = 0 or j = n
( 1)j for j = 1;:::;n 1: (6)
Make sure to employ (5) and (6) 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. xk = 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.

联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!