Reputation: 1
I am trying to create a function to test_Lagrange_interpolation().
I need to plot Lagrangian interpolant of (1) built on the grid (2) with N= 8 nodes and evaluated at x. And another plot Lagrangian interpolant of (1) built on the grid (3) withN= 8 nodes and evaluated at x.
So, in other words, to make evenly space grid we can use linspace(-1,1,9) for unevely space grid what can we use?
Thankx
Upvotes: 0
Views: 735
Reputation: 1300
First, we have a Lagrange polynomials with type
x
to do interpolation.x
is an uneven vector.So, what is the benefit of an uneven interpolation? It is due to some shortage of even interpolation:Runge's phenomenon, which is a problem of oscillation at the edges of an interval that occurs when using polynomial interpolation with polynomials of a high degree over a set of equispaced interpolation points.
In other words, just look at the figure below. The left one is a LaGrange polynomial with even grid and the right one's grid is uneven(Chebyshev polynomials), and we could reckon that in this case, the performance of the right one (uneven grid) is better.
Codes:
clc; clear;
syms X
subplot(1,2,1)
ezplot('1/(1+25*x^2)',[-3 3])
Y=0;
xx=-3:0.5:3;
yy=1./(1+25*xx.^2);
for ii=1:length(xx)
tmp=1;
for jj=1:length(xx)
if (jj == ii)
continue;
end
tmp=tmp*(X-xx(jj))/(xx(ii)-xx(jj));
end
Y=Y+tmp*yy(ii);
end
hold on
ezplot(Y,[-3 3])
axis([-3 3 0 1.2])
title('even grid')
subplot(1,2,2)
ezplot('1/(1+25*x^2)',[-3 3])
Y2=0;
xx=-cos((0:12)/12*pi)*3;
yy=1./(1+25*xx.^2);
for ii=1:length(xx)
tmp=1;
for jj=1:length(xx)
if (jj == ii)
continue;
end
tmp=tmp*(X-xx(jj))/(xx(ii)-xx(jj));
end
Y2=Y2+tmp*yy(ii);
end
hold on
ezplot(Y2,[-3 3])
axis([-3 3 0 1.2])
title('uneven grid')
hope it helps!
Upvotes: 1