A cura di Giuseppe Ciaburro
Pubblicato il 28/01/2005
I diagrammi derivati dai Polinomi Lagrangian e Chebyshev per effettuarne un agevole confronto
Di seguito sono riportati i diagrammi e la funzione per ottenerli relativi ai Polinomi Lagrangian e Chebyshev per effettuarne un agevole confronto

function lebesgue = lagrcheb(n, i)
% LAGRCHEB Plot Lagrangian and Chebyshev polynomial for comparison
%
% This function plots the i-th Lagrangian-polynomial of degree
% n-1 for aequdistant nodes and for the Chebyshev-nodes on [-1,1]
%
% usage: lagrcheb(n, i)
% 1998, Rolf Krause, krause@math.fu-berlin.de
% test the arguments for being ok
if(nargin ~= 2), error('wrong number of arguments'); end
lebesgue = 0;
n = fix(n);
i = fix(i);
if(n < 2), error('n<1'); end
if(i < 1 | i > n), error('i < 1 or i > n'); end
% first, we compute the polynomial for aequdistant nodes
a = -1; % plot between a and b
b = 1;
m = 1e2; % default number of plot points between two nodes
clf;
x = linspace(a,b,n);
x_plot = linspace(a,b,m*n);
y_plot = zeros(1, length(x_plot));
lag = x([1:i-1 i+1:n]);
for j=1:length(x_plot);
y_plot(j) = prod((x_plot(j)-lag)./(x(i)-lag));
end
lebesgue = max(y_plot);
subplot(2,1,1);
plot(x_plot, y_plot, 'r');
hold on;
plot(x, zeros(1,length(x)), 'r*');
c = sprintf('Lagrange Polynom L_{%d}(x) fuer aequdistante- und Tschebyscheff Knoten; n=%d', ...
i,n-1);
title(c);
subplot(2,1,2);
plot(x_plot, y_plot, 'r');
hold on;
plot([x(i), x(i)], [0 1], 'r');
plot(x, zeros(1,length(x)), 'r*');
title('Ausschnitt aus dem oberen Bild, Tschebyscheff-Polynom vollstaendig sichtbar');
% now, the same for the chebychev-nodes
x = cos((2*[n-1:-1:0]+1)./ (2*(n-1) + 2) * pi);
lag = x([1:i-1 i+1:n]);
for j=1:length(x_plot);
y_plot(j) = prod((x_plot(j)-lag)./(x(i)-lag));
end
subplot(2,1,1);
plot(x_plot, y_plot, 'b');
plot(x, zeros(1,length(x)), 'b+');
subplot(2,1,2);
yrange = 1.5 * [min(y_plot) max(y_plot)];
axis([a b yrange]);
plot([x(i), x(i)], [0 1], 'b');
plot(x_plot, y_plot, 'b');
plot(x, zeros(1,length(x)), 'b+');
Per approfondire l'argomento: