Question: function u= baryinterp(x,w,y,grid) %MACM 316 - Week 7 % Matlab function to compute the Barycentric form of the interpolating % polynomial P(x) % Name: baryinterp.m

function u= baryinterp(x,w,y,grid) %MACM 316 - Week 7 % Matlab function to compute the Barycentric form of the interpolating % polynomial P(x) % Name: baryinterp.m % Inputs: % x - interpolation nodes % w - Barycentric weights % y - values to interpolate % grid - fine grid to evaluate the interpolating polynomial P on % Output: % u = P(grid) - the values P on the fine grid n=length(x); m=length(grid); u=zeros(m,1); for i=1:m diff=grid(i).*ones(n,1)-x; l=sum(diff==0); if l==0 z=w./diff; u(i)=(z'*y)/sum(z); else u(i)=y(find(diff==0)); end end end function w = baryweights(x) %MACM 316 - Week 7 % Matlab function to compute the barycentric weights w % Name: baryweights.m % Input: % x - interpolation nodes % Output: % w - vector of barycentric weights n=length(x); w=zeros(n,1); for i=1:n X=x-x(i)*ones(n,1); X=X([1:i-1 i+1:n],1); w(i)=1/prod(X); endMACM 316 - Assignment 6 Please read the Guidelines for Assignments rst. Problem A must be submitted to Canvas by Monday March 9. Problems B and C are not to be submitted. The related quiz will be given in class on Friday March 6. Acknowledge any collaborations and assistance from colleagues/TAs/instructor. A. Computing Assignment - Polynomial interpolation and node distribution Required submission: 1 page PDF document and scripts/codes uploaded to Canvas. The purpose of this assignment is to examine how the locations of the nodes x0 , x1 , . . . , xn aect the accuracy and robustness of polynomial interpolation. To compute the interpolating polynomial, you will be using the barycentric form described in lectures. For this, you need to download the matlab functions baryweights.m and baryinterp.m. The rst computes the weights w0 , w1 , . . . , wn of the barycentric form and the second computes the interpolating polynomial. To begin, consider the equally-spaced nodes on [1, 1], given by xi = 1 + 2i , n i = 0, . . . , n. (1) Write a code to compute the error of the interpolating polynomial en = max |P (x) f (x)|, 1x1 for some suitable range of n (in practice, you should replace this maximum by the maximum on some suciently ne grid) and plot log10 (en ) versus n for the test functions: f1 (x) = 1 , 5 4x f2 (x) = 1 . 1 + 16x2 Using this, comment on the accuracy of polynomial interpolation at equally-spaced nodes. Next, consider the so-called Chebyshev nodes on [1, 1], given by xi = cos(i/n), i = 0, . . . , n. (2) Repeat the previous experiment with these nodes instead of (1) and test it on the functions above. Note that in this case you should not use the function baryweights.m to nd the weights, but instead use the known formula 1 w0 = , 2 wj = (1)j , j = 1, . . . , n 1, 1 wn = (1)n , 2 (if you don't do this, your computation may result in under/overow). Is polynomial interpolation at Chebyshev nodes accurate? Is it robust? Finally, use the Chebyshev nodes to approximate the function f3 (x) = cos(104 x). Find the smallest value of n (to within 10) such that en 105 . 1 B. Interpolation with Lagrange Polynomial Q1: Section 3.1, Ex 5 Q2: Section 3.1, Ex 7 Q3: Section 3.1, Ex 12 Q4: Section 3.1, Ex 13 C. Divided Dierences Q1: Section 3.3, Ex 1 Q2: Section 3.3, Ex 3 Q3: Section 3.3, Ex 5 2

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Mathematics Questions!