1 / 10

Lecture 17: Polynomial interpolation. Runge example.

Lecture 17: Polynomial interpolation. Runge example. Download rungepoly.m. Runge phenomenon – polydomial wiggle associated rith high degree polynomial interpolation. function rungepoly(n) % interpolate Runge function with polynomial % estimated at uniformly spaced points

fabian
Download Presentation

Lecture 17: Polynomial interpolation. Runge example.

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lecture 17: Polynomial interpolation. Runge example. Download rungepoly.m Runge phenomenon – polydomial wiggle associated rith high degree polynomial interpolation

  2. function rungepoly(n) % interpolate Runge function with polynomial % estimated at uniformly spaced points % input: n - degree of polynomial % plot runge function xmin=-1; xmax=1; f = inline('1./(1 + 12*x.^2)'); x = linspace(xmin,xmax,200); % interpolation with equidistant points x = linspace(xmax,xmin,n); y = f(x); p=polyfit(x,y,n-1); xvec=linspace(xmin,xmax,500); yvec=polyval(p,xvec); yexact= f(xvec); plot(xvec,yvec,'b',x,y,'ro',xvec,yexact,'r--'); legend('Interpolation','Interpolating points','Exact solution'); end

  3. Result: >> rungepoly(10)

  4. Result: >> rungepoly(20)

  5. Runge example with Chebyshev interpolation. Download rungecheb.m • The nth Chebyshev polynomial is given by • Tn(x) = cos(n arrcos(x)) • All the zeros of Tn(x) lie in [-1,+1] and can be calculated by • xi = cos((2i-1) pi/2n) where odd is an odd integer. • The use of the zeros of the Chebyshev nodes as • interpolation points ensures that the maximum of the • interpolation error will be minimized.

  6. function rungecheb(n) % interpolate Runge function with polynomial % estimated at Chebychev points % input: n - degree of polynomial % plot runge function xmin=-1; xmax=1; f = inline('1./(1 + 12*x.^2)'); x = linspace(xmin,xmax,200); % interpolation with equidistant points x = chebroots(n); y = f(x); p=polyfit(x,y,n-1); xvec=linspace(xmin,xmax,500); yvec=polyval(p,xvec); yexact= f(xvec); plot(xvec,yvec,'b',x,y,'ro',xvec,yexact,'r--'); legend('Interpolation','Interpolating points','Exact solution'); title('interpolation at Chebyshev points') end

  7. function x = chebroots(n) % compute roots of Chebyshev polinomial % % input: n - order of polynomial for k=1:n x(k)=cos( pi*(2*k-1)/(2*n) ); end end

  8. Result: >> rungecheb(10) function Compare to equally spaced points:

  9. Result: >> rungecheb(20) Compare to equally spaced points:

  10. Inclass • The following data are related to the life expectances of citizens of two • European regions. • 1975198019851990 • WE:72.874.275.276.4 • EE:70.270.270.3 71.2 • Interpolate each set of data with a polynomial of degree 3 and • estimate the life expectances in 1970, 1983, and 1988. • Plot each fit along with the data and label your plots.

More Related