% cheb_interp_.m % need cheb_mat.m
function main(f,a,b,deg)
f = fcnchk(f); % make f as a function xx = linspace(a,b,10*deg+1); pxx = f(xx); % original function to find % polynomial interpolation with equispaced data xe = linspace(a,b,deg+1); ye = f(xe); pe = polyfit(xe,ye,deg); pex = polyval(pe,xx); % Chebyshev polynomial interpolation with Chebyshev Gauss points [D,xg,we] = cheb_mat(deg+1,1); % D = Diff matrix, xg = gauss points in [-1,1], we = weights xg = a + (b-a)*(xg+1)/2; % gauss points in [a,b] yg = f(xg); pg = polyfit(xg,yg,deg); pgx = polyval(pg,xx);
%plot(xe,ye,'o',xx,pxx,'b-',xx,pex,'m-.') %pause %plot(xg,yg,'o',xx,pxx,'b-',xx,pgx,'m-') %pause plot(xe,ye,'m*',xg,yg,'ro',xx,pxx,'b-',xx,pex,'m-',xx,pgx,'r-') title('Interpolations : Magenta(equispace), Red(Cheby Gauss pts) ')
|
|