• Non ci sono risultati.

Polynomial interpolation

N/A
N/A
Protected

Academic year: 2021

Condividi "Polynomial interpolation"

Copied!
9
0
0

Testo completo

(1)

Polynomial interpolation

Polynomial interpolation

Emma Perracchione

Corso di Calcolo Numerico per Ingegneria Meccanica - Matr. PARI (Univ. PD)

Gli esercizi sono presi dal libro: S. De Marchi, D. Poggiali, Exercices of numerical calculus with solutions in Matlab/Octave.

A.A. 2018/2019

(2)

Polynomial interpolation Materiale

Materiale

TUTTO IL MATERIALE SI TROVA AL SEGUENTE LINK E VERRA’

AGGIORNATO AD OGNI LEZIONE.

https://www.math.unipd.it/~emma/CN1819.html OPUURE VEDASI

https://elearning.unipd.it/dii/course/view.php?id=1720

(3)

Polynomial interpolation Remarks

Introduction

For a given set of points (xi, fi), i = 0, . . . , n, the Lagrange polynomial Πn is the polynomial of degree n that assumes at each value xi the corresponding value fi.

Lagrange interpolation is susceptible to Runge’s phenomenon of large oscillation.

This lecture is a kind of basis for the following ones. Helpfull, for instance, for numerical differentiation and integral approximation.

(4)

Polynomial interpolation Remarks

Lagrange

The Lagrange form is given by:

Πn(x ) :=

n

X

i =0

fi`i(x ),

where

`i(x ) := Y

0≤j ≤n j 6=i

x − xj

xi − xj.

When interpolating a given function f by a polynomial of degree n at the nodes x0, . . . , xn we get the error E (x ) = |R(x )|, where

R(x ) = f (x ) − Πn(x ), and

R(x ) = ωn+1(x )fn+1(ξ)

(n + 1)!, x0 < ξ < xn, ωn+1(x ) =

n

Y

i =0

(x − xi).

(5)

Polynomial interpolation Exercises

Exercise 1

Exercise

Construct the interpolating Lagrange polynomial on equispaced points of degree n = 5, . . . , 15 for the Runge function:

g (x ) = 1

1 + x2, x ∈ [−5, 5].

On the script Esercizio1, using the command pause(.5), make the plots of the function and of the polynomials.

Hint

The function named Lagrange.m is already in your folder. It computes the Lagrange basis. Then, recall this function on an independent script and complete the first exercise.

(6)

Polynomial interpolation Exercises

Exercise 1

function l = lagrange(i,x,xbar)

% i-th elementary Lagrange polynomial of

% the points x evalued on xbar n = length(x); m = length(xbar);

l=prod(repmat(xbar,1,n-1)-repmat(x([1:i-1,i+1:n]),m,1),2)...

/prod(x(i)-x([1:i-1,i+1:n]));

% Denominator of the product in Lagrange form:

% prod(x(i)-x([1:i-1,i+1:n]))

% Numerator of the product in Lagrange form:

% repmat(xbar,1,n-1)-repmat(x([1:i-1,i+1:n]),m,1)

% repmat is needed to create an array for evaluating

% the interpolant.

% For understanding the program write help repmat

(7)

Polynomial interpolation Matlab pre-built routines

Polyfit and polyval

The coefficients of the interpolating polynomial can be obtained via the command polyfit.

At first, let us see the Matlab help.

>> help polyfit

polyfit Fit polynomial to data.

P = polyfit(X,Y,N) finds the coefficients of a polynomial P(X) of degree N that fits the data Y best in a

least-squares sense. P is a row vector of length N+1 containing the polynomial coefficients in

descending powers,

P(1)*X^N + P(2)*X^(N-1) +...+ P(N)*X + P(N+1).

... ...

Reference page for polyfit Other functions named polyfit

(8)

Polynomial interpolation Matlab pre-built routines

Polyfit and polyval

For evaluating the interpolant, let us see the Matlab help for polyval.

>>help polyval

polyval Evaluate polynomial.

Y = polyval(P,X) returns the value of a polynomial P evaluated at X. P is a vector of length N+1 whose elements are the coefficients of the

polynomial in descending powers.

Y = P(1)*X^N + P(2)*X^(N-1) + ... + P(N)*X + P(N+1) ...

(9)

Polynomial interpolation Exercises

Exercise 2

Exercise

Find the coefficients of the polynomial interpolating x = (−2, 1, 3) and y = (−2, 11, 17) via the polyfit command on a script named

Esercizio2 and “on paper”. Evaluate and plot the interpolant for 100 evaluation points.

Hint

Compute the coefficients of the Lagrange polynomial p2(x ) = a2· x2+ a1· x + a0. Then you will obtain

p2(x ) = (−4/15) · x2+ (61/15) · x + (36/5)

≈ −0.26x2+ 4.06x + 7.2.

Riferimenti

Documenti correlati

In § 6 we give three examples: (i) the HOMFLYPT ability to detect the presence of zero-linking number structures (such as a system of unlinked vortex rings), that otherwise would

In particular, the use of rational blending functions allows for obtaining spline interpolants of considerably low and sometimes even minimum degree against high polynomial

polymorphims of the hOCT1 and MDR1 genes and the response to imatinib in patients newly diagnosed with chronic- phase chronic myeloid leukemia. Most CML patients who

SIAM Conference on Mathematical and Computational Issues in the Geosciences (SIAM GS13) Padova (Italy) June 17-20 2013M. Polynomial interpolation and quadrature on subregions of

On the other hand, discrete extremal sets (of Fekete and Leja type) ex- tracted from such meshes show good Lebesgue constants and behave asymp- totically as the corresponding

Keywords: Weakly Admissible Meshes, Discrete Extremal Sets, Approximate Fekete Points, Discrete Leja Points, Polynomial Interpolation, Algebraic Cubature, Quadran- gles,

On the base of these and several other numerical tests with spherical triangles of different size and functions of different regularity, we are confident that the proposed