1 / 28

Lecture 4II

Lecture 4II. Lagrange polynomial Polynomial interpolation. poly. Express a polynomial according to given zeros poly.m returns coefficients of a polynomial with roots –5,0 and 5. poly([-5 0 5]). >> poly([-5 0 5]) ans = 1 0 -25 0. polyval. x=linspace(-5,5);

hamptond
Télécharger la présentation

Lecture 4II

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 4II • Lagrange polynomial • Polynomial interpolation 數值方法2008 Applied Mathematics, NDHU

  2. poly • Express apolynomial according to given zeros • poly.m returns coefficients of a polynomial with roots –5,0 and 5 poly([-5 0 5]) 數值方法2008 Applied Mathematics, NDHU

  3. >> poly([-5 0 5]) ans = 1 0 -25 0 數值方法2008 Applied Mathematics, NDHU

  4. polyval x=linspace(-5,5); p=poly([-5 0 5]); y=polyval(p,x); • Polynomial evaluation • polyval.m substitutes elements in x to polynomial p • p is a vector that represents a polynomial with roots 5, 0 and -5 數值方法2008 Applied Mathematics, NDHU

  5. Lagrange polynomial • n knots, • Li denotes the ith Lagrange polynomial that responds one to xi and zeros to the other knots 數值方法2008 Applied Mathematics, NDHU

  6. Mathematical expression 數值方法2008 Applied Mathematics, NDHU

  7. Proof 數值方法2008 Applied Mathematics, NDHU

  8. Proof 數值方法2008 Applied Mathematics, NDHU

  9. Product form 數值方法2008 Applied Mathematics, NDHU

  10. Lagrange polynomial Given n knots, Let Li denote the ith Lagrange polynomial • Li is a polynomial of degree n-1 • Li has n-1 roots: • Normalization: Li satisfies Li(xi)=1 數值方法2008 Applied Mathematics, NDHU

  11. Polynomial of n-1 roots • x is a vector that consists of n distinct knots • pi is a polynomial whose roots are all knots except for xi xzeros=[x(1,:i-1) x(i+1:n)]; pi=poly(xzeros); 數值方法2008 Applied Mathematics, NDHU

  12. Normalization c=polyval(pi,x(i)); pi=pi/c; Normalization condition 數值方法2008 Applied Mathematics, NDHU

  13. Implementation I • Apply poly.m and polyval.m xzeros=[x(1:i-1) x(i+1:n)]; pi=poly(xzeros); c=polyval(pi,x(i)); pi=pi/c; 數值方法2008 Applied Mathematics, NDHU

  14. Lagrange polynomial evaluation % x contains n knots % Substitute elements in v to Li defined by given knots % y= Li(v) y=lagrange_poly(v,x,i) 數值方法2008 Applied Mathematics, NDHU

  15. Implementation II y=ones(size(v)) n=length(x) y=lagrange_poly(v,x,i) for j=1:n i==j Y y=…. 數值方法2008 Applied Mathematics, NDHU

  16. Evaluation of product form by for-looping function y=lagrange_poly(v,x,i) % evaluation of Li defined by knots in x y=ones(size(v)); n=length(x); for j=1:n if j~=i y=y.*(v-x(j))/(x(i)-x(j)); end end return 數值方法2008 Applied Mathematics, NDHU

  17. n=4,i=1 v=linspace(-2,3); y=lagrange_poly(v,[-1 0 1 2],1); plot(v,y); 數值方法2008 Applied Mathematics, NDHU

  18. n=4,i=1 x=[-1 0 1 2];i=1;n=length(x); xzeros=[x(1:i-1) x(i+1:n)]; pi=poly(xzeros); pi=pi/polyval(pi,x(i)); v=linspace(-2,3); plot(v,polyval(pi,v),'r'); 數值方法2008 Applied Mathematics, NDHU

  19. n=4,i=2 (Implementation I) x=[-1 0 1 2];i=2;n=length(x); xzeros=[x(1:i-1) x(i+1:n)]; pi=poly(xzeros); pi=pi/polyval(pi,x(i)); v=linspace(-2,3); plot(v,polyval(pi,v),'r'); plot(v,0); 數值方法2008 Applied Mathematics, NDHU

  20. n=4,i=2 v=linspace(-2,3); y=lagrange_poly(v,[-1 0 1 2],2); plot(v,y); plot(v,0); 數值方法2008 Applied Mathematics, NDHU

  21. Polynomial interpolation • Find a polynomial well interpolating given points • Input: paired data, S={(xi,yi)}i • Output: a polynomial p(x) that pass all points in S p(x) xi yi 數值方法2008 Applied Mathematics, NDHU

  22. Sampling A sample from an unknown target function y x 數值方法2008 Applied Mathematics, NDHU

  23. Polynomial interpolation • Given • Find a polynomial that satisfies for all i 數值方法2008 Applied Mathematics, NDHU

  24. Interpolating polynomial • A linear combination of n Lagrange polynomials defined by n knots • f is a polynomial of degree n-1 • Li denotes the ith Lagrange polynomial 數值方法2008 Applied Mathematics, NDHU

  25. Verification 數值方法2008 Applied Mathematics, NDHU

  26. Evaluation of interpolating polynomial function z=int_poly(v,x,y) % x contains n knots % y contains desired targets % substitute elements in v to f 數值方法2008 Applied Mathematics, NDHU

  27. Evaluation of interpolating polynomial n=length(x) z=zeros(size(v)) function z=int_poly(v,x,y) for i=1:n % call lagrange_poly(v,x,i) to evaluate Li(v) 數值方法2008 Applied Mathematics, NDHU

  28. function z=int_poly(v,x,y) z=zeros(size(v)); n=length(x); for i=1:n z=z+lagrange_poly(v,x,i)*y(i); end return 數值方法2008 Applied Mathematics, NDHU

More Related