1 / 6

Lecture 16: Polynomial interpolation

Lecture 16: Polynomial interpolation. Download polyfitexample.m. p=polyfit(x,y,n) creates list of interpolating polynomial coefficients of order n polyval(p,x) evaluates interpolating polynomial with coefficients p at x. Script polyfitexample %example of polyfit use x=[ -1 1 2];

blenda
Download Presentation

Lecture 16: Polynomial interpolation

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 16: Polynomial interpolation Download polyfitexample.m p=polyfit(x,y,n) creates list of interpolating polynomial coefficients of order n polyval(p,x) evaluates interpolating polynomial with coefficients p at x.

  2. Scriptpolyfitexample %example of polyfit use x=[ -1 1 2]; y=[1 3 -2]; n=length(y)-1; p=polyfit(x,y,n); xvec=linspace(-1,2,100); yvec=polyval(p,xvec); plot(xvec,yvec,x,y,'.')

  3. Result: p = -2.0000 1.0000 4.0000

  4. polyfitexample2.m function polyfitexample2%example of erro of polynomial interpolation xmin=0; xmax=5; nmax=10; %number of points which interpolate interval [xmin,xmax]; x=linspace(xmin,xmax,nmax); y=exp(x); n=length(y)-1; p=polyfit(x,y,n) xvec=linspace(xmin-1,xmax+2,500); yvec=polyval(p,xvec); yexact=exp(xvec); plot(xvec,yvec,x,y,'g+',xvec,yexact,'-'); legend('Interpolation','Interpolating points','Exact solution'); end

  5. Number of interpolating points nmax=3

  6. Number of interpolating points nmax=10

More Related