Description
Please submit to CANVAS a .zip le that includes the following Matlab functions:
Lagrange interp.m
test Lagrange interpolation.m
compute Lebesgue function.m
test Lebesgue function.m
Exercise 1 Write a function Lagrange interp.m that computes the Lagrangian interpolant of a given set of data points (x_{i}; y_{i}), i = 1, 2, :::. The function should be of 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 at which we evaluate the polynomial interpolant
Output:
y: polynomial interpolant evaluated at x
Hint: Compare the output of your function with the output of the Matlab/Octave builtin function,
y=polyval(polyfit(xi,yi,length(xi)1),x)
(see the Matlab/Octave documentation).
Exercise 2 Consider the nonlinear function

f(x) =
1
;
x 2 [ 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 fx_{i}; f(x_{i})g_{i=0;::;N} in the following cases:
1

1. Evenlyspaced grid with N + 1 points
j
^{x}j ^{= 1 + 2} _{N}
;j = 0; ::; N
(2)
2. Unevenlyspaced grid with N + 1 points (ChebyshevGaussLobatto points)

x_{j} = cos
j ; j = 0; 1; :::; N;
(3)
N
In particular, write a Matlab function test Lagrange interpolation.m
function [x,f,P1,P2,P3,P4]=test Lagrange interpolation()
that returns the follwing items:
x: vector of 1000 evenlyspaced nodes in [ 1; 1] (use the command x=linspace(1,1,1000)).
f: vector representing (1) evaluated at x.
P1: Lagrangian interpolant of (1) built on the grid (2) with N = 8 nodes and evaluated at x.
P2: Lagrangian interpolant of (1) built on the grid (2) with N = 20 nodes and evaluated at x.
P1: Lagrangian interpolant of (1) built on the grid (3) with N = 8 nodes and evaluated at x.
P1: Lagrangian interpolant of (1) built on the grid (3) with N = 20 nodes and evaluated at x.
The function should also plot (1) (in blue) and the Lagrangian interpolants (in red) obtained by using both the evenlyspaced and the unevenlyspaced grids for the cases N = 8 and N = 20 (4 di erent gures). Each gure should include the graph of f(x), the data points fx_{i}; f(x_{i})g and the interpolant _{N} f(x) through those points.
Hint: See the code uploaded in CANVAS for examples of similar plots.
Exercise 3 Let fl_{i}(x)g_{i=0;::;N} be the set of Lagrange characteristic polynomials associated with the nodes fx_{j} g_{j=0;::;N} . We have seen in class that the polynomial interpolation error is related to the Lebesgue function

N
X_{j}
jl_{j}(x)j
_{N} (x) =
(Lebesgue function);
(4)
=0
and the Lebesgue constant
_{N} = max
_{N} (x)
(Lebesgue constant).
(5)
x2[ 1;1]

Given the vector of interpolation nodes xi=[xi(1) … xi(N+1)], write a Matlab/Octave function compute Lebesgue function.m that returns the Lebesgue function (4) evaluated at
2
1000 evenlyspaced nodes between xi(1) and xi(N+1). Such function should also return the Lebesgue constant (5).
function [lambda,L]=compute Lebesgue function(xi)
Input:
xi: vector of interpolation nodes xi=[xi(1) … xi(N+1)]
Output:
lambda: Lebesgue function _{N} (x) evaluated at 1000 evenlyspaced nodes between xi(1) and xi(N+1).
L: Lebesgue constant _{N }.

Apply the function compute Lebesgue function(xi) to the four cases of evenly and unevenlyspaced grids you studied in Exercise 2. To this end, write a function
function [L1,L2,L3,L4]=test Lebesgue function()
that plots the Lebesgue function (4) corresponding to the aforementioned four cases (in 4 di erent Figures), and returns the value of the Lebesgue constant for each case.
Remark: Recall, that the smaller the Lebesgue constant the smaller the approximation error of the Lagrangian polynomial interpolation. If fact, we have seen in class that

kf(x) _{N} (x)k_{1}
(1 + _{N} ) inf_{N} kf(x) (x)k_{1}
(6)
2P
3