
Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Assignment; Class: Numerical Analysis; Subject: Mathematics; University: University of California - Berkeley; Term: Summer 2009;
Typology: Assignments
1 / 1
This page cannot be seen from the preview
Don't miss anything!

In this assignment, we will use Newton’s divided difference algorithm to approximate the function cos(x) by a Lagrange polynomial in divided-difference form. There are three steps involved. The first step is to write a general function that computes the divided- difference coefficients ak = f [x 0 ,... , xk] of the Lagrange interpolating polynomial, given as input a vector containing x 0 ,... , xn. The second step will be to evaluate the Lagrange interpolating polynomial (in its divided-difference form Pn(x) =
∑n k=0 f^ [x^0 ,... xk]^
∏k j=0(x^ −^ xj^ )) at a few sample points.^ The third step will be to use the MATLAB plot function to graph the interpolating polynomial for the Cosine function, together with the Cosine function on the same set of axes over an appropriately-chosen interval. We begin by giving some example code. The following recursive MATLAB function will evaluate a 0 + a 1 (x − x 0 ) + · · · + an(x − x 0 )... (x − xn− 1 ), given as input vectors containing a 0 ,... , an and x 0 ,... , xn. When n > 0, it works by evaluating a 0 + (x − x 0 )[a 1 + a 2 (x − x 1 ) + · · · + an(x − x 1 )... (x − xn− 1 )]. function y=newton_eval(x,ai,xi) if length(xi)== y = ai(1); else y = ai(1) + (x-xi(1)) .* newton_eval(x,ai(2:end),xi(2:end)); end
f [x 0 ,... , xn] =
f [x 1 ,... , xn] − f [x 0 ,... , xn− 1 ] xn − x 0 , if n > 0
Note: The algorithm given in section 3.2 is more efficient.
Date: Due Monday 7/20. 1