## Description

Please submit to CANVAS a .zip file that includes the following Matlab functions:

Lagrange interp.m

test Lagrange interpolation.m

plot Lebesgue function.m

test Lebesgue function.m

**EXERCISE 1** Write a Matlab function Lagrange interp.m that computes the Lagrangian interpolant of a given set of data points (x_{i}, y_{i}), i = 1, 2, …. The Matlab function should be in the form

function [y] = Lagrange interp(xi,yi,x)

Input:

xi: vector of interpolation nodes

yi: vector of data points at interpolation nodes

x: vector of points in which we evaluate the polynomial interpolant

Output:

y: polynomial interpolant evaluated at x

__Hint__: You can compare the output of your function with the output of the Matlab function, y=polyval(polyfit(xi,yi,length(xi)-1),x) (see the Matlab documentation).

**EXERCISE 2** Consider the nonlinear function

f (x) = | 1 | ,x ∈ [−1, 1]. | (1) |

1 + 20x^{2} |

By using the Matlab function you coded in Exercise 1, determine the Lagrangian interpolant of f , i.e. the polynomial Π_{N} f (x) that interpolates the set of data {x_{i}, f (x_{i})}_{i=0,..,N} in the following cases:

1. Evenly-spaced grid with N + 1 points | ||

j | ||

^{x}j = −1 + 2 _{N} |
,j = 0, .., N | (2) |

- Unevenly-spaced grid with N + 1 points (Chebyshev quadrature points)

π

x_{j} = cos _{N }j , j = 0, 1, …, N, (3)

In particular, write a Matlab function test Lagrange interpolation.m

function test Lagrange interpolation()

that plots the function (1) (in blue) and the Lagrangian interpolants (in red) obtained by using both the evenly-spaced and the unevenly-spaced grids in the cases N = 8 and N = 20 (4 diﬀerent figures). Each figure should include the graph of f (x), the data points {x_{i}, f (x_{i})} and the interpolant Π_{N} f (x) through those points. Which set of nodes gives us the smallest error? Which one the largest?

**EXERCISE 3** Let {l_{i}(x)}_{i=0,..,N} be the set of Lagrange characteristic polynomials associated with the nodes {x_{j} }_{j=0,..,N} . We have seen in class that the polynomial interpolation error is related to the Lebesgue function

N | ||

λ_{N} (x) = |l^{X}_{j} (x)| |
(Lebesgue function), | (4) |

j=0

and the Lebesgue constant

Λ_{N} = max λ_{N} (x) |
(Lebesgue constant). | (5) |

x∈[−1,1] |

- Write a Matlab function plot Lebesgue function.m that plots the Lebesgue function (4) and returns the value of the Lebesgue constant (5) for any given set of interpolation nodes. The function should be in the form

function [L]=plot Lebesgue function(xi)

Input:

xi: vector of interpolation nodes xi=[xi(1) … xi(N+1)]

Output:

Plot of the Lebesgue function λ_{N} (x)

L: Lebesgue constant Λ_{N}

- Apply the function plot Lebesgue function(xi) to the four cases of evenly- and unevenly-spaced grids you studied in Exercise 2. To this end, write a Matlab function

function [L1,L2,L3,L4]=test Lebesgue function()

that plots the Lebesgue function (4) corresponding to the aforementioned four cases (4 diﬀer-ent figures), and returns the value of the Lebesgue constant for each case.

__Remark__: In general, the smaller the Lebesgue constant the smaller the approximation error of polynomial interpolation. If fact, the following error estimate holds true

kf (x) − Π_{N} (x)k_{∞} |
≤ (1 + Λ_{N} ) inf kf (x) − ψ(x)k_{∞} |
(6) |

ψ∈P_{N} |
_{ } |